Ejemplo n.º 1
0
 def config_req_pict(self, kw, req=None):
     app = {}
     header = {
         "Accept": "*/*",
         "Content-Type": "application/json;charset=utf-8"
     }
     for item in kw:
         url = "%s://%s" % (item["protocol"], item["url"])
         params = BaseParams().param_fi(ast.literal_eval(
             item["params"]))["params"]
         for i in params:
             _info = ""
             if i.get("info", "null") != "null":
                 _info = i.get("info", "参数正确")
                 i.pop("info")
             if item["method"] == "get":
                 res = requests.get(url, data=json.dumps(i), headers=header)
             else:
                 res = requests.post(url,
                                     data=json.dumps(i),
                                     headers=header)
             app["url"] = item["url"]
             app["method"] = item["method"]
             app["params"] = str(i)
             app["code"] = str(res.status_code)
             app["msg"] = item["mark"] + "_" + _info
             app["hope"] = item.get("hope", "")
             app["res"] = str(res.text)
             app["result"] = ""
             print("==请求url:%s==" % url)
             print("==请求参数:%s==" % app["params"])
             print("==响应码=:%s=" % app["code"])
             print("==响应结果=:%s=" % app["res"])
             writeInfo(app, Element.INFO_FILE)
Ejemplo n.º 2
0
    def config_req(self, kw):
        app = {}
        header = {"Accept": "*/*",
                  "Content-Type": "application/json;charset=utf-8"}
        for item in kw:
            url = "%s://%s" % (item["protocol"], item["url"])
            print("==请求url:%s==" % url)
            print("==请求参数:%s==" % item["params"])
            if item["method"] == "get":
                res = requests.get(url, data=json.dumps(
                    ast.literal_eval(item["params"])), headers=header,
                                   verify=False)
            elif item["method"] == "post":
                res = requests.post(url, data=json.dumps(
                    ast.literal_eval(item["params"])), headers=header,
                                    verify=False)
            else:
                print("现在只针post和ge方法进行了测试,其他方法请自行扩展")
            app["url"] = item["url"]
            app["method"] = item["method"]
            app["params"] = item["params"]
            app["code"] = str(res.status_code)
            app["msg"] = item["mark"]
            app["hope"] = item.get("hope", "")
            app["res"] = str(res.text)
            print("==响应结果=:%s=" % app["res"])

            app["result"] = self.__check(app["hope"], app["res"])
            print("==响应码=:%s=" % app["code"])

            writeInfo(app, Element.INFO_FILE)
Ejemplo n.º 3
0
 def config_req_pict(self, kw, req=None):
     app = {}
     header = {"Accept": "*/*", "Content-Type": "application/json;charset=utf-8"}
     for item in kw:
         url = "%s://%s" % (item["protocol"], item["url"])
         params = BaseParams().param_fi(ast.literal_eval(item["params"]))["params"]
         for i in params:
             _info = ""
             if i.get("info", "null") != "null":
                 _info = i.get("info", "参数正确")
                 i.pop("info")
             if item["method"] == "get":
                 res = requests.get(url, data=json.dumps(i), headers=header)
             else:
                 res = requests.post(url, data=json.dumps(i), headers=header)
             app["url"] = item["url"]
             app["method"] = item["method"]
             app["params"] = str(i)
             app["code"] = str(res.status_code)
             app["msg"] = item["mark"] + "_" + _info
             app["hope"] = item.get("hope", "")
             app["res"] = str(res.text)
             app["result"] = ""
             print("==请求url:%s==" % url)
             print("==请求参数:%s==" % app["params"])
             print("==响应码=:%s=" % app["code"])
             print("==响应结果=:%s=" % app["res"])
             writeInfo(app, Element.INFO_FILE)
Ejemplo n.º 4
0
    def config_req(self, kw):
        app = {}
        header = {"Accept": "*/*", "Content-Type": "application/json;charset=utf-8"}
        for item in kw:
            url = "%s://%s" % (item["protocol"], item["url"])
            print("==请求url:%s==" % url)
            print("==请求参数:%s==" % item["params"])
            if item["method"] == "get":
                res = requests.get(url, data=json.dumps(ast.literal_eval(item["params"])), headers=header, verify=False)
            elif item["method"] == "post":
                res = requests.post(url, data=json.dumps(ast.literal_eval(item["params"])), headers=header, verify=False)
            else:
                print("现在只针post和ge方法进行了测试,其他方法请自行扩展")
            app["url"] = item["url"]
            app["method"] = item["method"]
            app["params"] = item["params"]
            app["code"] = str(res.status_code)
            app["msg"] = item["mark"]
            app["hope"] = item.get("hope", "")
            app["res"] = str(res.text)
            print("==响应结果=:%s=" % app["res"])

            app["result"] = self.__check(app["hope"], app["res"])
            print("==响应码=:%s=" % app["code"])

            writeInfo(app, Element.INFO_FILE)
Ejemplo n.º 5
0
 def WritNewRepInfo(self):
     Config.app["接口名"] = str("$$$$$")
     Config.app["用例"] = str("$$$$$")
     Config.app["请求体"] = str("$$$$$")
     Config.app["请求地址"] = str("$$$$$")
     Config.app["断言"] = str("$$$$$")
     Config.app["响应码"] = str("$$$$$")
     Config.app["响应体"] = str("$$$$$")
     Config.app["请求方式"] = str("$$$$$")
     Config.app["结果"] = str("$$$$$")
     writeInfo(Config.app, Element.INFO_FILE)  # 先写入data.pickle文件
Ejemplo n.º 6
0
 def WritokInfo(self, item, res, todict):
     Config.app["接口名"] = item["接口名"]
     Config.app["用例"] = item["用例"]
     Config.app["请求体"] = str(todict)
     Config.app["请求地址"] = item["请求地址"]
     Config.app["断言"] = item.get("断言", "")
     Config.app["响应码"] = str(res.status_code)
     Config.app["响应体"] = str(res.text)
     Config.app["请求方式"] = item["请求方式"]
     Config.app["结果"] = self.__check(Config.app["断言"], Config.app["响应体"])
     writeInfo(Config.app, Element.INFO_FILE)  # 先写入data.pickle文件
Ejemplo n.º 7
0
 def WritexceInfo(self, item, exceInfo):
     Config.app["接口名"] = item["接口名"]
     Config.app["用例"] = item["用例"]
     Config.app["请求体"] = str(item["请求体"])
     Config.app["请求地址"] = item["请求地址"]
     Config.app["断言"] = item.get("断言", "")
     Config.app["响应码"] = str("异常跳过")
     Config.app["响应体"] = str(exceInfo)
     Config.app["请求方式"] = item["请求方式"]
     Config.app["结果"] = str("异常跳过")
     writeInfo(Config.app, Element.INFO_FILE)  # 先写入data.pickle文件
Ejemplo n.º 8
0
 def operate(self, path):
     '''
     发请求
     :param path: 统计的path
     :return: 
     '''
     threads = []
     for item in range(len(self.getParam)):
         threads.append(BThread(self.request(self.getParam[item])))
     for j in range(len(self.getParam)):
         threads[j].start()
     for k in range(len(self.getParam)):
         threads[k].join()
     writeInfo(self.data, path)
 def post_data_header_error(self, url, header, item, unique_flag):
     # 请求头
     if item["head_required"] != "":
         for z in ast.literal_eval(item["head_required"]):
             for i in ast.literal_eval(str(header)):
                 post_data = ast.literal_eval(item["params"])
                 post_data = update_json_data_unique(post_data, unique_flag)
                 header_data = dictdelhead(header, i)
                 header_data = update_json_data_unique(
                     header_data, unique_flag)
                 res = requests.post(url,
                                     json=post_data,
                                     headers=header_data,
                                     verify=False)
                 writeInfo(
                     verifyhead(item, res, self.__verify, header_data, z,
                                i), Element.INFO_FILE)
                 self.test_case_count += 1
     else:
         pass
 def post_data_normal(self, url, header, item, unique_flag,
                      ignore_key_list):
     # 正向请求
     post_data = ast.literal_eval(item["params"])
     post_data = update_json_data_unique(post_data, unique_flag)
     if item["method"] == "get":
         res = requests.get(url,
                            json=post_data,
                            headers=header,
                            verify=False)
     elif item["method"] == "post":
         res = requests.post(url,
                             json=post_data,
                             headers=header,
                             verify=False)
     else:
         print("现在只针post和get方法进行了测试,其他方法请自行扩展")
     writeInfo(
         resultdata(item, res, self.__verify, post_data, "hope",
                    ignore_key_list), Element.INFO_FILE)
     self.test_case_count += 1
    def post_data_error(self, url, header, paths, item, required_key_list,
                        unique_flag, ignore_key_list):
        global test_case_count
        for i in paths:
            if i in required_key_list:
                required_flag = True
            else:
                required_flag = False
            # 生成参数异常测试数据(1、参数缺失(不填), 2、为空, 3、类型异常)
            params = get_test_data(ast.literal_eval(item["params"]), i,
                                   required_flag, unique_flag)
            for i in params:
                _info = ""
                if i.get("info", "null") != "null":
                    _info = i.get("info", "参数正确")
                    info = i.pop("info")
                if item["method"] == "get":
                    res = requests.get(url, data=json.dumps(i), headers=header)
                else:
                    res = requests.post(url,
                                        data=json.dumps(i),
                                        headers=header)

                if "非必填项 参数值为空" in info or "非必填项 参数缺失" in info:
                    writeInfo(
                        resultdata(item, res, self.__verify, i, "hope",
                                   ignore_key_list, info), Element.INFO_FILE)
                elif "必填项 参数缺失" in info:
                    writeInfo(
                        resultdata(item, res, self.__verify, i, "contrast",
                                   ignore_key_list, "head_verify", info),
                        Element.INFO_FILE)
                elif "必填项 参数值为空" in info:
                    writeInfo(
                        resultdata(item, res, self.__verify, i, "valuenull",
                                   ignore_key_list, "head-null", info),
                        Element.INFO_FILE)
                elif "参数类型异常" in info:
                    writeInfo(
                        resultdata(item, res, self.__verify, i, "typeerr",
                                   ignore_key_list, "head_typeerr", info),
                        Element.INFO_FILE)
                self.test_case_count += 1