Пример #1
0
class Test_class():

    @allure.story(interfaceChName + "-主流程")
    @allure.title("{case}")
    @pytest.mark.dependency(name=interfaceEnName + "_main")
    @pytest.mark.parametrize("case,description,httpParameters", list(parameters_main))
    def test_main(self, case, description, httpParameters):
        allure.attach('{0}'.format(testerName), "测试人员")
        allure.attach(json.dumps(httpParameters["query"], ensure_ascii=False), "接口入参")  # 测试用例的入参
        if 'caseNum' in httpParameters:
            print("\n ==清理数据库 & 插入数据==")
            mongoDataOpr.oprDatasToDB(dbJsonPath, dbName, "all", httpParameters["caseNum"])
        if httpParameters["paramType"] == "string":
            stringParams = jsonAnalysis.getStringParams(httpParameters["query"])
            urlPath2 = urlPath + stringParams
            postJ = httpApi.httpRequests(urlIP, urlPath2, httpParameters["httpType"])
        elif httpParameters["paramType"] == "json":
            postJ = httpApi.httpRequests(urlIP, urlPath, httpParameters["httpType"], parame=httpParameters["query"])
        else:
            assert 0, '参数类型「' + httpParameters["paramType"] + '」无法处理!'
        allure.attach("{0}".format(postJ), "接口出参")  # 测试用例的出参
        # 获取json中的所有叶节点key的路径
        keyPaths = jsonAnalysis.getKeyPaths(httpParameters["response"])
        for path in keyPaths:
            # 通过path获取对应的value
            res1 = jsonAnalysis.getKeyValues(httpParameters["response"], path)
            res2 = jsonAnalysis.getKeyValues(postJ, path)
            assert len(res2) > 0, path + "不存在"
            assert res1 == res2, path + " 值错误!"
        if httpParameters["isCheckDB"]:
            haha = mongoDataOpr.oprDatasToDB(dbJsonPath, dbName, "find")
            if httpParameters["checkDBType"] == "exist":
                assert len(haha) == 1
            if httpParameters["checkDBType"] == "non-exist":
                assert haha == []
Пример #2
0
class Test_class():
    def setup_class(self):
        print("====(整个测试类)前置条件:插入组织数据====")
        mongoDataOpr.oprDatasToDB(dbJsonPath, dbName, "insert")

    def teardown_class(self):
        print("\n ====(整个测试类)后置条件:清理数据库====")
        mongoDataOpr.oprDatasToDB(dbJsonPath, dbName, "delete")

    @allure.story(interfaceChName + "-主流程")
    @allure.title("{case}")
    @pytest.mark.dependency(name=interfaceEnName + "_main")
    @pytest.mark.parametrize("case,description,httpParameters",
                             list(parameters_main))
    def test_main(self, case, description, httpParameters):
        allure.attach('{0}'.format(testerName), "测试人员")
        allure.attach(json.dumps(httpParameters["query"], ensure_ascii=False),
                      "接口入参", allure.attachment_type.JSON)  #测试用例的入参
        if httpParameters["paramType"] == "string":
            stringParams = jsonAnalysis.getStringParams(
                httpParameters["query"])
            urlPath2 = urlPath + stringParams
            postJ = httpApi.httpRequests(urlIP,
                                         urlPath2,
                                         httpParameters["httpType"],
                                         token=tokenJ['access_token'])
        elif httpParameters["paramType"] == "json":
            postJ = httpApi.httpRequests(urlIP,
                                         urlPath,
                                         httpParameters["httpType"],
                                         parame=httpParameters["query"],
                                         token=tokenJ['access_token'])
        else:
            assert 0, '参数类型「' + httpParameters["paramType"] + '」无法处理!'
        allure.attach(json.dumps(postJ, ensure_ascii=False), "接口出参",
                      allure.attachment_type.JSON)  #测试用例的出参
        keyPaths = jsonAnalysis.getKeyPaths(httpParameters["response"])
        for path in keyPaths:
            res1 = jsonAnalysis.getKeyValues(httpParameters["response"], path)
            res2 = jsonAnalysis.getKeyValues(postJ, path)
            assert len(res2) > 0, path + "不存在"
            assert res1 == res2, path + " 值错误!"
        if httpParameters["isCheckDB"]:
            haha = mongoDataOpr.oprDatasToDB(dbJsonPath, dbName, "find")
            if httpParameters["checkDBType"] == "exist":
                assert len(haha) == 1
            if httpParameters["checkDBType"] == "non-exist":
                assert haha == []
Пример #3
0
 if httpParameters["paramType"] == "string":
     stringParams = jsonAnalysis.getStringParams(
         httpParameters["query"])
     urlPath2 = urlPath + stringParams
     postJ = httpApi.httpRequests(urlIP, urlPath2,
                                  httpParameters["httpType"])
 elif httpParameters["paramType"] == "json":
     urlPath3 = urlPath + "?desc=%E6%B5%8B%E8%AF%95&filteringContent=123&isTerminateInferior=true&policyName=test&priority=1"
     postJ = httpApi.httpRequests(urlIP,
                                  urlPath3,
                                  httpParameters["httpType"],
                                  parame=httpParameters["query"])
 else:
     assert 0, '参数类型「' + httpParameters["paramType"] + '」无法处理!'
 allure.attach("{0}".format(postJ), "接口出参")  # 测试用例的出参
 keyPaths = jsonAnalysis.getKeyPaths(httpParameters['response'])
 for path in keyPaths:
     res1 = jsonAnalysis.getKeyValues(httpParameters["response"], path)
     res2 = jsonAnalysis.getKeyValues(postJ, path)
     assert len(res2) > 0, path + "不存在"
     assert res1 == res2, path + " 值错误!"
 if httpParameters["isCheckDB"]:
     haha = mongoDataOpr.oprDatasToDB(dbJsonPath, dbName, "find")
     if httpParameters["checkDBType"] == "exist":
         assert len(haha) == 1
     if httpParameters["checkDBType"] == "non-exist":
         assert haha == []
 if 'caseNum' in httpParameters:
     print("\n ==清理数据库 & 插入数据==")
     mongoDataOpr.oprDatasToDB(dbJsonPath, dbName, "delete",
                               httpParameters["caseNum"])