def test_positionStructQuery(self, login, getUserInfo): positionCategoryDict = Glob.get_value('positionCategoryDict') with allure.step("准备数据"): reqList = Common.cre_data('positionStructQuery.yaml', 'PositionCategory', None) Auth = login with allure.step("开始进行接口请求,并取到返回值"): for reqlist in reqList: logging.info("这里对接口返回的值进行json取值") ids = Common.getResult(Common.requestManual(reqlist, Auth)) logging.info("返回值为:%s" % ids) # 以下是取数,根据返回key取值,替换其中X resultList = ids['struct'] checkPositionList = [ checkData["positions"] for checkData in resultList if checkData["id"] == positionCategoryDict['positionCategoryId'] ][0] checkDataList = [checkid['id'] for checkid in checkPositionList] with allure.step("与数据库数据进行对比..."): # 查询sql的node,key值 querySqlResult = Common.getSqlResult('position', 'queryAllIds', "fetchall", datapositionCategoryDict = positionCategoryDict['positionCategoryId'], \ datatenant_id=getUserInfo) logging.info("数据库查询并sort排序的结果为:%s" % sorted(querySqlResult)) logging.info("接口返回并sort排序的数据为:%s" % sorted(checkDataList)) pytest.assume(sorted(querySqlResult).__eq__(sorted(checkDataList))) with allure.step("传递数据到下个接口..."): # 替换下方的x Glob.set_value('QueryResult', checkPositionList) Glob.set_value("allIds", checkDataList) logging.info(resultList) logging.info("query interface 结束测试....")
def test_createPosition(self, login, getUserInfo): logging.info("create interface 开始测试....") positionCategoryDict = Glob.get_value('positionCategoryDict') with allure.step("准备数据"): reqList = Common.cre_data('createPosition.yaml', 'Position', positionCategoryDict, mode='create') Auth = login with allure.step("开始进行接口请求,并取到返回值"): for reqlist in reqList: logging.info("这里对接口返回的值进行json取值") ids = Common.getResult(Common.requestManual(reqlist, Auth)) logging.info("返回值为:%s" % ids) # 以下填入取值x checkData = ids['createPosition'] assert checkData == "INSTANCE" with allure.step("与数据库数据进行对比..."): # 以下填入数据库的node 以及 key querySqlResult = Common.getSqlResult('position', 'queryCheckSql', "fetchall", \ datapositionCategoryDict = positionCategoryDict['positionCategoryId'], \ datatenant_id=getUserInfo) logging.info("数据库查询并sort排序的结果为:%s" % sorted(querySqlResult)) pytest.assume(sorted(querySqlResult).__ne__([])) with allure.step("传递数据到下个接口..."): # 设置需要传递下去的值 X checkDictlist = [{'id': SqlResult} for SqlResult in querySqlResult] checkDatalist = [SqlResult for SqlResult in querySqlResult] Glob.set_value("createPosition", checkDictlist) Glob.set_value("updateCheckPoint", checkDatalist) logging.info(checkDictlist) logging.info("create interface 结束测试....")
def test_createEducationTypes(self, login, getUserInfo): logging.info("create interface 开始测试....") with allure.step("准备数据"): reqList = Common.cre_data('createEducationS.yaml', 'EducationSetting') Auth = login logging.info("getuserinfo:%s" % getUserInfo) with allure.step("开始进行接口请求,并取到返回值"): for reqlist in reqList: logging.info("这里对接口返回的值进行json取值") ids = Common.getResult(Common.requestManual(reqlist, Auth)) # 以下填入取值x checkData = ids['mergeEducation'] checkDatalist.append(checkData) checkDictlist.append({'id': checkData}) with allure.step("与数据库数据进行对比..."): # 以下填入数据库的node 以及 key querySqlResult = Common.getSqlResult('educationSetting', 'queryCheckSqlS', "fetchall", tenant_id=getUserInfo) logging.info("数据库查询并sort排序的结果为:%s" % sorted(querySqlResult)) logging.info("接口返回并sort排序的数据为:%s" % sorted(checkDatalist)) pytest.assume(sorted(querySqlResult).__eq__(sorted(checkDatalist))) with allure.step("传递数据到下个接口..."): # 设置需要传递下去的值 X,Y Glob.set_value("QueryCheck", checkDatalist) Glob.set_value("createEducationTypes", checkDictlist) logging.info(checkDictlist) logging.info("create interface 结束测试....")
def test_postQuery(self, login, getUserInfo): createPositionId = Glob.get_value('createPositionId') data = {'id': createPositionId} with allure.step("准备数据"): reqList = Common.cre_data('postByPositionId.yaml', 'Post', data) Auth = login with allure.step("开始进行接口请求,并取到返回值"): for reqlist in reqList: logging.info("这里对接口返回的值进行json取值") ids = Common.getResult(Common.requestManual(reqlist, Auth)) logging.info("返回值为:%s" % ids) # 以下是取数,根据返回key取值,替换其中X resultList = ids['posts'] checkDataList = [checkid['id'] for checkid in resultList] with allure.step("与数据库数据进行对比..."): # 查询sql的node,key值 querySqlResult = Common.getSqlResult('post', 'queryAllIds', "fetchall",\ dataposition_id = createPositionId, \ datapost_level_id = 'aa3c3d8d-cdf9-42e2-8e71-233f7b87bb18', \ datatenant_id = getUserInfo, \ ) logging.info("数据库查询并sort排序的结果为:%s" % sorted(querySqlResult)) logging.info("接口返回并sort排序的数据为:%s" % sorted(checkDataList)) pytest.assume(sorted(querySqlResult).__eq__(sorted(checkDataList))) with allure.step("传递数据到下个接口..."): # 替换下方的x Glob.set_value('QueryResult', resultList) Glob.set_value("allIds", checkDataList) logging.info(resultList) logging.info("query interface 结束测试....")
def test_employmentTypeQuery(self, login, getUserInfo): with allure.step("准备数据"): reqList = Common.cre_data('EmploymentQuery.yaml', 'NatureEmployment') Auth = login with allure.step("开始进行接口请求,并取到返回值"): for reqlist in reqList: logging.info("这里对接口返回的值进行json取值") ids = Common.getResult(Common.requestManual(reqlist, Auth)) logging.info("返回值为:%s" % ids) # 以下是取数,根据返回key取值,替换其中X,Y部分为后续命名 resultList = ids['employmentTypes'] checkDataList = [checkData["id"] for checkData in resultList] with allure.step("与数据库数据进行对比..."): # 查询sql的node,key值 querySqlResult = Common.getSqlResult('employTypeSetting', 'queryAllIds', "fetchall", tenant_id=getUserInfo) logging.info("数据库查询并sort排序的结果为:%s" % sorted(querySqlResult)) logging.info("接口返回并sort排序的数据为:%s" % sorted(checkDataList)) pytest.assume(sorted(querySqlResult).__eq__(sorted(checkDataList))) with allure.step("传递数据到下个接口..."): Glob.set_value("employmentTypesData", resultList) Glob.set_value("allIds", checkDataList) logging.info(resultList) logging.info("query interface 结束测试....")
def login(): rs = doYaml.get_data(os.path.join(BASE_PATH, "login.yaml")) url = URL + rs["url"] method = rs["method"] data = rs["data"] #login登录 try: result = requests.request(method, url, json=data) if result.status_code == 200: rjson = result.json() if rjson["MessageType"] == 200: rsToken = rjson["Data"]["access_token"] else: logging.info("登录失败,请稍后再试") Glob.set_value("rsToken", rsToken) except Exception as e: logging.info("错误原因是:%s" % e) yield rsToken logging.info("开始清理临时数据...")
def test_createPost(self, login, getUserInfo): logging.info("create interface 开始测试....") createPositionList = Glob.get_value('createPosition') createPositionId = Glob.get_value('createPositionId') dataList = [{**{'postLevelId': 'aa3c3d8d-cdf9-42e2-8e71-233f7b87bb18'}, **createPosition} \ for createPosition in createPositionList] with allure.step("准备数据"): reqList = Common.cre_data('createPost.yaml', 'Post', dataList, mode='create') Auth = login with allure.step("开始进行接口请求,并取到返回值"): for reqlist in reqList: logging.info("这里对接口返回的值进行json取值") ids = Common.getResult(Common.requestManual(reqlist, Auth)) logging.info("返回值为:%s" % ids) # 以下填入取值x checkData = ids['createPost'] assert checkData == "INSTANCE" with allure.step("与数据库数据进行对比..."): # 以下填入数据库的node 以及 key querySqlResult = Common.getSqlResult('post', 'queryCheckSql', "fetchall", \ dataposition_id=createPositionId,\ datapost_level_id='aa3c3d8d-cdf9-42e2-8e71-233f7b87bb18',\ datatenant_id=getUserInfo,\ ) logging.info("数据库查询并sort排序的结果为:%s" % sorted(querySqlResult)) pytest.assume(sorted(querySqlResult).__ne__([])) with allure.step("传递数据到下个接口..."): # 设置需要传递下去的值 X checkDictlist = [{'id': SqlResult} for SqlResult in querySqlResult] checkDatalist = [SqlResult for SqlResult in querySqlResult] Glob.set_value("createPostDictlist", checkDictlist) Glob.set_value("createPostIdList", checkDatalist) logging.info(checkDictlist) logging.info("create interface 结束测试....")