def test_postgres_trigger_sum_zero(self):
""""
Check the database enforces leg amounts summing to zero
This is enforced by a postgres trigger applied in migration 0005.
Note that this requires the test case extend TransactionTestCase,
as the trigger is only run when changes are committed to the DB
(which the normal TestCase will not do)
"""
account = self.account()
transaction = Transaction.objects.create()
with self.assertRaises(DatabaseError):
Leg.objects.create(transaction=transaction, account=account, amount=100)
with self.assertRaises(DatabaseError), db_transaction.atomic():
# Also ensure we distinguish between currencies
Leg.objects.create(transaction=transaction, account=account, amount=Money(100, 'EUR'))
Leg.objects.create(transaction=transaction, account=account, amount=Money(-100, 'GBP'))
评论列表
文章目录