Skip to content
Closed
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
62 changes: 62 additions & 0 deletions openedx/core/djangoapps/user_authn/views/tests/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,68 @@ def test_country_overrides(self):

self.assertContains(response, 'Kosovo')

def test_unit_country_default_is_optional(self):
"""
Unit test for Bug #38195.

The platform default for REGISTRATION_EXTRA_FIELDS['country'] must be
'optional' so the country list is exposed via the registration form
API. The Profile MFE depends on this API to render its country
dropdown.
"""
assert settings.REGISTRATION_EXTRA_FIELDS.get('country') == 'optional'

def test_integration_country_field_exposed_by_default(self):
"""
Integration test for Bug #38195.

With default settings, the registration form API response must include
the country field populated with its options list, so consumers like
the Profile MFE can render a country dropdown.
"""
response = self.client.get(self.url)
self.assertHttpOK(response)
form_desc = json.loads(response.content.decode('utf-8'))
field_names = [field['name'] for field in form_desc['fields']]
assert 'country' in field_names, \
"country field must be exposed by default so Profile MFE gets the list"

country_field = next(f for f in form_desc['fields'] if f['name'] == 'country')
assert country_field['type'] == 'select'
assert len(country_field['options']) > 0, \
"country field must ship with the full list of country options"

def test_bug_38195_regression_profile_mfe_gets_country_options(self):
"""
Regression test for Bug #38195.

Before the fix, the default value of REGISTRATION_EXTRA_FIELDS['country']
was 'hidden', which caused RegistrationFormFactory._is_field_visible
to exclude the country field entirely from the registration form API
response. The Profile MFE, which consumes this API to get the country
list, had no country options to display.

This test hits the same API endpoint the Profile MFE uses and
verifies the country options are present in the response payload.
"""
response = self.client.get(self.url)
self.assertHttpOK(response)
self.assertContains(response, 'country')
self.assertContains(response, 'Kosovo')

@override_settings(REGISTRATION_EXTRA_FIELDS={"country": "hidden"})
def test_operator_can_still_hide_country(self):
"""
Ensures the default change does not remove the operator's ability to
hide the country field via override. Bug #38195.
"""
response = self.client.get(self.url)
self.assertHttpOK(response)
form_desc = json.loads(response.content.decode('utf-8'))
field_names = [field['name'] for field in form_desc['fields']]
assert 'country' not in field_names, \
"operator override to 'hidden' must still remove the country field"

def test_password_with_spaces(self):
"""Test that spaces are stripped correctly from password while creating an account."""
unstripped_password = self.PASSWORD + ' '
Expand Down
6 changes: 5 additions & 1 deletion openedx/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1686,7 +1686,11 @@ def add_optional_apps(optional_apps, installed_apps):
'honor_code': 'required',
'terms_of_service': 'hidden',
'city': 'hidden',
'country': 'hidden',
# 'country' defaults to 'optional' so the country list is exposed via the
# registration form API, which the Profile MFE relies on to render the
# country dropdown. Operators can override to 'hidden' or 'required' via
# site configuration or YAML env config. See issue #38195.
'country': 'optional',
}

######################### Course Enrollment Modes ##########################
Expand Down