diff --git a/pydantic_extra_types/currency_code.py b/pydantic_extra_types/currency_code.py index 7767ae0..89c12da 100644 --- a/pydantic_extra_types/currency_code.py +++ b/pydantic_extra_types/currency_code.py @@ -68,6 +68,7 @@ def _validate(cls, currency_code: str, _: core_schema.ValidationInfo) -> str: Raises: PydanticCustomError: If the ISO 4217 currency code is not valid. """ + currency_code = currency_code.upper() if currency_code not in cls.allowed_currencies: raise PydanticCustomError( 'ISO4217', 'Invalid ISO 4217 currency code. See https://en.wikipedia.org/wiki/ISO_4217' @@ -128,6 +129,7 @@ def _validate(cls, currency_symbol: str, _: core_schema.ValidationInfo) -> str: Raises: PydanticCustomError: If the ISO 4217 currency code is not valid or is bond, precious metal or testing code. """ + currency_symbol = currency_symbol.upper() if currency_symbol not in cls.allowed_currencies: raise PydanticCustomError( 'InvalidCurrency', diff --git a/tests/test_currency_code.py b/tests/test_currency_code.py index 78f54fe..c3ca4d0 100644 --- a/tests/test_currency_code.py +++ b/tests/test_currency_code.py @@ -25,6 +25,12 @@ def test_ISO4217_code_ok(currency: str): assert model.model_dump() == {'currency': currency} # test serialization +@pytest.mark.parametrize('currency', ['USD', 'usd', 'UsD']) +def test_ISO4217_code_ok_lower_case(currency: str): + model = ISO4217CheckingModel(currency=currency) + assert model.currency == currency.upper() + + @pytest.mark.parametrize( 'currency', filter( @@ -38,6 +44,12 @@ def test_everyday_code_ok(currency: str): assert model.model_dump() == {'currency': currency} # test serialization +@pytest.mark.parametrize('currency', ['USD', 'usd', 'UsD']) +def test_everyday_code_ok_lower_case(currency: str): + model = CurrencyCheckingModel(currency=currency) + assert model.currency == currency.upper() + + def test_ISO4217_fails(): with pytest.raises( ValidationError,