Commit fbd9cc13 by Sarina Canelake

Merge pull request #5386 from open-craft/fix-anonymous-ids-unicode

Fix UnicodeError with anonymous student IDs
parents 0ed3a95d 8e326722
...@@ -102,7 +102,7 @@ def anonymous_id_for_user(user, course_id, save=True): ...@@ -102,7 +102,7 @@ def anonymous_id_for_user(user, course_id, save=True):
hasher.update(settings.SECRET_KEY) hasher.update(settings.SECRET_KEY)
hasher.update(unicode(user.id)) hasher.update(unicode(user.id))
if course_id: if course_id:
hasher.update(course_id.to_deprecated_string()) hasher.update(course_id.to_deprecated_string().encode('utf-8'))
digest = hasher.hexdigest() digest = hasher.hexdigest()
if not hasattr(user, '_anonymous_id'): if not hasattr(user, '_anonymous_id'):
......
# -*- coding: utf-8 -*-
""" """
This file demonstrates writing tests using the unittest module. These will pass This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test". when you run "manage.py test".
...@@ -736,3 +737,11 @@ class AnonymousLookupTable(TestCase): ...@@ -736,3 +737,11 @@ class AnonymousLookupTable(TestCase):
real_user = user_by_anonymous_id(anonymous_id) real_user = user_by_anonymous_id(anonymous_id)
self.assertEqual(self.user, real_user) self.assertEqual(self.user, real_user)
self.assertEqual(anonymous_id, anonymous_id_for_user(self.user, self.course.id, save=False)) 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))
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