Пример #1
0
def test_validate_min_money():
    validator = MinMoneyValidator(Money(5, 'BTC'))
    validator(Money('5.00', 'BTC'))
    with pytest.raises(ValidationError):
        validator(Money('4.99', 'BTC'))
    with pytest.raises(ValueError):
        validator(Money('5.00', 'USD'))
Пример #2
0
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'))
                       ])
Пример #3
0
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_min_money_validation_passes_if_less_amount_is_in_different_currency():
    """It's incomparable, so it should be accepted."""
    validator = MinMoneyValidator(Money(5, "BTC"))
    validator(Money("5.00", "USD"))
    validator(Money("4.99", "USD"))
def test_min_money_validation_raises_error_if_less_money():
    validator = MinMoneyValidator(Money(5, "BTC"))
    validator(Money("5.00", "BTC"))
    with pytest.raises(ValidationError):
        validator(Money("4.99", "BTC"))