Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 80 additions & 1 deletion openedx/core/djangoapps/user_authn/api/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SERIALIZED_MFE_CONTEXT_WITH_TPA_DATA,
SERIALIZED_MFE_CONTEXT_WITHOUT_TPA_DATA,
)
from openedx.core.djangoapps.user_authn.serializers import MFEContextSerializer
from openedx.core.djangoapps.user_authn.serializers import ContextDataSerializer, MFEContextSerializer


class TestMFEContextSerializer(TestCase):
Expand Down Expand Up @@ -44,3 +44,82 @@ def test_mfe_context_serializer_default_response(self):
serialized_data,
SERIALIZED_MFE_CONTEXT_WITHOUT_TPA_DATA
)

def test_context_data_serializer_includes_enterprise_branding_when_present(self):
context_data = {
'currentProvider': None,
'platformName': 'Open edX',
'providers': [],
'secondaryProviders': [],
'finishAuthUrl': None,
'errorMessage': None,
'registerFormSubmitButtonText': None,
'autoSubmitRegForm': False,
'syncLearnerProfileData': False,
'countryCode': None,
'welcomePageRedirectUrl': None,
'pipeline_user_details': {
'username': 'jdoe',
'email': 'jdoe@example.com',
'fullname': 'Jane Doe',
'first_name': 'Jane',
'last_name': 'Doe',
},
'enterpriseBranding': {
'enterpriseName': 'Example Enterprise',
'enterpriseLogoUrl': 'https://example.com/logo.png',
'enterpriseBrandedWelcomeString': 'Welcome, Enterprise Learner',
'enterpriseSlug': 'example-enterprise',
'platformWelcomeString': 'Welcome to the Platform',
},
}

serialized = ContextDataSerializer(context_data).data

self.assertDictEqual(
serialized['enterpriseBranding'],
{
'enterpriseName': 'Example Enterprise',
'enterpriseLogoUrl': 'https://example.com/logo.png',
'enterpriseBrandedWelcomeString': 'Welcome, Enterprise Learner',
'enterpriseSlug': 'example-enterprise',
'platformWelcomeString': 'Welcome to the Platform',
}
)

self.assertDictEqual(
serialized['pipelineUserDetails'],
{
'username': 'jdoe',
'email': 'jdoe@example.com',
'name': 'Jane Doe',
'firstName': 'Jane',
'lastName': 'Doe',
}
)

def test_context_data_serializer_omits_enterprise_branding_when_absent(self):
context_data = {
'currentProvider': None,
'platformName': 'Open edX',
'providers': [],
'secondaryProviders': [],
'finishAuthUrl': None,
'errorMessage': None,
'registerFormSubmitButtonText': None,
'autoSubmitRegForm': False,
'syncLearnerProfileData': False,
'countryCode': None,
'welcomePageRedirectUrl': None,
'pipeline_user_details': {
'username': 'jdoe',
'email': 'jdoe@example.com',
'fullname': 'Jane Doe',
'first_name': 'Jane',
'last_name': 'Doe',
},
}

serialized = ContextDataSerializer(context_data).data

self.assertNotIn('enterpriseBranding', serialized)
4 changes: 4 additions & 0 deletions openedx/core/djangoapps/user_authn/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class ContextDataSerializer(serializers.Serializer):
countryCode = serializers.CharField(allow_null=True)
welcomePageRedirectUrl = serializers.CharField(allow_null=True)
pipelineUserDetails = serializers.SerializerMethodField()
enterpriseBranding = EnterpriseBrandingSerializer(
allow_null=True,
required=False,
)

Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding enterpriseBranding as a nested serializer will cause the API to start emitting an enterpriseBranding key whenever the upstream context includes it. In openedx/core/djangoapps/user_authn/views/utils.py:get_mfe_context the context is updated with 'enterpriseBranding': enterprise_branding even when enterprise_branding is None, so this change will likely introduce "enterpriseBranding": null in many responses where the key was previously absent. If the desired contract is to omit the key when there is no enterprise branding, consider either (a) only adding the key upstream when a branding dict exists, or (b) overriding ContextDataSerializer.to_representation to drop enterpriseBranding when it is None.

Suggested change
def to_representation(self, instance):
"""
Customize representation to omit the 'enterpriseBranding' key
when there is no enterprise branding data.
"""
data = super().to_representation(instance)
if data.get('enterpriseBranding') is None:
data.pop('enterpriseBranding', None)
return data

Copilot uses AI. Check for mistakes.
def get_pipelineUserDetails(self, obj):
if obj.get('pipeline_user_details'):
Expand Down
Loading