def test_validate_max_money(): validator = MaxMoneyValidator(Money(5, 'BTC')) validator(Money('5.00', 'BTC')) with pytest.raises(ValidationError): validator(Money('5.01', 'BTC')) with pytest.raises(ValueError): validator(Money('5.00', 'USD'))
class ValidatedPriceForm(forms.Form): price = MoneyField(currency='USD', max_digits=9, decimal_places=2, validators=[ MinMoneyValidator(Money(5, currency='USD')), MaxMoneyValidator(Money(15, currency='USD')) ])
class ValidatedPriceForm(forms.Form): price = MoneyField( available_currencies=AVAILABLE_CURRENCIES, max_digits=9, decimal_places=2, validators=[ MinMoneyValidator(Money(5, "USD")), MaxMoneyValidator(Money(15, "USD")), ], )
def test_max_money_validation_passes_if_greater_amount_is_in_different_currency( ): """It's incomparable, so it should be accepted.""" validator = MaxMoneyValidator(Money(5, "BTC")) validator(Money("5.00", "USD")) validator(Money("5.01", "USD"))
def test_max_money_validation_raises_error_if_greater_money(): validator = MaxMoneyValidator(Money(5, "BTC")) validator(Money("5.00", "BTC")) with pytest.raises(ValidationError): validator(Money("5.01", "BTC"))