def test_role_err(self): """ 角色错误或者空 :return: """ case = 'test_role_err' param = get_req_params(self.sheet, case) self.req_result = RequestMethod().post(self.url, param).json() self.assertEqual(self.req_result['code'], get_resp_params(self.sheet, case, 'code')) self.assertEqual(self.req_result['msg'], get_resp_params(self.sheet, case, 'msg'))
def test_login_success(self): """ 测试正常登录 :return: """ case = 'test_login_success' param = get_req_params(self.sheet, case) self.req_result = RequestMethod().post(self.url, param).json() self.assertEqual(self.req_result['code'], get_resp_params(self.sheet, case, 'code')) self.assertEqual(self.req_result['msg'], get_resp_params(self.sheet, case, 'msg')) self.assertEqual(self.req_result['data']['user_name'], get_resp_params(self.sheet, case, 'user_name'))
class Login(unittest.TestCase): def setUp(self): self.url = 'post' self.sheet = 'login' def tearDown(self): pass def test_log_success(self): case = 'test_login_success' param = get_req_params(self.sheet, case) print(param) self.req_result = RequestMethod().post(self.url, param=param).json() #c=self.req_result.json() #print(c) print(self.req_result) self.assertEqual(self.req_result['origin'], '101.86.20.3, 101.86.20.3')
class Login(unittest.TestCase): def setUp(self): self.url = 'post' self.sheet = 'login' def tearDown(self): pass @ddt.data(*data1) def test_log_success(self, par): case = 'test_login_success' #param=get_req_params(self.sheet,case) print('prar:', par) self.req_result = RequestMethod().post(self.url, params=par).text #c=self.req_result.json() #print(c) print('req_result:', self.req_result) self.assertEqual(self.req_result['origin'], '101.86.20.3, 101.86.20.3')
excel_case_2 = '../test/data/test_case_02.xls' save_path = '../test/reports/report.xls' g = GenerateTestcases() # 生成测试用例及测试用例解释的excel文件 test_cases = g.generate_testcases(origin_excel_path, excel_case_1, excel_case_2) # 写入的excel book = xlwt.Workbook(encoding="utf-8") sheet = book.add_sheet('Sheet1', cell_overwrite_ok=True) # 报文头 headers = {'Content-Type': 'application/json'} # 将测试用例写入excel文件中 # test_cases = ExcelToDic().getExcelData(excel_case_1, 'Sheet1') print(test_cases) len = len(test_cases) for i in range(len): print(test_cases[i]) response = RequestMethod().post(interface_url=login_url, headers=headers, data=test_cases[i]) print(i, response) # 将数据写入i行j列 sheet.write(0, 0, 'email') sheet.write(0, 1, 'password') sheet.write(0, 2, 'response') sheet.write(i + 1, 0, test_cases[i]['email']) sheet.write(i + 1, 1, test_cases[i]['password']) sheet.write(i + 1, 2, response.text) book.save(save_path)
def test_baidu(self): self.response = RequestMethod().get(interface_url=self.url) print(self.response.url) self.assertEqual(200, self.response.status_code)