test_core.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:django-hordak 作者: adamcharnock 项目源码 文件源码
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'))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号