Fix unicode-related failures in CSV upload.

TNL-586
This commit is contained in:
Daniel Friedman
2014-10-08 11:46:55 -04:00
parent 1809a28b89
commit 736ed94064
3 changed files with 44 additions and 7 deletions

View File

@@ -33,16 +33,16 @@ class TestReport(ModuleStoreTestCase):
if os.path.exists(settings.GRADES_DOWNLOAD['ROOT_PATH']):
shutil.rmtree(settings.GRADES_DOWNLOAD['ROOT_PATH'])
def create_student(self, username, email):
student = UserFactory.create(username=username, email=email)
CourseEnrollmentFactory.create(user=student, course_id=self.course.id)
@ddt.ddt
class TestInstructorGradeReport(TestReport):
"""
Tests that CSV grade report generation works.
"""
def create_student(self, username, email):
student = UserFactory.create(username=username, email=email)
CourseEnrollmentFactory.create(user=student, course_id=self.course.id)
@ddt.data([u'student@example.com', u'ni\xf1o@example.com'])
def test_unicode_emails(self, emails):
"""
@@ -60,6 +60,7 @@ class TestInstructorGradeReport(TestReport):
self.assertEquals(result['succeeded'], result['attempted'])
@ddt.ddt
class TestStudentReport(TestReport):
"""
Tests that CSV student profile report generation works.
@@ -73,3 +74,27 @@ class TestStudentReport(TestReport):
self.assertEquals(len(links), 1)
self.assertEquals(result, UPDATE_STATUS_SUCCEEDED)
@ddt.data([u'student', u'student\xec'])
def test_unicode_usernames(self, students):
"""
Test that students with unicode characters in their usernames
are handled.
"""
for i, student in enumerate(students):
self.create_student(username=student, email='student{0}@example.com'.format(i))
self.current_task = Mock()
self.current_task.update_state = Mock()
task_input = {
'features': [
'id', 'username', 'name', 'email', 'language', 'location',
'year_of_birth', 'gender', 'level_of_education', 'mailing_address',
'goals'
]
}
with patch('instructor_task.tasks_helper._get_current_task') as mock_current_task:
mock_current_task.return_value = self.current_task
result = push_students_csv_to_s3(None, None, self.course.id, task_input, 'calculated')
#This assertion simply confirms that the generation completed with no errors
self.assertEquals(result, UPDATE_STATUS_SUCCEEDED)