Skip to content

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

Add test for street_address being too long

Ania Warzecha2cfe3bfb24f5
diff --git a/saleor/account/i18n.py b/saleor/account/i18n.py
index 97d6255594..6d7c03082b 100644
--- a/saleor/account/i18n.py
+++ b/saleor/account/i18n.py
@@ -173,7 +173,12 @@ class CountryAwareAddressForm(AddressForm):
def validate_address(self, data):
try:
data["country_code"] = data.get("country", "")
- data["street_address"] = f'{data.get("street_address_1", "")}\n{data.get("street_address_2", "")}'
+
+ street_address_1 = data.get("street_address_1", "")
+ street_address_2 = data.get("street_address_2", "")
+ if street_address_1 or street_address_2:
+ data["street_address"] = f"{street_address_1}\n{street_address_2}"
+
normalized_data = i18naddress.normalize_address(data)
if getattr(self, "enable_normalization", True):
data = normalized_data
diff --git a/saleor/account/tests/test_account.py b/saleor/account/tests/test_account.py
index 06d57bdbf8..12b8bb23db 100644
--- a/saleor/account/tests/test_account.py
+++ b/saleor/account/tests/test_account.py
@@ -25,6 +25,7 @@ def test_address_form_for_country(country):
errors = form.errors
rules = i18naddress.get_validation_rules({"country_code": country})
required = rules.required_fields
+
if "street_address" in required:
assert "street_address_1" in errors
else:
@@ -59,6 +60,30 @@ def test_address_form_postal_code_validation():
assert "postal_code" in errors
+def test_address_form_long_street_address_validation():
+ data = {
+ "city": "test",
+ "city_area": "test",
+ "company_name": "test",
+ "first_name": "Amelia",
+ "last_name": "Doe",
+ "country": "US",
+ "country_area": "IN",
+ "phone": "",
+ "postal_code": "46802",
+ "street_address_1": (
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut "
+ "labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris "
+ "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit "
+ "esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt "
+ "in culpa qui officia deserunt mollit anim id est laborum"
+ ),
+ }
+ form = forms.get_address_form(data, country_code="US")
+ errors = form.errors
+ assert "street_address_1" in errors
+
+
@pytest.mark.parametrize(
("country", "phone", "is_valid"),
[
@@ -183,11 +208,6 @@ def test_copy_address(address):
assert copied_address == address
-def test_compare_addresses(address):
- copied_address = address.get_copy()
- assert address == copied_address
-
-
def test_compare_addresses_with_country_object(address):
copied_address = address.get_copy()
copied_address.country = Country("PL")