From 6af95b46e7772ce88da2073fa1b447a80b131d16 Mon Sep 17 00:00:00 2001 From: Syed Sajjad Hussain Shah <52817156+syedsajjadkazmii@users.noreply.github.com> Date: Thu, 27 Apr 2023 18:56:58 +0500 Subject: [PATCH] fix: pipeline_user_details serializer error on mfe context response (#32146) * fix: pipeline_user_details serializer error on mfe context response * fix: failed tests for mfe context API --------- Co-authored-by: Syed Sajjad Hussain Shah Co-authored-by: Shahbaz Shabbir --- .../djangoapps/user_authn/api/tests/test_views.py | 13 ++++++++++--- openedx/core/djangoapps/user_authn/serializers.py | 7 ++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/openedx/core/djangoapps/user_authn/api/tests/test_views.py b/openedx/core/djangoapps/user_authn/api/tests/test_views.py index 025094d701..75111a792f 100644 --- a/openedx/core/djangoapps/user_authn/api/tests/test_views.py +++ b/openedx/core/djangoapps/user_authn/api/tests/test_views.py @@ -42,8 +42,7 @@ class MFEContextViewTest(ThirdPartyAuthTestMixin, APITestCase): hostname = socket.gethostname() ip_address = socket.gethostbyname(hostname) self.country_code = country_code_from_ip(ip_address) - self.pipeline_user_details = {'username': None, 'email': None, 'name': None, - 'firstName': None, 'lastName': None} + self.pipeline_user_details = {} # Several third party auth providers are created for these tests: self.configure_google_provider(enabled=True, visible=True) @@ -97,7 +96,15 @@ class MFEContextViewTest(ThirdPartyAuthTestMixin, APITestCase): """ if add_user_details: - self.pipeline_user_details.update({'email': 'test@test.com'}) + self.pipeline_user_details.update( + { + 'username': None, + 'email': 'test@test.com', + 'name': None, + 'firstName': None, + 'lastName': None + } + ) return { 'contextData': { diff --git a/openedx/core/djangoapps/user_authn/serializers.py b/openedx/core/djangoapps/user_authn/serializers.py index 48918a89f7..9bbed367e6 100644 --- a/openedx/core/djangoapps/user_authn/serializers.py +++ b/openedx/core/djangoapps/user_authn/serializers.py @@ -53,7 +53,12 @@ class ContextDataSerializer(serializers.Serializer): autoSubmitRegForm = serializers.BooleanField(default=False) syncLearnerProfileData = serializers.BooleanField(default=False) countryCode = serializers.CharField(allow_null=True) - pipelineUserDetails = PipelineUserDetailsSerializer(source='pipeline_user_details', allow_null=True) + pipelineUserDetails = serializers.SerializerMethodField() + + def get_pipelineUserDetails(self, obj): + if obj.get('pipeline_user_details'): + return PipelineUserDetailsSerializer(obj.get('pipeline_user_details')).data + return {} class MFEContextSerializer(serializers.Serializer):