def testProxy(self): e = Entity() e.price = Money(0, "BGN") e.price.amount = 3 assert isinstance(e.price, Money) self.assertEqual(e.price, Money(3, "BGN")) e1 = Entity(price=Money(100, "USD")) e2 = Entity(price=Money(200, "USD")) self.assertEqual(e1.price, Money(100, "USD")) self.assertEqual(e2.price, Money(200, "USD")) e2.price = Money(300, "USD") self.assertEqual(e1.price, Money(100, "USD")) self.assertEqual(e2.price, Money(300, "USD")) self.assertEqual(e1.price, Money(100, "USD"))
def testAssign(self): ent = Entity(name='test', price=Money(100, "USD")) 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 = Entity.objects.get(pk=ent.id) self.assertEquals(ent_same.price, Money(10, "USD"))
def testProxy(self): e = Entity() e.price = Money(0, "BGN") e.price.amount = 3 self.assertEqual(e.price, Money(3, "BGN")) e.price.from_string("BGN 5.0") self.assertEqual(e.price, Money(5, "BGN")) e1 = Entity(price=Money(100, "USD")) e2 = Entity(price=Money(200, "USD")) self.assertEqual(e1.price, Money(100, "USD")) self.assertEqual(e2.price, Money(200, "USD")) e2.price = Money(300, "USD") self.assertEqual(e1.price, Money(100, "USD")) self.assertEqual(e2.price, Money(300, "USD")) e2.price.from_string("USD 400") self.assertEqual(e1.price, Money(100, "USD")) self.assertEqual(e2.price, Money(400, "USD"))