tests.py 文件源码

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

项目:babar3 作者: Babaritech 项目源码 文件源码
def test_balance_calcul(self):
        """
        Test balance is sum of payments minus sum of purchases
        """
        setup()
        amount = Decimal(200)
        Payment.objects.create(
            customer=Customer.objects.get(nickname="jim"),
            amount=amount
        )
        for i in range(25):
            if(random.choice((True, False))):
                Purchase.objects.create(
                    customer=Customer.objects.get(nickname="jim"),
                    product=Product.objects.get(name="Umbrella")
                )
                amount -= 5
            else:
                m = random.randrange(0, 20000) / 100
                Payment.objects.create(
                    customer=Customer.objects.get(nickname="jim"),
                    amount=m
                )
                amount += Decimal(m)
        self.assertEqual(
            Customer.objects.get(nickname="jim").balance,
            amount.quantize(Decimal('.001'), rounding=ROUND_HALF_UP)
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号