Beispiel #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)
Beispiel #2
0
    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)
Beispiel #3
0
    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)
Beispiel #4
0
    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')
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
0
    def test_success(self):
        """获取礼券成功
        """
        coupon = Coupon(name='test', cost=10, limit=1,
                        key='bb', exchange_style='wechat')

        coupon.save()
        user = User.objects.create_user('jeff', '*****@*****.**', '123')

        xml = """<xml>
        <ToUserName><![CDATA[techparty]]></ToUserName>
        <FromUserName><![CDATA[o_BfQjrOWghP2cM0cN7K0kkR54fA]]></FromUserName>
        <CreateTime>1400131860</CreateTime>
        <MsgType><![CDATA[text]]></MsgType>
        <Content><![CDATA[bb1233]]></Content>
        <MsgId>1234567890123456</MsgId>
        </xml>"""
        rsp = self.request_content(xml)
        self.assertIn('无效的兑换码,或已被兑换过。', rsp)

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

        xml = """<xml>
        <ToUserName><![CDATA[techparty]]></ToUserName>
        <FromUserName><![CDATA[o_BfQjrOWghP2cM0cN7K0kkR54fA]]></FromUserName>
        <CreateTime>1400131860</CreateTime>
        <MsgType><![CDATA[text]]></MsgType>
        <Content><![CDATA[bb1233]]></Content>
        <MsgId>1234567890123456</MsgId>
        </xml>"""
        rsp = self.request_content(xml)
        self.assertIn('您已获得了10金币', rsp)

        xml = """<xml>
        <ToUserName><![CDATA[techparty]]></ToUserName>
        <FromUserName><![CDATA[o_BfQjrOWghP2cM0cN7K0kkR54fA]]></FromUserName>
        <CreateTime>1400131860</CreateTime>
        <MsgType><![CDATA[text]]></MsgType>
        <Content><![CDATA[bb1233]]></Content>
        <MsgId>1234567890123456</MsgId>
        </xml>"""
        rsp = self.request_content(xml)
        self.assertIn('无效的兑换码,或已被兑换过。', rsp)