Fixed unicode error in CSV grade report generation.
TNL-1196
This commit is contained in:
@@ -572,8 +572,7 @@ def upload_grades_csv(_xmodule_instance_args, _entry_id, course_id, _task_input,
|
||||
# We were able to successfully grade this student for this course.
|
||||
task_progress.succeeded += 1
|
||||
if not header:
|
||||
# Encode the header row in utf-8 encoding in case there are unicode characters
|
||||
header = [section['label'].encode('utf-8') for section in gradeset[u'section_breakdown']]
|
||||
header = [section['label'] for section in gradeset[u'section_breakdown']]
|
||||
rows.append(
|
||||
["id", "email", "username", "grade"] + header + cohorts_header + group_configs_header
|
||||
)
|
||||
|
||||
@@ -139,6 +139,23 @@ class TestInstructorGradeReport(TestReportMixin, InstructorTaskCourseTestCase):
|
||||
_groups = [group.name for group in self.course.user_partitions[0].groups]
|
||||
self.assertEqual(_groups, user_groups)
|
||||
|
||||
@patch('instructor_task.tasks_helper._get_current_task')
|
||||
@patch('instructor_task.tasks_helper.iterate_grades_for')
|
||||
def test_unicode_in_csv_header(self, mock_iterate_grades_for, _mock_current_task):
|
||||
"""
|
||||
Tests that CSV grade report works if unicode in headers.
|
||||
"""
|
||||
# mock a response from `iterate_grades_for`
|
||||
mock_iterate_grades_for.return_value = [
|
||||
(
|
||||
self.create_student('username', 'student@example.com'),
|
||||
{'section_breakdown': [{'label': u'\u8282\u540e\u9898 01'}], 'percent': 0},
|
||||
'Cannot grade student'
|
||||
)
|
||||
]
|
||||
result = upload_grades_csv(None, None, self.course.id, None, 'graded')
|
||||
self.assertDictContainsSubset({'attempted': 1, 'succeeded': 1, 'failed': 0}, result)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestStudentReport(TestReportMixin, InstructorTaskCourseTestCase):
|
||||
|
||||
Reference in New Issue
Block a user