Skip to content

Commit

Permalink
接口管理字段调整
Browse files Browse the repository at this point in the history
  • Loading branch information
“null.lu” committed Nov 24, 2023
1 parent 7212548 commit a193570
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
14 changes: 1 addition & 13 deletions backend/api/dao/https.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,9 @@ def create_api(cls, api: dict, request: Any):
def run_api_doc(cls, api: dict):

try:
# 默认空配置
config = {
'ENV': {},
'db': [],
'global_func': "",
'rerun': 1
}

api = Format(api)
case_data = api.create_step_template()
result = run_test(
case_data=case_data,
env_config=config,
debug=False
)
result = run_test(case_data=case_data, debug=False)
return result
except (Exception, ):
raise Exception("调试测试接口失败")
16 changes: 11 additions & 5 deletions backend/core/request/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,12 @@ def __handler_request_data(self, data) -> dict[str | Any, Any]:
if k in params_fields:
request_params[k] = v
# 请求地址
request_params['url'] = ENV.get('host') + data.get('interface').get('url')
# request_params['url'] = data.get('host') or ENV.get('host') + data.get('interface').get('url')
if ENV.get('host'):
request_params['url'] = ENV.get('host') + data.get('interface').get('url')
else:
request_params['url'] = data.get('interface').get('url')

# 请求方法
request_params['method'] = data.get('interface').get('method')
# 请求头
Expand Down Expand Up @@ -480,7 +485,7 @@ def __run_setup_script(self, data):
next(self.hook_gen) # noqa


def run_test(case_data, env_config, tester='测试员', thread_count=1, debug=True) -> tuple[Any, dict[Any, Any]] | Any:
def run_test(case_data, env_config={}, tester='测试员', thread_count=1, debug=True) -> tuple[Any, dict[Any, Any]] | Any:
"""
:param case_data: 测试套件数据
:param env_config: 用例执行的环境配置
Expand All @@ -497,9 +502,10 @@ def run_test(case_data, env_config, tester='测试员', thread_count=1, debug=Tr
"""
global global_func, db, DEBUG, ENV, result # noqa
global_func_file = env_config.get('global_func', b'')
if global_func:
if global_func_file:
with open('global_func.py', 'w', encoding='utf-8') as f:
f.write(global_func_file)
f.write(global_func_file) # noqa

# 更新运行环境
global_func = importlib.reload(global_func)
DEBUG = debug
Expand All @@ -512,7 +518,7 @@ def run_test(case_data, env_config, tester='测试员', thread_count=1, debug=Tr
# 运行测试用例
runner = TestRunner(suite=suite, tester=tester)
result = runner.run(thread_count=thread_count, rerun=rerun)
if global_func:
if global_func and global_func_file:
os.remove('global_func.py')
# 断开数据库连接
db.close_connect()
Expand Down
10 changes: 3 additions & 7 deletions backend/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
# },
{
"title": "测试用例44442",
"host": "http://httpbin.org/post",
# "host": "http://httpbin.org/post",
"interface": {
"url": "/post",
"url": "http://httpbin.org/post",
"name": "登录",
"method": "post",
},
Expand All @@ -71,11 +71,7 @@
'global_func': "print('前置脚本123')",
'rerun': 1
}
result = run_test(
case_data=case_data,
env_config=config,
debug=False
)
result = run_test(case_data=case_data, debug=False)
import json

r = json.dumps(ResponseStandard.encode_json(result), ensure_ascii=False)
Expand Down

0 comments on commit a193570

Please sign in to comment.