diff --git a/lms/djangoapps/discussion/notification_prefs/tests.py b/lms/djangoapps/discussion/notification_prefs/tests.py index 6a665160e3..6efe5e3f90 100644 --- a/lms/djangoapps/discussion/notification_prefs/tests.py +++ b/lms/djangoapps/discussion/notification_prefs/tests.py @@ -53,7 +53,7 @@ class NotificationPrefViewTest(UrlResetMixin, TestCase): def create_prefs(self): """Create all test preferences in the database""" for (user, token) in self.tokens.items(): - UserPreference.objects.create(user=user, key=NOTIFICATION_PREF_KEY, value=token) + UserPreference.objects.get_or_create(user=user, key=NOTIFICATION_PREF_KEY, value=token) def assertPrefValid(self, user): """Ensure that the correct preference for the user is persisted""" diff --git a/lms/djangoapps/discussion/notification_prefs/views.py b/lms/djangoapps/discussion/notification_prefs/views.py index d9411c50b8..a91996e623 100644 --- a/lms/djangoapps/discussion/notification_prefs/views.py +++ b/lms/djangoapps/discussion/notification_prefs/views.py @@ -71,7 +71,7 @@ class UsernameCipher(object): encryptor = aes_cipher.encryptor() padder = PKCS7(AES.block_size).padder() padded = padder.update(username.encode("utf-8")) + padder.finalize() - return urlsafe_b64encode(initialization_vector + encryptor.update(padded) + encryptor.finalize()) + return urlsafe_b64encode(initialization_vector + encryptor.update(padded) + encryptor.finalize()).decode() @staticmethod def decrypt(token): @@ -187,7 +187,7 @@ def set_subscription(request, token, subscribe): # pylint: disable=unused-argum success, the response will contain a page indicating success. """ try: - username = UsernameCipher().decrypt(token.encode()) + username = UsernameCipher().decrypt(token.encode()).decode() user = User.objects.get(username=username) except UnicodeDecodeError: raise Http404("base64url") diff --git a/lms/djangoapps/discussion/rest_api/forms.py b/lms/djangoapps/discussion/rest_api/forms.py index 05b1f367dc..85a879a7b9 100644 --- a/lms/djangoapps/discussion/rest_api/forms.py +++ b/lms/djangoapps/discussion/rest_api/forms.py @@ -167,7 +167,7 @@ class CourseDiscussionRolesForm(CourseDiscussionSettingsForm): (FORUM_ROLE_GROUP_MODERATOR, FORUM_ROLE_GROUP_MODERATOR), ) rolename = ChoiceField( - ROLE_CHOICES, + choices=ROLE_CHOICES, error_messages={u"invalid_choice": u"Role '%(value)s' does not exist"} )