Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix postal code validation logic

Patryk Zawadzkiaa445cc2ecc3
diff --git a/saleor/userprofile/forms.py b/saleor/userprofile/forms.py
index 1f39f6309d..cad86c6b27 100644
--- a/saleor/userprofile/forms.py
+++ b/saleor/userprofile/forms.py
@@ -80,8 +80,7 @@ class AddressForm(forms.ModelForm):
self.add_error('country_area', error)
if 'postal_code' in errors:
if errors['postal_code'] == 'invalid':
- postal_code_example = validation_data[
- 'postal_code_example']
+ postal_code_example = validation_data.postal_code_example
if postal_code_example:
error = _(
'Invalid postal code. Ex. %(example)s') % {
diff --git a/saleor/userprofile/test_userprofile.py b/saleor/userprofile/test_userprofile.py
index 9794c71624..88bacf8b24 100644
--- a/saleor/userprofile/test_userprofile.py
+++ b/saleor/userprofile/test_userprofile.py
@@ -33,3 +33,14 @@ def test_address_form_for_country(country):
assert 'postal_code' in errors
else:
assert 'postal_code' not in errors
+
+
+def test_address_form_postal_code_validation():
+ data = {
+ 'first_name': 'John',
+ 'last_name': 'Doe',
+ 'country': 'PE',
+ 'postal_code': 'XXX'}
+ form = forms.AddressForm(data)
+ errors = form.errors
+ assert 'postal_code' in errors