class PosCashierSpBill(unittest.TestCase): """对账""" host = Get.host('pos_cashier_spbill') def setUp(self): self.header = {'Content-Type': 'application/x-www-form-urlencoded'} self.db = DB() def test_runspbill(self): """/allinpay/runspbill""" self.analysis(57) def test_allinpay_spbillresult(self): """/allinpay/spbillresult""" self.analysis(59) def test_allinpay_spbilldetail(self): """/allinpay/spbilldetail""" self.analysis(60) # def test_allinpay_updateSpbillStatus(self): # """/allinpay/updateSpbillStatus""" # self.analysis(61) def test_allinpay_sysRefundTotal(self): """/allinpay/sysRefundTotal""" self.analysis(62) def test_allinpay_addRefundFile(self): """/allinpay/addRefundFile""" self.analysis(63) def test_allinpay_sysRefundTotalDetail(self): """/allinpay/sysRefundTotalDetail""" self.analysis(64) def analysis(self, case_id): item = self.db.query_one("select * from api where id=" + str(case_id)) post_data = eval(item['params']) result = Get.result(PosCashierSpBill.host, self.header, item, post_data) r_value = 'Pass' if item['expect'] == 'code:' + str( result['code']) else 'Fail' self.db.insert( { 'project': item['project'], 'api_path': item['api_path'], 'api_type': item['api_type'], 'result': r_value }, 'result') self.assertEqual(item['expect'], 'code:' + str(result['code']), item['api_path'])
class PosCashierWeb(unittest.TestCase): """POS收银台""" partner_flow = '' host = Get.host('pos_cashier_web') def setUp(self): self.header = {'Content-Type': 'application/x-www-form-urlencoded'} self.db = DB() def test_payByOrderPos_1prePay(self): """/payByOrderPos/prePay""" res_data = self.analysis(53, random_key='partnerFlow') PosCashierWeb.partner_flow = res_data['partnerFlow'] def test_payByOrderPos_cancelPay(self): """/payByOrderPos/cancelPay""" self.analysis(54, ref_data={'partnerFlow': PosCashierWeb.partner_flow}) def test_payByOrderPos_queryPay(self): """/payByOrderPos/queryPay""" self.analysis(55, encrypt_sign=False) def test_payByOrderPos_queryBatch(self): """/payByOrderPos/queryBatch""" self.analysis(56, encrypt_sign=False) def test_allinpay_orderQueryInfo(self): """/allinpay/orderQueryInfo""" item = self.db.query_one("select * from api where id=58") post_url = '%s/%s%s' % (PosCashierWeb.host, item['project'], item['api_path']) post_data = item['params'] res = requests.post(post_url, data=post_data, headers=self.header).content.decode() r1 = item['expect'].split(';')[0] r2 = item['expect'].split(';')[1] r_value = 'Pass' if r1 in res or r2 in res else 'Fail' self.db.insert( { 'project': item['project'], 'api_path': item['api_path'], 'api_type': item['api_type'], 'result': r_value }, 'result') expect = '!!!@@@' if r1 in res: expect = r1 if r2 in res: expect = r2 self.assertIn(expect, res, item['api_path']) def analysis(self, case_id, random_key='', ref_data={}, encrypt_sign=True): item = self.db.query_one("select * from api where id=" + str(case_id)) if item['api_type'] != 'web4': post_data = eval(item['params']) else: post_data = item['params'] if random_key == '': pass else: post_data[random_key] = Get.random_value(20) if ref_data == {}: pass else: for k, v in ref_data.items(): post_data[k] = v if encrypt_sign is True: post_data['sign'] = Get.sign(post_data, 'seNJ00') result = Get.result(PosCashierWeb.host, self.header, item, post_data) r_value = 'Pass' if item['expect'] == 'returnCode:' + str( result['returnCode']) else 'Fail' self.db.insert( { 'project': item['project'], 'api_path': item['api_path'], 'api_type': item['api_type'], 'result': r_value }, 'result') self.assertEqual(item['expect'], 'returnCode:' + str(result['returnCode']), item['api_path']) return result