def test_login(self, item): python_dict = json.loads(item.request_data) try: # 调用url进行拼接 item_url = get_do_excel.join_url(sheet_url=item.url) res = request.Request(url=item_url, method=item.method, data=python_dict) expect = json.loads(item.expect)['code'] practical = res.get_josn()['code'] try: self.assertEqual(expect,practical) #回写测试结果成功 get_do_excel.write_practical_by_case_id(sheet_name=sheet_name,case_id=item.id,practical=res.get_text(), result='succeed') # 增加日志输出 Log().out_debug('pass', item.api_describe, res.get_josn()) except: # 回写测试结果失败 get_do_excel.write_practical_by_case_id(sheet_name=sheet_name,case_id=item.id,practical=res.get_text(), result='fail') # 增加日志输出 Log().out_debug('file', item.api_describe, res.get_josn()) except SyntaxError as e: print('{0}功能,第{1}用例执行失败,失败用例描述名称{2},参数为空'.format(item.api, item.id, item.api_describe)) raise e
class TestCollectBankInfo: req = request.Request(commondata.url) test = assertion.Assertion() @pytest.mark.parametrize('payment_method', testdata.pay_method) def test_payment_method(self, payment_method): data = testdata.sample.copy() data['payment_method'] = payment_method response = self.req.post_request(data) assert self.test.assert_code(response.status_code, commondata.suc_code) assert self.test.assert_msg(response.text, 'success', commondata.success) @pytest.mark.parametrize('payment_method', testdata.invalid_pay_method) def test_invalid_payment_method(self, payment_method): data = testdata.sample.copy() data['payment_method'] = payment_method response = self.req.post_request(data) assert self.test.assert_code(response.status_code, commondata.fail_code) assert self.test.assert_msg(response.text, 'error', commondata.pay_method_error) @pytest.mark.parametrize('bank_country_code', testdata.valid_code_list) def test_bank_country_code(self, bank_country_code): response = self.req.post_request(bank_country_code) print(response.text) assert self.test.assert_code(response.status_code, commondata.suc_code) assert self.test.assert_msg(response.text, 'success', commondata.success) @pytest.mark.parametrize('bank_country_code', testdata.invalid_bank_country_code) def test_invalid_bank_country_code(self, bank_country_code): data = testdata.sample.copy() data['bank_country_code'] = bank_country_code response = self.req.post_request(data) assert self.test.assert_code(response.status_code, commondata.fail_code) assert self.test.assert_msg(response.text, 'error', commondata.bank_country_code_error) @pytest.mark.parametrize('account_name', testdata.account_name) def test_account_name(self, account_name): data = testdata.sample.copy() data['account_name'] = account_name response = self.req.post_request(data) assert self.test.assert_code(response.status_code, commondata.suc_code) assert self.test.assert_msg(response.text, 'success', commondata.success) @pytest.mark.parametrize('account_name', testdata.account_name) def test_account_name(self, account_name): data = testdata.sample.copy() data['account_name'] = account_name response = self.req.post_request(data) assert self.test.assert_code(response.status_code, commondata.suc_code) assert self.test.assert_msg(response.text, 'success', commondata.success) @pytest.mark.parametrize('account_name', testdata.invalid_account_name) def test_empty_account_name(self, account_name): data = testdata.sample.copy() data['account_name'] = account_name response = self.req.post_request(data) assert self.test.assert_code(response.status_code, commondata.fail_code) assert self.test.assert_in_msg(response.text, 'error', commondata.account_name_error) @pytest.mark.parametrize('account_number', testdata.us_account_number) def test_us_account_number(self, account_number): data = testdata.us_sample.copy() data['account_number'] = account_number response = self.req.post_request(data) assert self.test.assert_code(response.status_code, commondata.suc_code) assert self.test.assert_msg(response.text, 'success', commondata.success) @pytest.mark.parametrize('account_number', testdata.au_account_number) def test_au_account_number(self, account_number): data = testdata.au_sample.copy() data['account_number'] = account_number response = self.req.post_request(data) assert self.test.assert_code(response.status_code, commondata.suc_code) assert self.test.assert_msg(response.text, 'success', commondata.success) @pytest.mark.parametrize('account_number', testdata.cn_account_number) def test_cu_account_number(self, account_number): data = testdata.cn_sample.copy() data['account_number'] = account_number response = self.req.post_request(data) print(data) print(response.text) assert self.test.assert_code(response.status_code, commondata.suc_code) assert self.test.assert_msg(response.text, 'success', commondata.success) @pytest.mark.parametrize('account_number', testdata.invalid_us_account_number) def test_invalid_us_account_number(self, account_number): data = testdata.us_sample.copy() data['account_number'] = account_number response = self.req.post_request(data) assert self.test.assert_code(response.status_code, commondata.fail_code) assert self.test.assert_in_msg(response.text, 'error', commondata.account_us_number_error) @pytest.mark.parametrize('account_number', testdata.invalid_au_account_number) def test_invalid_au_account_number(self, account_number): data = testdata.au_sample.copy() data['account_number'] = account_number response = self.req.post_request(data) assert self.test.assert_code(response.status_code, commondata.fail_code) assert self.test.assert_in_msg(response.text, 'error', commondata.account_au_number_error) @pytest.mark.parametrize('account_number', testdata.invalid_cn_account_number) def test_invalid_cu_account_number(self, account_number): data = testdata.cn_sample.copy() data['account_number'] = account_number response = self.req.post_request(data) assert self.test.assert_code(response.status_code, commondata.fail_code) assert self.test.assert_in_msg(response.text, 'error', commondata.account_cn_number_error) @pytest.mark.parametrize('swift_code', testdata.invalid_swift_code_list1) def test_invalid_swift_code1(self, swift_code): response = self.req.post_request(swift_code) assert self.test.assert_code(response.status_code, commondata.fail_code) assert self.test.assert_in_msg(response.text, 'error', commondata.swift_code_error) @pytest.mark.parametrize('swift_code', testdata.invalid_swift_code_list2) def test_invalid_swift_code2(self, swift_code): response = self.req.post_request(swift_code) assert self.test.assert_code(response.status_code, commondata.fail_code) assert self.test.assert_in_msg(response.text, 'error', commondata.swift_code_error) @pytest.mark.parametrize('swift_code', testdata.invalid_swift_code_list3) def test_invalid_swift_code3(self, swift_code): response = self.req.post_request(swift_code) assert self.test.assert_code(response.status_code, commondata.fail_code) assert self.test.assert_in_msg(response.text, 'error', commondata.swift_code_error) @pytest.mark.parametrize('bsb', testdata.invalid_bsb) def test_invalid_bsb(self, bsb): data = testdata.au_sample.copy() data['bsb'] = bsb response = self.req.post_request(data) assert self.test.assert_code(response.status_code, commondata.fail_code) assert self.test.assert_in_msg(response.text, 'error', commondata.bsb_error) @pytest.mark.parametrize('bsb', testdata.invalid_bsb_list) def test_invalid_bsb1(self, bsb): response = self.req.post_request(bsb) assert self.test.assert_code(response.status_code, commondata.fail_code) assert self.test.assert_in_msg(response.text, 'error', commondata.bsb_error) @pytest.mark.parametrize('bsb', testdata.bsb) def test_bsb(self, bsb): data = testdata.au_sample.copy() data['bsb'] = bsb response = self.req.post_request(data) assert self.test.assert_code(response.status_code, commondata.suc_code) assert self.test.assert_in_msg(response.text, 'success', commondata.success) @pytest.mark.parametrize('aba', testdata.aba) def test_aba(self, aba): data = testdata.us_sample.copy() data['aba'] = aba response = self.req.post_request(data) assert self.test.assert_code(response.status_code, commondata.suc_code) assert self.test.assert_in_msg(response.text, 'success', commondata.success) @pytest.mark.parametrize('aba', testdata.invalid_aba) def test_invalid_aba(self, aba): data = testdata.us_sample.copy() data['aba'] = aba response = self.req.post_request(data) assert self.test.assert_code(response.status_code, commondata.fail_code) assert self.test.assert_in_msg(response.text, 'error', commondata.aba_error) @pytest.mark.parametrize('aba', testdata.invalid_aba_list) def test_invalid_aba1(self, aba): response = self.req.post_request(aba) assert self.test.assert_code(response.status_code, commondata.fail_code) assert self.test.assert_in_msg(response.text, 'error', commondata.aba_error)
#判断cese_id 若值相等,进行回写相应列 if sheet.cell(r, 1).value == case_id: sheet.cell(r, 7).value = replace_end self.workbook.save(self.file_name) break #拼接url地址 def join_url(self,sheet_url): #获取基础路径中url conf = Conf() base_url = conf.get_base_url('api','url') # print(type(base_url)) return os.path.join(base_url,sheet_url) if __name__ == '__main__': do_excel = Do_Excel('../datas./testdatas.xlsx') datas = do_excel.get_cases('login') for item in datas: item_url = do_excel.join_url(sheet_url=item.url) print(item_url) python_str= json.loads(item.request_data) try: res = request.Request(url=item_url,method=item.method,data=python_str) print(res.get_josn()) except SyntaxError as e: print('第{0}用例执行失败,失败名称{1}'.format(item.id,item.api_describe))