def test_invalid_default(self): with self.assertRaises(TypeError): testfield = MoneyField( name='testfield', decimal_places=2, max_digits=8, default="1234.00 EUR", )
def test_both_fixed_currency_and_default_valid(self): testfield = MoneyField( name='testfield', decimal_places=2, max_digits=8, currency='USD', default=Money('1234.00', 'USD'), )
def test_both_default_and_currency_default(self): with self.assertRaises(FieldError): testfield = MoneyField( name='testfield', decimal_places=2, max_digits=8, currency_default='EUR', default=Money('1234.00', 'EUR'), )
def test_both_fixed_currency_and_currency_choices(self): with self.assertRaises(FieldError): testfield = MoneyField( name='testfield', decimal_places=2, max_digits=8, currency='USD', currency_choices=(('USD', 'USD'), ), )
class ChoicesCurrencyModel(models.Model): CURRENCY_CHOICES = ( ('EUR', 'EUR'), ('USD', 'USD'), ('CNY', 'CNY'), ) CURRENCY_DEFAULT = 'EUR' name = models.CharField(blank=True, max_length=100) price = MoneyField(decimal_places=2, max_digits=12, currency_choices=CURRENCY_CHOICES, currency_default=CURRENCY_DEFAULT)
class FixedCurrencyModel(models.Model): name = models.CharField(blank=True, max_length=100) price = MoneyField(decimal_places=2, max_digits=12, currency='EUR')
class SomeMoney(models.Model): field1 = models.CharField(blank=True, max_length=100) field2 = MoneyField(decimal_places=2, max_digits=12) field3 = models.CharField(blank=True, max_length=100)
class FreeCurrencyDefaultAmountModel(models.Model): name = models.CharField(blank=True, max_length=100) price = MoneyField(decimal_places=2, max_digits=12, amount_default=Decimal('1234.00'))
def test_missing_max_digits(self): with self.assertRaises(FieldError) as cm: testfield = MoneyField(name='testfield', decimal_places=2) self.assertIn('max_digits', cm.exception.args[0])