def handle_titan_test(self, info, data_type="data"): case_name = info['case_name'] logger().debug(case_name) url = info['url'] method = info['method'] data = info['data'] logger().debug(data) expect = info['expect'] logger().debug(expect) if method == "GET": res = Request().get(url, params=data) elif method == "POST": if data_type == "data": res = Request().post(url, data=data) elif data_type == "json": headers = {"Content-Type": "application/json; charset=UTF-8"} res = Request().post(url, json=data, headers=headers) else: logger().error("data_type 输入有误") else: logger().error("method 输入有误") code = res["code"] body = res["body"] if isinstance(expect, list): for i in range(len(expect)): ex = str(expect[i]) Assertions().assert_in_text(body, ex, case_name, url, method, data) else: ex = str(expect) Assertions().assert_in_text(body, ex, case_name, url, method, data) Assertions().assert_code(200, code) Report().get_titan_report(case_name, url, method, data, expect)
def test_pass(self, params_init): """ 用例描述:登陆正向用例 """ self.request = Request() self.params = params_init.get_params_list('login') self.test_assert = Assertions() response = self.request.post_request(self.params['Login'][0]['url'],\ self.params['Login'][0]['data'], \ self.params['Login'][0]['header']) assert self.test_assert.assert_code(response['code'], 200) assert self.test_assert.assert_body(response['body'], 'msg', 'OK')
class TestLogin(): @allure.severity('登陆') @allure.story('登陆正向用例') @pytest.mark.skip('不执行登录用例') def test_pass(self, params_init): """ 用例描述:登陆正向用例 """ self.request = Request() self.params = params_init.get_params_list('login') self.test_assert = Assertions() response = self.request.post_request(self.params['Login'][0]['url'],\ self.params['Login'][0]['data'], \ self.params['Login'][0]['header']) assert self.test_assert.assert_code(response['code'], 200) assert self.test_assert.assert_body(response['body'], 'msg', 'OK')
def get_indicator_data(response_data): conf_indicator_list = ConfigYaml().get_titan_info() for indicator_name in conf_indicator_list: test_indicator_list = list() file = Conf.get_titan_indicator_path() + os.sep + indicator_name + ".txt" with open(file, "r", encoding="utf-8") as f: standard_indicator_list = eval(f.read()) for first_data in response_data: disease_title = first_data["title"] if disease_title == indicator_name: test_indicator_list = get_data(first_data) print(test_indicator_list) Assertions().assert_in_titan_data(standard_indicator_list, test_indicator_list, indicator_name)
def assert_db(db_name, result, db_verify): # sql = init_db("db_1") sql = init_db(db_name) # 2、查询sql,excel定义好的 db_res = sql.fetchone(db_verify) # log.debug("数据库查询结果:{}".format(str(db_res))) # 3、数据库的结果与接口返回的结果验证 # 获取数据库结果的key verify_list = list(dict(db_res).keys()) # 根据key获取数据库结果,接口结果 for line in verify_list: # res_line = res["body"][line] res_line = result[line] res_db_line = dict(db_res)[line] # 验证 Assertions().assert_body(res_line, res_db_line)
def assert_init(): return Assertions()
def get_indicator_data(response_data): conf_indicator_list = ConfigYaml().get_titan_info() for indicator_name in conf_indicator_list: test_indicator_list = list() file = Conf.get_titan_indicator_path( ) + os.sep + indicator_name + ".txt" with open(file, "r", encoding="utf-8") as f: standard_indicator_list = eval(f.read()) for first_data in response_data: disease_title = first_data["title"] if disease_title == indicator_name: if "children" in first_data and first_data["children"]: for second_data in first_data["children"]: if second_data["title"] is None: second_data["title"] = " " primary_classification_title = second_data["title"] if "children" in second_data and second_data[ "children"]: for third_data in second_data["children"]: if third_data[ "title"] is None or "title" not in third_data.keys( ): secondary_classification_title = " " else: secondary_classification_title = third_data[ "title"] if "children" in third_data and third_data[ "children"]: for fourth_data in third_data[ "children"]: if "title" not in fourth_data.keys( ): fourth_data["title"] = " " elif fourth_data["title"] is None: fourth_data["title"] = " " tertiary_classification_title = fourth_data[ "title"] if "children" in fourth_data and fourth_data[ "children"]: for fifth_data in fourth_data[ "children"]: if "title" not in fifth_data.keys( ): fifth_data[ "title"] = " " elif fifth_data[ "title"] is None: fifth_data[ "title"] = " " fourth_classification_title = fifth_data[ "title"] if "children" in fifth_data and fifth_data[ "children"]: for sixth_data in fifth_data[ "children"]: if "title" not in sixth_data.keys( ): sixth_data[ "title"] = " " elif sixth_data[ "title"] is None: sixth_data[ "title"] = " " fifth_classification_title = sixth_data[ "title"] if "children" in sixth_data and sixth_data[ "children"]: for seventh_data in sixth_data[ "children"]: if seventh_data[ "title"] is None: seventh_data[ "title"] = " " seventh_classification_title = seventh_data[ "title"] title = disease_title + " -- " + primary_classification_title + " -- " + secondary_classification_title + " -- " + tertiary_classification_title + " -- " + fourth_classification_title + " -- " + fifth_classification_title + " -- " + seventh_classification_title test_indicator_list.append( title) else: title = disease_title + " -- " + primary_classification_title + " -- " + secondary_classification_title + " -- " + tertiary_classification_title + " -- " + fourth_classification_title + " -- " + fifth_classification_title test_indicator_list.append( title) else: title = disease_title + " -- " + primary_classification_title + " -- " + secondary_classification_title + " -- " + tertiary_classification_title + " -- " + fourth_classification_title test_indicator_list.append( title) else: title = disease_title + " -- " + primary_classification_title + " -- " + secondary_classification_title + " -- " + tertiary_classification_title test_indicator_list.append( title) else: title = disease_title + " -- " + primary_classification_title + " -- " + secondary_classification_title test_indicator_list.append(title) Assertions().assert_in_titan_data(standard_indicator_list, test_indicator_list, indicator_name)