From 4bd0981e688af7eb0c00eea56406840ca805f2f7 Mon Sep 17 00:00:00 2001 From: Blue Date: Wed, 14 Feb 2024 13:51:25 +0500 Subject: [PATCH] fix: update registration api response and replace username with name (#34226) Update api registration api response and add full_name in response --- openedx/core/djangoapps/user_authn/views/register.py | 2 +- .../djangoapps/user_authn/views/tests/test_register.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/openedx/core/djangoapps/user_authn/views/register.py b/openedx/core/djangoapps/user_authn/views/register.py index 04b0ae678f..c7889d96a7 100644 --- a/openedx/core/djangoapps/user_authn/views/register.py +++ b/openedx/core/djangoapps/user_authn/views/register.py @@ -590,7 +590,7 @@ class RegistrationView(APIView): redirect_to, root_url = get_next_url_for_login_page(request, include_host=True) redirect_url = get_redirect_url_with_host(root_url, redirect_to) - authenticated_user = {'username': user.username, 'user_id': user.id} + authenticated_user = {'username': user.username, 'full_name': user.profile.name, 'user_id': user.id} response = self._create_response( request, {'authenticated_user': authenticated_user}, status_code=200, redirect_url=redirect_url ) diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_register.py b/openedx/core/djangoapps/user_authn/views/tests/test_register.py index 20261ab9a9..3de71534f2 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_register.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_register.py @@ -2258,6 +2258,11 @@ class RegistrationViewTestV2(RegistrationViewTestV1): @override_settings(LOGIN_REDIRECT_WHITELIST=['openedx.service']) @skip_unless_lms def test_register_success_with_redirect(self, next_url, course_id, expected_redirect): + expected_response = { + 'username': self.USERNAME, + 'full_name': self.NAME, + 'user_id': 1 + } post_params = { "email": self.EMAIL, "name": self.NAME, @@ -2282,7 +2287,7 @@ class RegistrationViewTestV2(RegistrationViewTestV1): # Check that authenticated user details are also returned in # the response for successful registration decoded_response = json.loads(response.content.decode('utf-8')) - assert decoded_response['authenticated_user'] == {'username': self.USERNAME, 'user_id': 1} + assert decoded_response['authenticated_user'] == expected_response @mock.patch('openedx.core.djangoapps.user_authn.views.register._record_is_marketable_attribute') def test_logs_for_error_when_setting_is_marketable_attribute(self, set_is_marketable_attr):