1616from common .djangoapps .student .tests .factories import UserFactory
1717from common .djangoapps .third_party_auth import pipeline
1818from common .djangoapps .third_party_auth .tests .testutil import ThirdPartyAuthTestMixin , simulate_running_pipeline
19- from openedx .core .djangoapps .site_configuration .tests .test_util import with_site_configuration
2019from openedx .core .djangoapps .geoinfo .api import country_code_from_ip
20+ from openedx .core .djangoapps .site_configuration .tests .test_util import with_site_configuration
2121from openedx .core .djangoapps .user_api .tests .test_views import UserAPITestCase
22+ from openedx .core .djangoapps .user_authn .api .tests .test_data import mfe_context_data_keys
2223from openedx .core .djangolib .testing .utils import skip_unless_lms
2324
2425
@@ -42,6 +43,7 @@ def setUp(self): # pylint: disable=arguments-differ
4243 hostname = socket .gethostname ()
4344 ip_address = socket .gethostbyname (hostname )
4445 self .country_code = country_code_from_ip (ip_address )
46+ self .pipeline_user_details = {}
4547
4648 # Several third party auth providers are created for these tests:
4749 self .configure_google_provider (enabled = True , visible = True )
@@ -93,21 +95,34 @@ def get_context(self, params=None, current_provider=None, backend_name=None, add
9395 """
9496 Returns the MFE context
9597 """
98+
99+ if add_user_details :
100+ self .pipeline_user_details .update (
101+ {
102+ 'username' : None ,
103+ 'email' : 'test@test.com' ,
104+ 'name' : None ,
105+ 'firstName' : None ,
106+ 'lastName' : None
107+ }
108+ )
109+
96110 return {
97- 'context_data ' : {
111+ 'contextData ' : {
98112 'currentProvider' : current_provider ,
99113 'platformName' : settings .PLATFORM_NAME ,
100114 'providers' : self .get_provider_data (params ) if params else [],
101115 'secondaryProviders' : [],
102116 'finishAuthUrl' : pipeline .get_complete_url (backend_name ) if backend_name else None ,
103117 'errorMessage' : None ,
104118 'registerFormSubmitButtonText' : 'Create Account' ,
119+ 'autoSubmitRegForm' : False ,
105120 'syncLearnerProfileData' : False ,
106- 'pipeline_user_details ' : { 'email' : 'test@test.com' } if add_user_details else {} ,
107- 'countryCode ' : self .country_code
121+ 'countryCode ' : self . country_code ,
122+ 'pipelineUserDetails ' : self .pipeline_user_details ,
108123 },
109- 'registration_fields ' : {},
110- 'optional_fields ' : {
124+ 'registrationFields ' : {},
125+ 'optionalFields ' : {
111126 'extended_profile' : [],
112127 },
113128 }
@@ -182,7 +197,7 @@ def test_tpa_hint(self):
182197 })
183198
184199 response = self .client .get (self .url , self .query_params )
185- assert response .data ['context_data ' ]['providers' ] == provider_data
200+ assert response .data ['contextData ' ]['providers' ] == provider_data
186201
187202 def test_user_country_code (self ):
188203 """
@@ -191,7 +206,7 @@ def test_user_country_code(self):
191206 response = self .client .get (self .url , self .query_params )
192207
193208 assert response .status_code == 200
194- assert response .data ['context_data ' ]['countryCode' ] == self .country_code
209+ assert response .data ['contextData ' ]['countryCode' ] == self .country_code
195210
196211 @override_settings (
197212 ENABLE_DYNAMIC_REGISTRATION_FIELDS = True ,
@@ -205,7 +220,7 @@ def test_required_fields_not_configured(self):
205220 self .query_params .update ({'is_register_page' : True })
206221 response = self .client .get (self .url , self .query_params )
207222 assert response .status_code == status .HTTP_200_OK
208- assert response .data ['registration_fields ' ]['fields' ] == {}
223+ assert response .data ['registrationFields ' ]['fields' ] == {}
209224
210225 @with_site_configuration (
211226 configuration = {
@@ -223,8 +238,9 @@ def test_required_field_order(self):
223238 """
224239 self .query_params .update ({'is_register_page' : True })
225240 response = self .client .get (self .url , self .query_params )
241+
226242 assert response .status_code == status .HTTP_200_OK
227- assert list (response .data ['registration_fields ' ]['fields' ].keys ()) == ['first_name' , 'last_name' , 'state' ]
243+ assert list (response .data ['registrationFields ' ]['fields' ].keys ()) == ['first_name' , 'last_name' , 'state' ]
228244
229245 @override_settings (
230246 ENABLE_DYNAMIC_REGISTRATION_FIELDS = True ,
@@ -248,7 +264,7 @@ def test_optional_field_has_no_description(self):
248264 self .query_params .update ({'is_register_page' : True })
249265 response = self .client .get (self .url , self .query_params )
250266 assert response .status_code == status .HTTP_200_OK
251- assert response .data ['optional_fields ' ]['fields' ] == expected_response
267+ assert response .data ['optionalFields ' ]['fields' ] == expected_response
252268
253269 @with_site_configuration (
254270 configuration = {
@@ -282,8 +298,9 @@ def test_configurable_select_option_fields(self):
282298 }
283299 self .query_params .update ({'is_register_page' : True })
284300 response = self .client .get (self .url , self .query_params )
301+
285302 assert response .status_code == status .HTTP_200_OK
286- assert response .data ['optional_fields ' ]['fields' ] == expected_response
303+ assert response .data ['optionalFields ' ]['fields' ] == expected_response
287304
288305 @with_site_configuration (
289306 configuration = {
@@ -302,7 +319,7 @@ def test_optional_field_order(self):
302319 self .query_params .update ({'is_register_page' : True })
303320 response = self .client .get (self .url , self .query_params )
304321 assert response .status_code == status .HTTP_200_OK
305- assert list (response .data ['optional_fields ' ]['fields' ].keys ()) == ['specialty' , 'goals' ]
322+ assert list (response .data ['optionalFields ' ]['fields' ].keys ()) == ['specialty' , 'goals' ]
306323
307324 @with_site_configuration (
308325 configuration = {
@@ -322,7 +339,7 @@ def test_field_not_available_in_extended_profile_config(self):
322339 self .query_params .update ({'is_register_page' : True })
323340 response = self .client .get (self .url , self .query_params )
324341 assert response .status_code == status .HTTP_200_OK
325- assert list (response .data ['registration_fields ' ]['fields' ].keys ()) == ['specialty' ]
342+ assert list (response .data ['registrationFields ' ]['fields' ].keys ()) == ['specialty' ]
326343
327344 @override_settings (
328345 ENABLE_DYNAMIC_REGISTRATION_FIELDS = True ,
@@ -333,9 +350,34 @@ def test_response_structure(self):
333350 Test that API return valid response dictionary with both required and optional fields
334351 """
335352 response = self .client .get (self .url , self .query_params )
336-
337353 assert response .data == self .get_context ()
338354
355+ def test_mfe_context_api_serialized_response (self ):
356+ """
357+ Test MFE Context API serialized response
358+ """
359+ response = self .client .get (self .url , self .query_params )
360+ self .assertEqual (response .status_code , status .HTTP_200_OK )
361+
362+ params = {
363+ 'next' : self .query_params ['next' ]
364+ }
365+
366+ self .assertEqual (
367+ response .data ,
368+ self .get_context (params )
369+ )
370+
371+ def test_mfe_context_api_response_keys (self ):
372+ """
373+ Test MFE Context API response keys
374+ """
375+ response = self .client .get (self .url , self .query_params )
376+ self .assertEqual (response .status_code , status .HTTP_200_OK )
377+
378+ response_keys = set (response .data .keys ())
379+ self .assertSetEqual (response_keys , mfe_context_data_keys )
380+
339381
340382@skip_unless_lms
341383class SendAccountActivationEmail (UserAPITestCase ):
0 commit comments