def test_default(self): EUR = MoneyMaker('EUR') f = MoneyDbField(currency='EUR', null=False) self.assertEqual(f.get_default(), EUR()) f = MoneyDbField(currency='EUR', null=True) self.assertEqual(f.get_default(), EUR()) f = MoneyDbField(currency='EUR') self.assertEqual(f.get_default(), EUR())
def test_default(): OneEuro = EUR(1) f = MoneyDbField(currency='EUR', null=True) assert f.get_default() is None f = MoneyDbField(currency='EUR', null=True, default=EUR()) assert f.get_default() == EUR() f = MoneyDbField(currency='EUR', null=False, default=OneEuro) assert f.get_default() == OneEuro
def test_default(self): EUR = MoneyMaker('EUR') OneEuro = EUR(1) f = MoneyDbField(currency='EUR', null=True) self.assertEqual(f.get_default(), None) f = MoneyDbField(currency='EUR', null=True, default=EUR()) self.assertEqual(f.get_default(), EUR()) f = MoneyDbField(currency='EUR', null=False, default=OneEuro) self.assertEqual(f.get_default(), OneEuro)
def test_to_python(): f = MoneyDbField(currency='EUR', null=True) assert f.to_python(3) == EUR('3') assert f.to_python('3.14') == EUR('3.14') assert f.to_python(None) == EUR() with pytest.raises(ValidationError): f.to_python('abc')
def test_to_python(self): EUR = MoneyMaker('EUR') f = MoneyDbField(currency='EUR', null=True) self.assertEqual(f.to_python(3), EUR('3')) self.assertEqual(f.to_python('3.14'), EUR('3.14')) self.assertEqual(f.to_python(None), EUR()) with self.assertRaises(ValidationError): f.to_python('abc')
def test_format(self): f = MoneyDbField(max_digits=5, decimal_places=3) self.assertEqual(f._format(f.to_python(2)), '2.000') self.assertEqual(f._format(f.to_python('2.34567')), '2.346') self.assertEqual(f._format(None), None)
def test_format(): f = MoneyDbField(max_digits=5, decimal_places=3) assert f._format(f.to_python(2)) == '2.000' assert f._format(f.to_python('2.34567')) == '2.346' assert f._format(None) is None