def test_price_attribute(self): e = SimpleMoneyModel() e.price = Money(3, "BGN") self.assertEqual(e.price, Money(3, "BGN")) e.price = Money.from_string("BGN 5.0") self.assertEqual(e.price, Money(5, "BGN"))
def test_price_attribute(self): e = SimpleMoneyModel() e.price = Money(3, "BGN") self.assertEqual(e.price, Money(3, "BGN")) e.price = Money.from_string("BGN 5.0") self.assertEqual(e.price, Money(5, "BGN"))
def test_price_amount_to_string(self): e1 = SimpleMoneyModel(price=Money('200', 'JPY')) e2 = SimpleMoneyModel(price=Money('200.0', 'JPY')) self.assertEqual(str(e1.price), "JPY 200") self.assertEqual(str(e1.price.amount), "200") self.assertEqual(str(e2.price.amount), "200.0")
def test_assign(self): price = Money(100, "USD") ent = SimpleMoneyModel(name='test', price=price.amount, price_currency=price.currency) ent.save() self.assertEquals(ent.price, Money(100, "USD")) ent.price = Money(10, "USD") ent.save() self.assertEquals(ent.price, Money(10, "USD")) ent_same = SimpleMoneyModel.objects.get(pk=ent.id) self.assertEquals(ent_same.price, Money(10, "USD"))
def test_assign(self): price = Money(100, "USD") ent = SimpleMoneyModel(name='test', price=price.amount, price_currency=price.currency) ent.save() self.assertEqual(ent.price, Money(100, "USD")) ent.price = Money(10, "USD") ent.save() self.assertEqual(ent.price, Money(10, "USD")) ent_same = SimpleMoneyModel.objects.get(pk=ent.id) self.assertEqual(ent_same.price, Money(10, "USD"))
def test_non_null(self): instance = SimpleMoneyModel() with pytest.raises(IntegrityError): instance.save()
def test_price_attribute_update(self): e2 = SimpleMoneyModel(price=Money(200, "JPY")) e2.price = Money(300, "USD") self.assertEqual(e2.price, Money(300, "USD"))
def test_non_null(self): instance = SimpleMoneyModel() with pytest.raises(IntegrityError): instance.save()
def test_price_attribute_update(self): e2 = SimpleMoneyModel(price=Money(200, "JPY")) e2.price = Money(300, "USD") self.assertEqual(e2.price, Money(300, "USD"))
def test_price_attribute_in_constructor(self): e1 = SimpleMoneyModel(price=Money(100, "USD")) e2 = SimpleMoneyModel(price=Money(200, "JPY")) self.assertEqual(e1.price, Money(100, "USD")) self.assertEqual(e2.price, Money(200, "JPY"))
def model_view(request): instance = SimpleMoneyModel(price=Money('0.0', 'JPY')) money = instance.price return render_to_response('view.html', {'money': money})