Esempio n. 1
0
 def test_conditional_update(self):
     ModelWithVanillaMoneyField.objects.bulk_create((
         ModelWithVanillaMoneyField(money=Money(1, 'USD'), integer=0),
         ModelWithVanillaMoneyField(money=Money(2, 'USD'), integer=1),
     ))
     ModelWithVanillaMoneyField.objects.update(
         money=Case(When(integer=0, then=Value(10)), default=Value(0)))
     assert ModelWithVanillaMoneyField.objects.get(
         integer=0).money == Money(10, 'USD')
     assert ModelWithVanillaMoneyField.objects.get(
         integer=1).money == Money(0, 'USD')
Esempio n. 2
0
 def test_value_create_invalid(self):
     with pytest.raises(ValidationError):
         ModelWithVanillaMoneyField.objects.create(money=Value('string'))
Esempio n. 3
0
 def test_value_create(self, value, expected):
     instance = NullMoneyFieldModel.objects.create(field=Value(value))
     instance.refresh_from_db()
     assert instance.field == expected
Esempio n. 4
0
 def test_create_func(self):
     instance = ModelWithVanillaMoneyField.objects.create(
         money=Func(Value(-10), function='ABS'))
     instance.refresh_from_db()
     assert instance.money.amount == 10