Commit 6ff027ab by Douglas Hall Committed by GitHub

Merge pull request #15395 from open-craft/haikuginger/case-insensitive-country-code

Allow lower- and mixed-case country default values on registration form
parents aea407b1 5d363df5
...@@ -935,7 +935,15 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, UserAPITestCase): ...@@ -935,7 +935,15 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, UserAPITestCase):
} }
) )
def test_register_form_third_party_auth_running_google(self): @ddt.data(
('pk', 'PK'),
('Pk', 'PK'),
('pK', 'PK'),
('PK', 'PK'),
('us', 'US'),
)
@ddt.unpack
def test_register_form_third_party_auth_running_google(self, input_country_code, expected_country_code):
no_extra_fields_setting = {} no_extra_fields_setting = {}
country_options = ( country_options = (
[ [
...@@ -948,7 +956,7 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, UserAPITestCase): ...@@ -948,7 +956,7 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, UserAPITestCase):
{ {
"value": country_code, "value": country_code,
"name": unicode(country_name), "name": unicode(country_name),
"default": True if country_code == "PK" else False "default": True if country_code == expected_country_code else False
} }
for country_code, country_name in SORTED_COUNTRIES for country_code, country_name in SORTED_COUNTRIES
] ]
...@@ -960,7 +968,7 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, UserAPITestCase): ...@@ -960,7 +968,7 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, UserAPITestCase):
email="bob@example.com", email="bob@example.com",
fullname="Bob", fullname="Bob",
username="Bob123", username="Bob123",
country="PK" country=input_country_code
): ):
self._assert_password_field_hidden(no_extra_fields_setting) self._assert_password_field_hidden(no_extra_fields_setting)
self._assert_social_auth_provider_present(no_extra_fields_setting, provider) self._assert_social_auth_provider_present(no_extra_fields_setting, provider)
...@@ -1025,7 +1033,7 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, UserAPITestCase): ...@@ -1025,7 +1033,7 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, UserAPITestCase):
{ {
u"label": u"Country", u"label": u"Country",
u"name": u"country", u"name": u"country",
u"defaultValue": u"PK", u"defaultValue": expected_country_code,
u"type": u"select", u"type": u"select",
u"required": True, u"required": True,
u"options": country_options, u"options": country_options,
......
...@@ -787,6 +787,14 @@ class RegistrationView(APIView): ...@@ -787,6 +787,14 @@ class RegistrationView(APIView):
country_label = _(u"Country") country_label = _(u"Country")
error_msg = _(u"Please select your Country.") error_msg = _(u"Please select your Country.")
# If we set a country code, make sure it's uppercase for the sake of the form.
default_country = form_desc._field_overrides.get('country', {}).get('defaultValue')
if default_country:
form_desc.override_field_properties(
'country',
default=default_country.upper()
)
form_desc.add_field( form_desc.add_field(
"country", "country",
label=country_label, label=country_label,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment