Exemple #1
0
 def test_close_syssn(self):
     '''
     订单关闭: 测试使用钱台订单关闭(/trade/v1/close)
     条件: 
     操作: 
     预期: 
     '''
     url = '%s/trade/v1/close' % QT_API
     param = {
         'txamt': self.txamt,
         'syssn': self._create_order().get('syssn'),
         'txdtm': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
     }
     sign = create_sign(param, TEST_APP['key'])
     req = urllib.urlencode(param)
     data = post(url, req, sign)
     #self.data = pre_create(**param)
     #print 'result',data
     struct = {
         u'resperr': u'(1146)',
         u'respcd': u'1146',
         u'respmsg': u'',
         u'syssn': u'20160218355381',
         u'orig_syssn': u'20160216355248'
     }
     nose.tools.ok_(data.get('respcd') == '0000', msg='返回码错误')
     nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
         struct, data),
                            msg='返回结构不一致')
Exemple #2
0
 def ttest_close_out_trade(self):
     '''
     订单关闭: 测试关闭订单(/trade/v1/close)
     条件: 
     操作: 
     预期: 
     '''
     url = '%s/trade/v1/close' % QT_API
     out_trade_no = '14555915664200'
     order_status = {
         'out_trade_no': out_trade_no,
     }
     self._update_order(**order_status)
     param = {
         'txamt': self.txamt,
         'out_trade_no': out_trade_sn,
         'txdtm': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
     }
     sign = create_sign(param, TEST_APP['key'])
     req = urllib.urlencode(param)
     data = post(url, req, sign)
     #self.data = pre_create(**param)
     struct = {
         u'resperr': u'(1146)',
         u'respcd': u'1146',
         u'respmsg': u'',
         u'syssn': u'20160218355381',
         u'orig_syssn': u'20160216355248'
     }
     nose.tools.ok_(data.get('respcd') == '1146', msg='返回码错误')
     nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
         struct, data),
                            msg='返回结构不一致')
Exemple #3
0
 def test_close_fail(self):
     '''
     订单关闭: 测试关闭订单失败(/trade/v1/close)
     条件:此接口不检查txamt和txdtm 
     操作: 
     预期: 
     '''
     url = '%s/trade/v1/close' % QT_API
     param = {
         'txamt': 11,
         'syssn': '2323432',  #self._create_order().get('syssn'),
         'txdtm': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
     }
     sign = create_sign(param, TEST_APP['key'])
     req = urllib.urlencode(param)
     data = post(url, req, sign)
     struct = {
         u'resperr': u'',
         u'respcd': u'1136',
         u'respmsg': u'',
         u'out_trade_no': u''
     }
     nose.tools.ok_(data.get('respcd') != '0000', msg='返回码错误')
     nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
         struct, data),
                            msg='返回结构不一致')
Exemple #4
0
    def test_get_tradelist(self):
        '''
        获取user的tradelist
        '''
        #预处理
        code = self._user_auth()
        access_token = self._access_token(code)

        url = '%s/user/v1/tradelist?' % QT_API
        param = {
            'access_token': access_token,
            'start_time':
            datetime.datetime.now().strftime("%Y-%m-01 %H:%M:%S"),
            'end_time': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            'page': 1,
            'page_size': 10,
        }
        re = get(url + urllib.urlencode(param))

        nose.tools.ok_(re.get('respcd') == '0000', '获取trade_list失败')
        nose.tools.ok_(isinstance(re['data'].get('tradelist'), list),
                       '非list类型')
        struct = {
            u'pay_type': u'800207',
            u'sysdtm': u'2016-08-08 18:05:46',
            u'txcurrcd': u'CNY',
            u'txdtm': u'2016-08-08 18:05:46',
            u'txamt': u'1',
            u'syssn': u'20160808124500020000000357',
            u'customer_id': u''
        }
        if re['data'].get('tradelist'):
            nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
                struct, re['data'].get('tradelist')[0]),
                                   msg='返回结构不一致')
Exemple #5
0
 def test_add_goods_img(self):
     '''
     验证增加商品名称, 添加商品主图片 (/goods/v1/add_goods)
     '''
     url = '%s/goods/v1/add_goods' %QT_API
     cate_id,unionid,goods_id = self._add_goods()
     goodsname =  '商品名称' + str(int(time.time()))
     txamt = random.randint(1,100)
     param = {
             'cate_id' : cate_id,
             'name'   : '商品描述' + str(int(time.time())),
             'info'    : '商品描述' + str(int(time.time())),
             'spec'    : 'big',  
             'txamt'   : txamt,
             'origamt' : txamt,
             'weight'  : random.randint(1,100),
             'img'     : "http://qmm.la/nzpDHn",
             }
     sign = create_sign(param,TEST_APP['key'])
     req = urllib.urlencode(param)
     data = post(url,req,sign,mchnt=self.mchnt)
     #print data
     nose.tools.ok_('0000' == data.get('respcd'), msg = '添加商品失败')
     nose.tools.ok_(data['data'].get('goods_id'), msg = 'goods_id没有返回')
     nose.tools.ok_(data['data'].get('unionid'), msg = 'unionid没有返回')
     nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(GOODS_INFO,data),msg='返回结构不一致')
Exemple #6
0
    def test_query_goods(self):
        '''
        验证查询商品, 分别使用cate_id,goods_id, offset, limit, unionid  查询成功(/goods/v1/query_cate)
        '''
        url = '%s/goods/v1/query_goods' %QT_API
        cate_id,unionid,goods_id = self._add_goods()
        descr =  '商品分类' + str(int(time.time()))
        for x in range(4):
            param = {}
            if x == 0:
                param['cate_id'] = cate_id
            if x == 1:
                #limit 和offset 必须同时存在
                param['limit'] = 1
                param['offset'] = 2
            if x == 2:
                param['goods_id'] = goods_id
            if x == 3:
                param['unionid'] = unionid

            sign = create_sign(param,TEST_APP['key'])
            req = urllib.urlencode(param)
            data = post(url,req,sign,mchnt=self.mchnt)
            #print data
            nose.tools.ok_('0000' == data.get('respcd'), msg = '查询商品失败')
            nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(GOODS_QUERY_INFO,data),msg='返回结构不一致')
Exemple #7
0
    def test_query(self):
        '''
        订单查询: 订单查询失败(/trade/v1/query)
        条件: 
        操作: 
        预期:
        '''
        out_trade_sn = self._order().get('out_trade_no')
        param = {
            'out_trade_no': out_trade_sn,
        }

        sign = create_sign(param, TEST_APP['key'])
        req = urllib.urlencode(param)
        data = post(self.url, req, sign)
        #self.data = pre_create(**param)
        #print 'result',data
        struct = {
            u'resperr':
            u'\u8bf7\u6c42\u6210\u529f',
            u'page_size':
            10,
            u'respmsg':
            u'',
            u'respcd':
            u'0000',
            u'data': [{
                u'pay_type':
                u'800201',
                u'sysdtm':
                u'2016-02-18 12:50:24',
                u'order_type':
                u'payment',
                u'txcurrcd':
                u'CNY',
                u'txdtm':
                u'2016-02-18 12:50:24',
                u'txamt':
                u'1',
                u'out_trade_no':
                u'14557710248461',
                u'syssn':
                u'20160218355384',
                u'cancel':
                u'0',
                u'respcd':
                u'1143',
                u'errmsg':
                u'\u4ea4\u6613\u9519\u8bef\uff0c\u8bf7\u8054\u7cfb\u94b1\u65b9\u5ba2\u670d'
            }],
            u'page':
            1
        }
        nose.tools.ok_(data.get('respcd') == '0000', msg='返回respcd码错误')
        nose.tools.ok_(data['data'][0].get('respcd') == '1143', msg='返回码错误')
        nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
            struct, data),
                               msg='返回结构不一致')
Exemple #8
0
    def test_order_other_param(self):
        '''
        钱台订单: 测试增加其他参数预下单(/trade/v1/payment)
        条件: 
        操作: 
        预期: 
        '''
        url = '%s/trade/v1/payment' % QT_API
        param_list = [
            'goods_name', 'goods_info', 'pay_limit', 'udid', 'mchntid'
        ]
        for p in param_list:
            out_trade_sn = int(time.time() * 10000)
            param = {
                'txamt': self.txamt,
                'txcurrcd': 'CNY',
                'pay_type': 800201,
                'out_trade_no': out_trade_sn,
                'txdtm': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            }
            if p == "goods_name":
                param['goods_name'] = 'goods'

            if p == "goods_info":
                param['goods_info'] = 'goods_info'

            if p == "pay_limit":
                param['pay_limit'] = "no_credit"

            if p == "udid":
                param['udid'] = "abcdef"

            if p == "mchntid":
                param['mchntid'] = "abc123"

            sign = create_sign(param, TEST_APP['key'])
            req = urllib.urlencode(param)
            data = post(url, req, sign)
            #print 'result: %s'%p,"===",param
            #print 'result: %s'%p,"===",data
            struct = {
                u'pay_type': u'800201',
                u'sysdtm': u'2016-02-16 16:03:20',
                u'resperr': u'\u4ea4\u6613\u6210\u529f',
                u'txcurrcd': u'CNY',
                u'txdtm': u'2016-02-16 16:03:20',
                u'txamt': u'1',
                u'respmsg': u'',
                u'out_trade_no': u'14556098000975',
                u'syssn': u'20160216355258',
                u'qrcode': u'weixin://wxpay/bizpayurl?pr=wd71tMi',
                u'respcd': u'0000'
            }
            nose.tools.ok_(data.get('respcd') == '0000', msg='返回码错误')
            nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
                struct, data),
                                   msg='返回结构不一致')
Exemple #9
0
 def test_area_info(self):
     '''
     测试区域信息查询(/tool/v1/area)
     返回预期:查询成功 
     请求类型:GET
     '''
     url = '%s/tool/v1/area' % QT_API
     res = get(url)
     nose.tools.ok_('0000' == res.get('respcd'), msg='区域信息查询失败')
     nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
         AREA_INFO, res),
                            msg='返回结构不一致')
Exemple #10
0
 def test_headbank_info(self):
     '''
     测试总行信息查询(/tool/v1/headbank)
     返回预期:查询成功
     请求类型:GET
     '''
     url = '%s/tool/v1/headbank' % QT_API
     res = get(url)
     #print res
     nose.tools.ok_('0000' == res.get('respcd'), msg='总行信息查询失败')
     nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
         HEADBANK_INFO, res),
                            msg='返回结构不一致')
Exemple #11
0
 def test_mcc_info(self):
     '''
     测试mcc 信息查询 (/tool/v1/mcc)
     返回预期:查询成功
     请求类型:get
     '''
     url = '%s/tool/v1/mcc' % QT_API
     res = get(url)
     #print res
     nose.tools.ok_('0000' == res.get('respcd'), msg='MCC信息查询失败')
     nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
         MCC_INFO, res),
                            msg='返回结构不一致')
Exemple #12
0
 def test_order_h5(self):
     '''
     钱台订单: 测试微信公众账号预下单(/trade/v1/payment)
     条件: 
     操作: 
     预期: 
     '''
     url = '%s/trade/v1/payment' % QT_API
     out_trade_sn = int(time.time() * 10000)
     param = {
         'txamt': self.txamt,
         'txcurrcd': 'CNY',
         'pay_type': 800207,
         'out_trade_no': out_trade_sn,
         'txdtm': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
         #'sub_openid':'oo3Lss4RHF6LNDv2iYt3YUn50Zsg',
     }
     if DEBUG_MODE != 'offline':
         param['sub_openid'] = 'oo3Lss4RHF6LNDv2iYt3YUn50Zsg'
     else:
         param['sub_openid'] = 'oYkCztyemzMxwKHFYXlKrH1M4m3c'
     sign = create_sign(param, TEST_APP['key'])
     req = urllib.urlencode(param)
     data = post(url, req, sign)
     #print 'result\n',data
     struct = {
         u'pay_type': u'800207',
         u'sysdtm': u'2016-02-17 14:13:51',
         u'resperr': u'\u4ea4\u6613\u6210\u529f',
         u'txcurrcd': u'CNY',
         u'txdtm': u'2016-02-17 14:13:50',
         u'txamt': u'1',
         u'respmsg': u'',
         u'out_trade_no': u'14556896309805',
         u'syssn': u'20160217355282',
         u'pay_params': {
             u'package': u'prepay_id=wx20160217141351f9afbe18f90426146429',
             u'timeStamp': u'1455689631',
             u'signType': u'MD5',
             u'paySign': u'F36C1706B2C92F496E4977093E02363E',
             u'appId': u'wx370e5f2f9001f90b',
             u'nonceStr': u'523ca46a375e4b5f8bf7bd231c6045dd'
         },
         u'respcd': u'0000'
     }
     nose.tools.ok_(data.get('respcd') == '0000', msg='返回码错误')
     #print 'struct\n',struct
     nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
         struct, data),
                            msg='返回结构不一致')
Exemple #13
0
 def test_order_app(self):
     '''
     钱台订单: 测试微信扫码预下单(/trade/v1/payment)
     条件: 
     操作: 
     预期: 
     '''
     url = '%s/trade/v1/payment' % QT_API
     out_trade_sn = int(time.time() * 10000)
     param = {
         'txamt': self.txamt,
         'txcurrcd': 'CNY',
         'pay_type': 800210,
         'out_trade_no': out_trade_sn,
         'txdtm': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
     }
     submchnt = ''
     sign = create_sign(param, TEST_APP['key'])
     req = urllib.urlencode(param)
     data = post(url, req, sign, mchnt=submchnt)
     #print data
     struct = {
         u'cardcd': u'',
         u'pay_type': u'',
         u'sysdtm': u'',
         u'cardcd': u'',
         u'resperr': u'',
         u'txcurrcd': u'',
         u'txdtm': u'',
         u'txamt': u'1',
         u'respmsg': u'',
         u'out_trade_no': u'14633944799951',
         u'syssn': u'20160516124500020005341807',
         u'pay_params': {
             u'package': u'Sign=WXPay',
             u'timestamp': u'1463394480',
             u'sign': u'49357F2C967ED1DB05718D486B199882',
             u'partnerid': u'1298257101',
             u'appid': u'wx087a3fc3f3757766',
             u'prepayid': u'wx20160516182800851177b3350003221281',
             u'noncestr': u'71662d73503b4cd297eddebb685bfaa4'
         },
         u'respcd': u'0000'
     }
     nose.tools.ok_(data.get('respcd') == '0000', msg='返回码错误')
     nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
         struct, data),
                            msg='返回结构不一致')
Exemple #14
0
 def test_add_cate(self):
     '''
     验证添加商品分类,  必传参数(/goods/v1/add_cate)
     '''
     url = '%s/goods/v1/add_cate' %QT_API
     name =  '商品分类' + str(int(time.time()))
     param = {
             'name'   :  name,
             }
     sign = create_sign(param,TEST_APP['key'])
     req = urllib.urlencode(param)
     data = post(url,req,sign,mchnt=self.mchnt)
     #print data
     nose.tools.ok_('0000' == data.get('respcd'), msg = '增加菜品分类失败')
     nose.tools.ok_(19 == len(data['data'].get('cate_id')), msg = '返回的cate_id信息有误')
     nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(NEWADD_CATE,data),msg='返回结构不一致')
Exemple #15
0
 def test_submchnt_wx(self):
     '''
     钱台订单: 测试微信子商户下单(/trade/v1/payment)
     条件:子商户id 11754  // 10205 账户使用中信账号不能交易 
     操作: 
     预期: 
     '''
     url = '%s/trade/v1/payment' % QT_API
     out_trade_sn = int(time.time() * 10000)
     param = {
         'txamt': self.txamt,
         'txcurrcd': 'CNY',
         'pay_type': 800207,
         'out_trade_no': out_trade_sn,
         'txdtm': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
         #'openid':'oMGYCj7dkqBDjry172r83XgD-t3s',
         'sub_openid': 'oo3Lss4RHF6LNDv2iYt3YUn50Zsg',
     }
     sign = create_sign(param, TEST_APP['key'])
     req = urllib.urlencode(param)
     data = post(url, req, sign, mchnt='la33S8k8')
     print data
     nose.tools.ok_(data.get('respcd') == '0000', msg='返回码错误')
     struct = {
         u'cardcd': u'',
         u'pay_type': u'800207',
         u'sysdtm': u'2016-03-23 20:25:11',
         u'resperr': u'\u4ea4\u6613\u6210\u529f',
         u'txcurrcd': u'CNY',
         u'txdtm': u'2016-03-23 20:25:11',
         u'txamt': u'1',
         u'respmsg': u'',
         u'out_trade_no': u'14587359113311',
         u'syssn': u'20160323801075',
         u'pay_params': {
             u'package': u'prepay_id=wx201603232025111667d839410381315372',
             u'timeStamp': u'1458735911',
             u'signType': u'MD5',
             u'paySign': u'698378C5D0A953F0140715B991F631AF',
             u'appId': u'wx370e5f2f9001f90b',
             u'nonceStr': u'95c8a15cae02421489f23f13eee65e6c'
         },
         u'respcd': u'0000'
     }
     nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
         struct, data),
                            msg='返回结构不一致')
Exemple #16
0
    def test_query_fail(self):
        '''
        订单撤销: 测试订单查询失败(/trade/v1/refund)
        条件:不存在的订单 
        操作: 
        预期: 
        '''
        param = {
            'out_trade_no': '2015020212345678',
        }

        sign = create_sign(param, TEST_APP['key'])
        req = urllib.urlencode(param)
        data = post(self.url, req, sign)
        #print 'result',data
        struct = {
            u'resperr':
            u'',
            u'page_size':
            10,
            u'respmsg':
            u'',
            u'respcd':
            u'0000',
            u'data': [{
                u'pay_type': u'',
                u'sysdtm': u'',
                u'order_type': u'payment',
                u'txcurrcd': u'',
                u'txdtm': u'',
                u'txamt': u'',
                u'out_trade_no': u'',
                u'syssn': u'',
                u'cancel': u'0',
                u'respcd': u'',
                u'errmsg': u''
            }],
            u'page':
            1
        }
        nose.tools.ok_(data.get('respcd') == '0000', msg='返回码错误')
        nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
            struct, data),
                               msg='返回结构不一致')
        nose.tools.assert_false(data.get('data'), msg='返回结构不一致')
Exemple #17
0
 def test_branchbank_info(self):
     '''
     测试支行信息查询,使用正确的city_id,仅传必传参数(/tool/v1/branchbank)
     返回预期:查询成功
     请求类型:get
     '''
     url = '%s/tool/v1/branchbank?' % QT_API
     param = {
         'city_id': '181',
     }
     #print req
     url = url + urllib.urlencode(param)
     sign = create_sign(param, TEST_APP['key'])
     res = get(url, sign)
     #print res
     nose.tools.ok_('0000' == res.get('respcd'), msg='城市信息查询失败')
     nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
         BRANCHBANK_INFO, res),
                            msg='返回结构不一致')
Exemple #18
0
 def test_add_goods(self):
     '''
     验证增加商品名称,必传参数 (/goods/v1/add_goods)
     '''
     url = '%s/goods/v1/add_goods' %QT_API
     cate_id = self._add_cate()
     goodsname =  '商品名称' + str(int(time.time()))
     param = {
             'cate_id' : cate_id,
             'name'    : goodsname,
             }
     sign = create_sign(param,TEST_APP['key'])
     req = urllib.urlencode(param)
     data = post(url,req,sign,mchnt=self.mchnt)
     #print data
     nose.tools.ok_('0000' == data.get('respcd'), msg = '添加菜品失败')
     nose.tools.ok_(data['data'].get('goods_id'), msg = 'goods_id没有返回')
     nose.tools.ok_(data['data'].get('unionid'), msg = 'unionid没有返回')
     nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(GOODS_INFO,data),msg='返回结构不一致')
Exemple #19
0
 def test_city_info_err(self):
     '''
     测试城市信息查询,使用错误的area_id(/tool/v1/city)
     返回预期:查询为空
     请求类型:get
     '''
     url = '%s/tool/v1/city?' % QT_API
     param = {
         'area_id': '1111',
     }
     #print req
     url = url + urllib.urlencode(param)
     sign = create_sign(param, TEST_APP['key'])
     res = get(url, sign)
     #print res
     nose.tools.ok_('0000' == res.get('respcd'), msg='城市信息查询失败')
     nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
         CITY_INFO, res),
                            msg='返回结构不一致')
Exemple #20
0
    def test_order_submchnt(self):
        '''
        钱台订单: 测试下单时使用子商户且商户信息在消息体中(/trade/v1/payment)
        条件: 
        操作: 
        预期: 
        '''
        if DEBUG_MODE == 'offline':
            mchid = 'B7eeimnZ'
        else:
            mchid = 'ZOkq8uOqdP'
        url = '%s/trade/v1/payment' % QT_API
        out_trade_sn = int(time.time() * 10000)
        param = {
            'txamt': self.txamt,
            'txcurrcd': 'CNY',
            'pay_type': 800201,
            'out_trade_no': out_trade_sn,
            'mchid': mchid,
            'txdtm': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
        }

        sign = create_sign(param, TEST_APP['key'])
        req = urllib.urlencode(param)
        data = post(url, req, sign)
        #print 'result: ',data
        struct = {
            u'pay_type': u'800201',
            u'sysdtm': u'2016-02-16 16:03:20',
            u'resperr': u'\u4ea4\u6613\u6210\u529f',
            u'txcurrcd': u'CNY',
            u'txdtm': u'2016-02-16 16:03:20',
            u'txamt': u'1',
            u'respmsg': u'',
            u'out_trade_no': u'14556098000975',
            u'syssn': u'20160216355258',
            u'qrcode': u'weixin://wxpay/bizpayurl?pr=wd71tMi',
            u'respcd': u'0000'
        }
        nose.tools.ok_(data.get('respcd') == '0000', msg='返回码错误')
        nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
            struct, data),
                               msg='返回结构不一致')
Exemple #21
0
 def test_query_mch_username(self):
     '''
     测试商户信息查询,使用username(/mch/v1/query)
     返回预期:查询成功
     请求类型:GET
     '''
     url = '%s/mch/v1/query?' % QT_API
     param = {
         'username': '******',
     }
     #print req
     sign = create_sign(param, TEST_APP['key'])
     url = url + urllib.urlencode(param)
     res = get(url, sign)
     #for key,value in res['data'].items():
     #    print key, ':', value
     nose.tools.ok_('0000' == res.get('respcd'), msg='用户查询失败')
     nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
         QUERY_MCH, res),
                            msg='返回结构不一致')
Exemple #22
0
    def test_order_micropay(self):
        '''
        钱台订单: 测试微信刷卡支付(/trade/v1/payment)
        条件: 
        操作: 
        预期: 
        '''
        url = '%s/trade/v1/payment' % QT_API
        out_trade_sn = int(time.time() * 10000)
        #auth_code = str(int(time.time() *1000000)) + str(random.randrange(10,99))
        auth_code = '130132752777533864'
        param = {
            'txamt': self.txamt,
            'txcurrcd': 'CNY',
            'pay_type': 800208,
            'out_trade_no': out_trade_sn,
            'txdtm': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            'auth_code': auth_code,
        }
        sign = create_sign(param, TEST_APP['key'])
        req = urllib.urlencode(param)
        data = post(url, req, sign)
        #print 'result \n',data
        struct = {
            u'pay_type': u'800208',
            u'resperr':
            u'\u4ea4\u6613\u5931\u8d25\uff0c\u8bf7\u7a0d\u540e\u91cd\u8bd5\uff0c\u6216\u8054\u7cfb\u94b1\u65b9\u5ba2\u670d(1101)',
            u'txcurrcd': u'CNY',
            u'txdtm': u'2016-02-16 17:18:18',
            u'txamt': u'1',
            u'respmsg': u'',
            u'out_trade_no': u'14556142982734',
            u'syssn': u'20160216355271',
            u'respcd': u'1101'
        }

        nose.tools.ok_(data.get('respcd') == '1202', msg='返回码错误')
        nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
            struct, data),
                               msg='返回结构不一致')
Exemple #23
0
 def test_query_cate(self):
     '''
     验证查询商品分类, 分别使用ID, OFFSET, LIMIT,  查询成功(/goods/v1/query_cate)
     '''
     url = '%s/goods/v1/query_cate' %QT_API
     cate_id = self._add_cate()
     descr =  '商品分类' + str(int(time.time()))
     status = random.randint(0,1)
     for x in range(2):
         param = {}
         if x == 0:
             param['cate_id'] = cate_id
         if x == 1:
             #limit 和offset 必须同时存在
             param['limit'] = 1
             param['offset'] = 2
         sign = create_sign(param,TEST_APP['key'])
         req = urllib.urlencode(param)
         data = post(url,req,sign,mchnt=self.mchnt)
         #print data
         nose.tools.ok_('0000' == data.get('respcd'), msg = '查询菜品分类失败')
         nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(CATE_INFO,data),msg='返回结构不一致')
Exemple #24
0
    def ttest_order_alipay_saoma(self):
        '''
        钱台订单: 测试支付宝扫码预下单(/trade/v1/payment)
        条件: 
        操作: 
        预期: 
        '''
        url = '%s/trade/v1/payment' % QT_API
        out_trade_sn = int(time.time() * 10000)
        param = {
            'txamt': self.txamt,
            'txcurrcd': 'CNY',
            'pay_type': 800101,
            'out_trade_no': out_trade_sn,
            'txdtm': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
        }
        sign = create_sign(param, TEST_APP['key'])
        req = urllib.urlencode(param)
        data = post(url, req, sign)
        #print 'result',data
        struct = {
            u'pay_type': u'800108',
            u'resperr': u'',
            u'txcurrcd': u'CNY',
            u'txdtm': u'2016-02-16 17:18:18',
            u'txamt': u'1',
            u'respmsg': u'',
            u'out_trade_no': u'14556142982734',
            u'syssn': u'20160216355271',
            u'respcd': u'1101'
        }
        #struct = {u'pay_type': u'800108', u'resperr': u'',  u'txdtm': u'2016-02-16 17:18:18', u'txamt': u'1', u'respmsg': u'', u'out_trade_no': u'14556142982734', u'syssn': u'20160216355271', u'respcd': u'1101'}

        #print 'old: ', struct
        nose.tools.ok_(data.get('respcd') == '0000', msg='返回码错误')
        nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
            struct, data),
                               msg='返回结构不一致')
Exemple #25
0
 def test_order_paylimit(self):
     '''
     钱台订单: 测试微信下单限制信用卡(/trade/v1/payment)
     条件: 
     操作: 
     预期: 
     '''
     url = '%s/trade/v1/payment' % QT_API
     out_trade_sn = int(time.time() * 10000)
     param = {
         'txamt': self.txamt,
         'txcurrcd': 'CNY',
         'pay_type': 800201,
         'out_trade_no': out_trade_sn,
         'txdtm': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
         'limit_pay': 'no_credit',
     }
     sign = create_sign(param, TEST_APP['key'])
     req = urllib.urlencode(param)
     data = post(url, req, sign)
     #print 'result: %s'%p,"===",param
     struct = {
         u'pay_type': u'800201',
         u'sysdtm': u'2016-02-16 16:03:20',
         u'resperr': u'\u4ea4\u6613\u6210\u529f',
         u'txcurrcd': u'CNY',
         u'txdtm': u'2016-02-16 16:03:20',
         u'txamt': u'1',
         u'respmsg': u'',
         u'out_trade_no': u'14556098000975',
         u'syssn': u'20160216355258',
         u'qrcode': u'weixin://wxpay/bizpayurl?pr=wd71tMi',
         u'respcd': u'0000'
     }
     nose.tools.ok_(data.get('respcd') == '0000', msg='返回码错误')
     nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
         struct, data),
                            msg='返回结构不一致')
Exemple #26
0
    def test_refund_wx(self):
        '''
        订单撤销: 测试微信订单退款(/trade/v1/refund)
        条件: 
        操作: 
        预期: 
        '''
        url = '%s/trade/v1/refund' %QT_API
        
        out_trade_sn = int(time.time()*10000)
        param = {
                'txamt'   : self.txamt,
                #'syssn'   : '20160414124500020003833701', 
                'syssn'   : '20160825536565', 
                'out_trade_no': out_trade_sn,
                'txdtm': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
                }
        sign = create_sign(param,TEST_APP['key'])
        req = urllib.urlencode(param)
        data = post(url,req,sign)
        print 'result',data
	struct = {u'resperr': u'\u4ea4\u6613\u4e0d\u5b58\u5728\u6216\u4e0d\u5728\u53ef\u64cd\u4f5c\u65f6\u95f4\u5185', u'respcd': u'1136', u'respmsg': u'', u'out_trade_no': u'14606316974781'}
        #nose.tools.ok_(data.get('respcd')=='1143', msg='返回码错误')
        nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(struct,data),msg='返回结构不一致')
Exemple #27
0
    def test_query_OK(self):
        '''
        订单查询: 订单查询(/trade/v1/query)
        条件: 
        操作: 
        预期:
        '''
        syssn = '20160317800888'
        param = {
            #'out_trade_no': '',
            #'syssn':syssn,
            'start_time':
            datetime.datetime.now().strftime("%Y-%m-01 00:00:00"),
            'end_time': datetime.datetime.now().strftime("%Y-%m-%d %H:00:00"),
            'page': random.randint(1, 10),
            'page_size': random.randint(2, 10),
        }

        sign = create_sign(param, TEST_APP['key'])
        req = urllib.urlencode(param)
        data = post(self.url, req, sign)
        #print 'result',data
        #struct = {u'total_num': 1, u'resperr': u'', u'page_num': 1, u'page_size': 10, u'respmsg': u'', u'respcd': u'0000', u'data': [{u'pay_type': u'', u'sysdtm': u'', u'order_type': u'payment', u'txcurrcd': u'', u'txdtm': u'', u'txamt': u'', u'out_trade_no': u'', u'syssn': u'', u'cancel': u'0', u'respcd': u'', u'errmsg': u''}], u'page': 1}
        struct = {
            u'resperr':
            u'',
            u'page_size':
            10,
            u'respmsg':
            u'',
            u'respcd':
            u'0000',
            u'data': [{
                u'pay_type': u'',
                u'sysdtm': u'',
                u'order_type': u'payment',
                u'txcurrcd': u'',
                u'txdtm': u'',
                u'txamt': u'',
                u'out_trade_no': u'',
                u'syssn': u'',
                u'cancel': u'0',
                u'respcd': u'',
                u'errmsg': u''
            }],
            u'page':
            1
        }
        struct2 = {
            u'pay_type': u'',
            u'sysdtm': u'',
            u'order_type': u'payment',
            u'txcurrcd': u'',
            u'txdtm': u'',
            u'txamt': u'',
            u'out_trade_no': u'',
            u'syssn': u'',
            u'cancel': u'0',
            u'respcd': u'',
            u'errmsg': u''
        }
        nose.tools.ok_(data.get('respcd') == '0000', msg='返回码错误')
        #print 'struct: \n',struct
        #nose.tools.ok_(data['data'][0].get('pay_type')=='800108', msg='返回码错误')
        #nose.tools.ok_(data['data'][0].get('respcd')=='1143', msg='返回码错误')
        nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
            struct, data),
                               msg='返回整体结构不一致')
        if data.get('data'):
            nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
                struct2, data['data'][0]),
                                   msg='返回结构不一致')
Exemple #28
0
    def test_query_other_param(self):
        '''
        订单查询: 非必要参数订单查询(/trade/v1/query)
        条件: 
        操作: 
        预期:
        '''
        start_time = datetime.datetime.now().strftime("%Y-%m-01 00:00:00"),
        end_time = datetime.datetime.now().strftime("%Y-%m-%d 23:23:00"),
        #params = ['syssn','pay_type','start_time','page']
        params = ['pay_type']
        #params = ['start_time']#,'page']
        for p in params:
            param = {}
            if p == 'syssn':
                param['syssn'] = '20160217355317'
            if p == 'pay_type':
                param['pay_type'] = '800101'
            if p == 'start_time':
                param['start_time'] = start_time
                param['end_time'] = end_time
            if p == 'page':
                param['start_time'] = start_time
                param['end_time'] = end_time
                param['page'] = 2
                param['page_size'] = 2

            sign = create_sign(param, TEST_APP['key'])
            req = urllib.urlencode(param)
            data = post(self.url, req, sign)
            #print 'result',data
            if p == 'syssn':
                struct = {
                    u'resperr':
                    u'',
                    u'page_size':
                    10,
                    u'respmsg':
                    u'',
                    u'respcd':
                    u'0000',
                    u'data': [{
                        u'pay_type': u'',
                        u'sysdtm': u'',
                        u'order_type': u'payment',
                        u'txcurrcd': u'',
                        u'txdtm': u'',
                        u'txamt': u'',
                        u'out_trade_no': u'',
                        u'syssn': u'',
                        u'cancel': u'0',
                        u'respcd': u'',
                        u'errmsg': u''
                    }],
                    u'page':
                    1
                }
                struct2 = {
                    u'pay_type': u'',
                    u'sysdtm': u'',
                    u'order_type': u'payment',
                    u'txcurrcd': u'',
                    u'txdtm': u'',
                    u'txamt': u'',
                    u'out_trade_no': u'',
                    u'syssn': u'',
                    u'cancel': u'0',
                    u'respcd': u'',
                    u'errmsg': u''
                }
                nose.tools.ok_(data.get('respcd') == '0000', msg='返回码错误')
                #print 'source:\n',struct
                #print 'now:\n',struct
                #nose.tools.ok_(data['data'][0].get('pay_type')=='800108', msg='返回码错误')
                nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
                    struct, data),
                                       msg='返回结构不一致')
                #nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(struct2,data['data'][0]),msg='返回结构不一致')
            if p == 'pay_type':
                struct = {
                    u'resperr':
                    u'',
                    u'page_size':
                    10,
                    u'respmsg':
                    u'',
                    u'respcd':
                    u'0000',
                    u'data': [{
                        u'pay_type': u'',
                        u'sysdtm': u'',
                        u'order_type': u'payment',
                        u'txcurrcd': u'',
                        u'txdtm': u'',
                        u'txamt': u'',
                        u'out_trade_no': u'',
                        u'syssn': u'',
                        u'cancel': u'0',
                        u'respcd': u'',
                        u'errmsg': u''
                    }],
                    u'page':
                    1
                }
                struct2 = {
                    u'pay_type': u'',
                    u'sysdtm': u'',
                    u'order_type': u'payment',
                    u'txcurrcd': u'',
                    u'txdtm': u'',
                    u'txamt': u'',
                    u'out_trade_no': u'',
                    u'syssn': u'',
                    u'cancel': u'0',
                    u'respcd': u'',
                    u'errmsg': u''
                }
                nose.tools.ok_(data.get('respcd') == '0000', msg='返回码错误')
                #print 'now:\n',data
                nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
                    struct, data),
                                       msg='返回结构不一致')
            if p == 'start_time':
                struct = {
                    u'resperr':
                    u'',
                    u'page_size':
                    10,
                    u'respmsg':
                    u'',
                    u'respcd':
                    u'0000',
                    u'data': [{
                        u'pay_type': u'',
                        u'sysdtm': u'',
                        u'order_type': u'payment',
                        u'txcurrcd': u'',
                        u'txdtm': u'',
                        u'txamt': u'',
                        u'out_trade_no': u'',
                        u'syssn': u'',
                        u'cancel': u'0',
                        u'respcd': u'',
                        u'errmsg': u''
                    }],
                    u'page':
                    1
                }
                struct2 = {
                    u'pay_type': u'',
                    u'sysdtm': u'',
                    u'order_type': u'payment',
                    u'txcurrcd': u'',
                    u'txdtm': u'',
                    u'txamt': u'',
                    u'out_trade_no': u'',
                    u'syssn': u'',
                    u'cancel': u'0',
                    u'respcd': u'',
                    u'errmsg': u''
                }
                nose.tools.ok_(data.get('respcd') == '0000', msg='返回码错误')
                #nose.tools.ok_(data['data'][0].get('respcd')=='1144', msg='返回码错误')
                nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
                    struct, data),
                                       msg='返回结构不一致')
                nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
                    struct2, data['data'][0]),
                                       msg='返回结构不一致')
                q = {
                    'sysdtm': ('between', [start_time, end_time]),
                    'busicd': ('in', ('800101', '800108', '800201', '800207',
                                      '800208', '800103', '800203')),
                    'userid':
                    '11751',
                }
                num = self._query_order(**q)
                #print '==================num: ',  num
                #print '==================len: ',  len(data['data'])
                #print num,len(data['data'])
                nose.tools.ok_(len(data['data']) == num, msg='查询结果与实际不一致')
                #print 'source:\n',struct
                #print 'now:\n',struct
            if p == 'page':
                param['page'] = 1
                param['page_size'] = 2
                struct = {
                    u'resperr':
                    u'',
                    u'page_size':
                    10,
                    u'respmsg':
                    u'',
                    u'respcd':
                    u'0000',
                    u'data': [{
                        u'pay_type': u'',
                        u'sysdtm': u'',
                        u'order_type': u'payment',
                        u'txcurrcd': u'',
                        u'txdtm': u'',
                        u'txamt': u'',
                        u'out_trade_no': u'',
                        u'syssn': u'',
                        u'cancel': u'0',
                        u'respcd': u'',
                        u'errmsg': u''
                    }],
                    u'page':
                    1
                }
                struct2 = {
                    u'pay_type': u'',
                    u'sysdtm': u'',
                    u'order_type': u'payment',
                    u'txcurrcd': u'',
                    u'txdtm': u'',
                    u'txamt': u'',
                    u'out_trade_no': u'',
                    u'syssn': u'',
                    u'cancel': u'0',
                    u'respcd': u'',
                    u'errmsg': u''
                }
                nose.tools.ok_(data.get('respcd') == '0000', msg='返回码错误')
                #nose.tools.ok_(data['data'][0].get('respcd')=='1144', msg='返回码错误')
                nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
                    struct, data),
                                       msg='返回结构不一致')
                nose.tools.assert_true(cmp_struct.CmpStructure().cmp_object(
                    struct2, data['data'][0]),
                                       msg='返回结构不一致')
                nose.tools.ok_(len(data['data']) == 2, msg='返回页数不一致')
                nose.tools.ok_(data['page'] == 2, msg='返回页数不一致')