Commit e97283ae by Nimisha Asthagiri

Fix column alignment issue when Teams is disabled

parent 16e96365
...@@ -134,7 +134,8 @@ class _CertificateBulkContext(object): ...@@ -134,7 +134,8 @@ class _CertificateBulkContext(object):
class _TeamBulkContext(object): class _TeamBulkContext(object):
def __init__(self, context, users): def __init__(self, context, users):
if context.teams_enabled: self.enabled = context.teams_enabled
if self.enabled:
self.teams_by_user = { self.teams_by_user = {
membership.user.id: membership.team.name membership.user.id: membership.team.name
for membership in for membership in
...@@ -326,7 +327,10 @@ class CourseGradeReport(object): ...@@ -326,7 +327,10 @@ class CourseGradeReport(object):
""" """
Returns a list of names of teams in which the given user belongs. Returns a list of names of teams in which the given user belongs.
""" """
return [bulk_teams.teams_by_user.get(user.id, '')] team_names = []
if bulk_teams.enabled:
team_names = [bulk_teams.teams_by_user.get(user.id, '')]
return team_names
def _user_verification_mode(self, user, context, bulk_enrollments): def _user_verification_mode(self, user, context, bulk_enrollments):
""" """
......
...@@ -96,10 +96,13 @@ class InstructorGradeReportTestCase(TestReportMixin, InstructorTaskCourseTestCas ...@@ -96,10 +96,13 @@ class InstructorGradeReportTestCase(TestReportMixin, InstructorTaskCourseTestCas
report_store = ReportStore.from_config(config_name='GRADES_DOWNLOAD') report_store = ReportStore.from_config(config_name='GRADES_DOWNLOAD')
report_csv_filename = report_store.links_for(course_id)[0][0] report_csv_filename = report_store.links_for(course_id)[0][0]
report_path = report_store.path_to(course_id, report_csv_filename) report_path = report_store.path_to(course_id, report_csv_filename)
found_user = False
with report_store.storage.open(report_path) as csv_file: with report_store.storage.open(report_path) as csv_file:
for row in unicodecsv.DictReader(csv_file): for row in unicodecsv.DictReader(csv_file):
if row.get('username') == username: if row.get('Username') == username:
self.assertEqual(row[column_header], expected_cell_content) self.assertEqual(row[column_header], expected_cell_content)
found_user = True
self.assertTrue(found_user)
@ddt.ddt @ddt.ddt
...@@ -301,7 +304,7 @@ class TestInstructorGradeReport(InstructorGradeReportTestCase): ...@@ -301,7 +304,7 @@ class TestInstructorGradeReport(InstructorGradeReportTestCase):
user_b.username, user_b.username,
course.id, course.id,
cohort_name_header, cohort_name_header,
u'Default Group', u'',
) )
@patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task') @patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task')
...@@ -1229,13 +1232,11 @@ class TestTeamStudentReport(TestReportMixin, InstructorTaskCourseTestCase): ...@@ -1229,13 +1232,11 @@ class TestTeamStudentReport(TestReportMixin, InstructorTaskCourseTestCase):
""" Run the upload_students_csv task and verify that the correct team was added to the CSV. """ """ Run the upload_students_csv task and verify that the correct team was added to the CSV. """
current_task = Mock() current_task = Mock()
current_task.update_state = Mock() current_task.update_state = Mock()
task_input = { task_input = [
'features': [
'id', 'username', 'name', 'email', 'language', 'location', 'id', 'username', 'name', 'email', 'language', 'location',
'year_of_birth', 'gender', 'level_of_education', 'mailing_address', 'year_of_birth', 'gender', 'level_of_education', 'mailing_address',
'goals', 'team' 'goals', 'team'
] ]
}
with patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task') as mock_current_task: with patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task') as mock_current_task:
mock_current_task.return_value = current_task mock_current_task.return_value = current_task
result = upload_students_csv(None, None, self.course.id, task_input, 'calculated') result = upload_students_csv(None, None, self.course.id, task_input, 'calculated')
...@@ -1243,10 +1244,13 @@ class TestTeamStudentReport(TestReportMixin, InstructorTaskCourseTestCase): ...@@ -1243,10 +1244,13 @@ class TestTeamStudentReport(TestReportMixin, InstructorTaskCourseTestCase):
report_store = ReportStore.from_config(config_name='GRADES_DOWNLOAD') report_store = ReportStore.from_config(config_name='GRADES_DOWNLOAD')
report_csv_filename = report_store.links_for(self.course.id)[0][0] report_csv_filename = report_store.links_for(self.course.id)[0][0]
report_path = report_store.path_to(self.course.id, report_csv_filename) report_path = report_store.path_to(self.course.id, report_csv_filename)
found_user = False
with report_store.storage.open(report_path) as csv_file: with report_store.storage.open(report_path) as csv_file:
for row in unicodecsv.DictReader(csv_file): for row in unicodecsv.DictReader(csv_file):
if row.get('username') == username: if row.get('username') == username:
self.assertEqual(row['team'], expected_team) self.assertEqual(row['team'], expected_team)
found_user = True
self.assertTrue(found_user)
def test_team_column_no_teams(self): def test_team_column_no_teams(self):
self._generate_and_verify_teams_column(self.student1.username, UNAVAILABLE) self._generate_and_verify_teams_column(self.student1.username, UNAVAILABLE)
...@@ -1698,11 +1702,14 @@ class TestGradeReportEnrollmentAndCertificateInfo(TestReportMixin, InstructorTas ...@@ -1698,11 +1702,14 @@ class TestGradeReportEnrollmentAndCertificateInfo(TestReportMixin, InstructorTas
report_store = ReportStore.from_config(config_name='GRADES_DOWNLOAD') report_store = ReportStore.from_config(config_name='GRADES_DOWNLOAD')
report_csv_filename = report_store.links_for(self.course.id)[0][0] report_csv_filename = report_store.links_for(self.course.id)[0][0]
report_path = report_store.path_to(self.course.id, report_csv_filename) report_path = report_store.path_to(self.course.id, report_csv_filename)
found_user = False
with report_store.storage.open(report_path) as csv_file: with report_store.storage.open(report_path) as csv_file:
for row in unicodecsv.DictReader(csv_file): for row in unicodecsv.DictReader(csv_file):
if row.get('username') == username: if row.get('Username') == username:
csv_row_data = [row[column] for column in self.columns_to_check] csv_row_data = [row[column] for column in self.columns_to_check]
self.assertEqual(csv_row_data, expected_data) self.assertEqual(csv_row_data, expected_data)
found_user = True
self.assertTrue(found_user)
def _create_user_data(self, def _create_user_data(self,
user_enroll_mode, user_enroll_mode,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment