diff --git a/app/core/executor.py b/app/core/executor.py index 2b5ddda2..50d37b07 100755 --- a/app/core/executor.py +++ b/app/core/executor.py @@ -102,14 +102,14 @@ async def parse_gconfig(self, data, type_, env, *fields): for f in fields: await self.parse_field(data, f, GconfigType.text(type_), env) - async def load_testcase_variables(self, data, type_, *fields): + async def load_testcase_variables(self, data, type_, params, *fields): """load_testcase_variables, include global variables""" for f in fields: self.append("解析{}: [{}]中的变量".format(GconfigType.text(type_), data, f)) origin_field = getattr(data, f) # if not None or "" if origin_field: - rendered = Render.render(self.glb, origin_field) + rendered = Render.render(params, origin_field) if rendered != origin_field: self.append("替换变量成功, [{}]:\n\n[{}] -> [{}]\n".format(f, origin_field, rendered)) setattr(data, f, rendered) @@ -222,7 +222,7 @@ async def execute_constructors(self, env: int, path, case_info, params, req_para for i, c in enumerate(constructors): if c.suffix == suffix: await self.execute_constructor(env, current, path, params, req_params, c) - self.replace_args(params, case_info, constructors, asserts) + # self.replace_args(params, case_info, constructors, asserts) current += 1 async def execute_constructor(self, env, index, path, params, req_params, constructor: Constructor): @@ -279,7 +279,7 @@ async def run(self, env: int, case_id: int, params_pool: dict = None, request_pa # 挂载全局变量 case_params.update(self.glb) - request_param.update(self.glb) + req_params.update(self.glb) try: case_info = await TestCaseDao.async_query_test_case(case_id) @@ -298,13 +298,13 @@ async def run(self, env: int, case_id: int, params_pool: dict = None, request_pa out_parameters = await PityTestCaseOutParametersDao.select_list(case_id=case_id) # Step5: 替换参数 - self.replace_args(req_params, case_info, constructors, asserts) + # self.replace_args(req_params, case_info, constructors, asserts) # Step6: 执行前置条件 await self.execute_constructors(env, path, case_info, case_params, req_params, constructors, asserts) # 获取全局变量更新body url headers - await self.load_testcase_variables(case_info, GconfigType.case, *Executor.fields) + await self.load_testcase_variables(case_info, GconfigType.case, case_params, *Executor.fields) if case_info.request_headers and case_info.request_headers != "": headers = json.loads(case_info.request_headers) diff --git a/app/core/msg/mail.py b/app/core/msg/mail.py index 1c9dfe2f..e98a3681 100644 --- a/app/core/msg/mail.py +++ b/app/core/msg/mail.py @@ -3,7 +3,6 @@ from email.mime.text import MIMEText from email.utils import make_msgid -import aioify from awaits.awaitable import awaitable from jinja2.environment import Template diff --git a/app/core/paramters/jsonpath_parser.py b/app/core/paramters/jsonpath_parser.py index 318773d1..62bd39b0 100644 --- a/app/core/paramters/jsonpath_parser.py +++ b/app/core/paramters/jsonpath_parser.py @@ -2,7 +2,6 @@ jsonpath parser """ import json -from functools import lru_cache from typing import Any import jsonpath @@ -19,16 +18,15 @@ def get_source(cls, source): @classmethod def parse(cls, source: dict, expression: str = "", **kwargs) -> Any: - source = cls.get_source(source) + data = cls.get_source(source) if not source or not expression: raise CaseParametersError(f"parse out parameters failed, source or expression is empty") try: - data = JSONPathParser.get_object(source) results = jsonpath.jsonpath(data, expression) if results is False: if not data and expression == "$..*": # 说明想要全匹配并且没数据,直接返回data - return json.dumps(data, ensure_ascii=False) + return data raise CaseParametersError("jsonpath match failed, please check your response or jsonpath.") return Parser.parse_result(results, "0") except CaseParametersError as e: @@ -36,11 +34,6 @@ def parse(cls, source: dict, expression: str = "", **kwargs) -> Any: except Exception as err: raise CaseParametersError(f"parse json data error, please check jsonpath or json: {err}") - @staticmethod - @lru_cache() - def get_object(json_str): - return json.loads(json_str) - class BodyJSONPathParser(JSONPathParser): @classmethod diff --git a/app/middleware/AsyncHttpClient.py b/app/middleware/AsyncHttpClient.py index 5a55254a..25dc2fc7 100755 --- a/app/middleware/AsyncHttpClient.py +++ b/app/middleware/AsyncHttpClient.py @@ -35,11 +35,11 @@ async def invoke(self, method: str): # 修复bug,当http状态码不为200的时候给出提示 return await self.collect(False, self.get_data(self.kwargs), resp.status, msg="http状态码不为200") cost = "%.0fms" % ((time.time() - start) * 1000) - response, json_format = await AsyncRequest.get_resp(resp) + response = await AsyncRequest.get_resp(resp) cookie = self.get_cookie(session) return await self.collect(True, self.get_data(self.kwargs), resp.status, response, resp.headers, resp.request_info.headers, elapsed=cost, - cookies=cookie, json_format=json_format) + cookies=cookie) async def download(self): async with aiohttp.ClientSession(cookie_jar=aiohttp.CookieJar(unsafe=True)) as session: @@ -99,11 +99,11 @@ async def get_resp(resp): try: data = await resp.json(encoding='utf-8') # 说明是json格式 - return json.dumps(data, ensure_ascii=False, indent=4), True + # return json.dumps(data, ensure_ascii=False, indent=4), True except: data = await resp.text() # 说明不是json格式,我们不做loads操作了 - return data, False + return data @staticmethod def get_request_data(body): diff --git a/conf/dev.env b/conf/dev.env index 0761e9c4..9064f645 100644 --- a/conf/dev.env +++ b/conf/dev.env @@ -1,5 +1,5 @@ # MySQL config -MYSQL_HOST="localhost" +MYSQL_HOST="121.5.2.74" MYSQL_PORT=3306 MYSQL_USER="root" MYSQL_PWD="" @@ -7,7 +7,7 @@ DBNAME="pity" # Redis config REDIS_ON=True -REDIS_HOST="localhost" +REDIS_HOST="121.5.2.74" REDIS_PORT=7788 REDIS_DB=0 REDIS_PASSWORD="" @@ -20,8 +20,8 @@ SECRET_KEY="6cb53ad7d135bb91a07f2deb7203d484741f1644" SERVER_PORT=7777 # Mock server -MOCK_ON=True -PROXY_ON=True +MOCK_ON=False +PROXY_ON=False PROXY_PORT=7778 # ETCD diff --git a/requirements.txt b/requirements.txt index 919fcefb..6a9c4b45 100755 --- a/requirements.txt +++ b/requirements.txt @@ -20,7 +20,6 @@ yagmail oss2~=2.15.0 python-multipart awaits~=0.0.1 -aioify~=0.4.0 grpc-requests loguru~=0.6.0 qiniu~=7.6.0