diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index 89e81d6529..28e1e6ed99 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -100,7 +100,7 @@ def anonymous_id_for_user(user, course_id, save=True): hasher.update(settings.SECRET_KEY) hasher.update(unicode(user.id)) if course_id: - hasher.update(course_id.to_deprecated_string()) + hasher.update(course_id.to_deprecated_string().encode('utf-8')) digest = hasher.hexdigest() if not hasattr(user, '_anonymous_id'): diff --git a/common/djangoapps/student/tests/tests.py b/common/djangoapps/student/tests/tests.py index 7e899e4ef2..dd060f1186 100644 --- a/common/djangoapps/student/tests/tests.py +++ b/common/djangoapps/student/tests/tests.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """ This file demonstrates writing tests using the unittest module. These will pass when you run "manage.py test". @@ -736,3 +737,11 @@ class AnonymousLookupTable(TestCase): real_user = user_by_anonymous_id(anonymous_id) self.assertEqual(self.user, real_user) self.assertEqual(anonymous_id, anonymous_id_for_user(self.user, self.course.id, save=False)) + + def test_roundtrip_with_unicode_course_id(self): + course2 = CourseFactory.create(org=self.COURSE_ORG, display_name=u"Omega Course Ω", number=self.COURSE_SLUG) + CourseEnrollment.enroll(self.user, course2.id) + anonymous_id = anonymous_id_for_user(self.user, course2.id) + real_user = user_by_anonymous_id(anonymous_id) + self.assertEqual(self.user, real_user) + self.assertEqual(anonymous_id, anonymous_id_for_user(self.user, course2.id, save=False))