def test_generate_normal(self): coupon = Coupon(name='test', cost=10, limit=1, key='test') coupon.save() user = User.objects.create_user('jeff', '*****@*****.**', '123') exc = coupon.generate(user) self.assertIsNotNone(exc)
def test_generate_limit(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() e = coupon.generate(user) self.assertIsNone(e)
def test_generate_duplidate(self): coupon = Coupon(name='test', cost=10, limit=1, key='test') coupon.save() user = User.objects.create_user('jeff', '*****@*****.**', '123') vera = User.objects.create_user('vera', '*****@*****.**', '123') exc = Exchange(coupon=coupon, user=user, cost=10, status='WAITING', exchange_code='1233') exc.save() e = coupon.generate(vera, default=1233) self.assertNotEquals(e.exchange_code, '1233')