diff --git a/src/openklant/utils/tests/test_validators.py b/src/openklant/utils/tests/test_validators.py index 143dc9d5..dd316f3c 100644 --- a/src/openklant/utils/tests/test_validators.py +++ b/src/openklant/utils/tests/test_validators.py @@ -7,6 +7,7 @@ validate_no_space, validate_phone_number, validate_postal_code, + validate_country, ) @@ -147,3 +148,22 @@ def test_validate_iban(self): self.assertIsNone(validate_iban("ab1299999999999")) self.assertIsNone(validate_iban("ab129")) self.assertIsNone(validate_iban("ab12aaaaaaaaaa")) + + def test_validate_country(self): + invalid_codes = [ + "", + "1", + "10", + "ZZ", + "1Z", + ] + for code in invalid_codes: + self.assertRaisesMessage( + ValidationError, + "Ongeldige landcode, de code moet behoren tot de ISO 3166-standaard", + validate_country, + code, + ) + + self.assertIsNone(validate_country("NL")) + self.assertIsNone(validate_country("nl")) diff --git a/src/openklant/utils/validators.py b/src/openklant/utils/validators.py index 2f657a9c..5bca9349 100644 --- a/src/openklant/utils/validators.py +++ b/src/openklant/utils/validators.py @@ -14,7 +14,7 @@ def validate_country(value) -> None: """ if not value.upper() in COUNTRIES_DICT.keys(): raise ValidationError( - _("Ongeldige landcode, de code moet behoren tot de ISO 3166-standaard.") + _("Ongeldige landcode, de code moet behoren tot de ISO 3166-standaard") )