diff --git a/lms/djangoapps/user_api/serializers.py b/lms/djangoapps/user_api/serializers.py index 42c42cf891..8822817933 100644 --- a/lms/djangoapps/user_api/serializers.py +++ b/lms/djangoapps/user_api/serializers.py @@ -14,8 +14,8 @@ class UserSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = User # This list is the minimal set required by the notification service - fields = ("id", "email", "name") - read_only_fields = ("id", "email") + fields = ("id", "email", "name", "username") + read_only_fields = ("id", "email", "username") class UserPreferenceSerializer(serializers.HyperlinkedModelSerializer): diff --git a/lms/djangoapps/user_api/tests/test_views.py b/lms/djangoapps/user_api/tests/test_views.py index 1e8e6f8074..075c1f0d9f 100644 --- a/lms/djangoapps/user_api/tests/test_views.py +++ b/lms/djangoapps/user_api/tests/test_views.py @@ -74,7 +74,7 @@ class UserApiTestCase(TestCase): def assertUserIsValid(self, user): """Assert that the given user result is valid""" - self.assertItemsEqual(user.keys(), ["email", "id", "name", "url"]) + self.assertItemsEqual(user.keys(), ["email", "id", "name", "username", "url"]) self.assertSelfReferential(user) def assertPrefIsValid(self, pref): @@ -196,7 +196,8 @@ class UserViewSetTest(UserApiTestCase): "email": user.email, "id": user.id, "name": user.profile.name, - "url": uri, + "username": user.username, + "url": uri } ) @@ -334,6 +335,7 @@ class UserPreferenceViewSetTest(UserApiTestCase): "email": pref.user.email, "id": pref.user.id, "name": pref.user.profile.name, + "username": pref.user.username, "url": self.get_uri_for_user(pref.user), }, "key": pref.key,