示例#1
0
    def test_valid_notfound(self):
        coupon = Coupon(name='test', cost=10, limit=1,
                        key='test')
        coupon.save()

        result = coupon.validate('1233')
        self.assertFalse(result)
示例#2
0
    def test_valid_duplicate(self):
        coupon = Coupon(name='test', cost=10, limit=1,
                        key='test')
        coupon.save()
        user = User.objects.create_user('jeff', '*****@*****.**', '123')

        exc = Exchange(coupon=coupon, user=user, cost=10, status='DONE',
                       exchange_code='1233')
        exc.save()

        result = coupon.validate('1233')
        self.assertFalse(result)
示例#3
0
    def test_valid_normal(self):
        coupon = Coupon(name='test', cost=10, limit=1,
                        key='test')
        coupon.save()
        user = User.objects.create_user('jeff', '*****@*****.**', '123')

        exc = Exchange(coupon=coupon, user=user, cost=10, status='WAITING',
                       exchange_code='1233')
        exc.save()

        apply_coupon.send = Mock()

        result = coupon.validate('1233')
        self.assertEqual(result.status, 'DONE')
        apply_coupon.send.assert_called_with(sender=Coupon, instance=coupon,
                                             cost=10, user=user)