Skip to content

Commit

Permalink
修复typing
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-clan committed Aug 31, 2024
1 parent 9c6ad30 commit 244f4a8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
31 changes: 19 additions & 12 deletions httpfpt/common/send_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from httpfpt.common.log import log
from httpfpt.core.get_conf import httpfpt_config
from httpfpt.db.mysql import mysql_client
from httpfpt.enums.query_fetch_type import QueryFetchType
from httpfpt.enums.request.body import BodyType
from httpfpt.enums.request.engin import EnginType
from httpfpt.enums.setup_type import SetupType
Expand Down Expand Up @@ -170,9 +171,13 @@ def send_request(
parsed_data = relate_parsed_data
elif key == SetupType.SQL:
setup_sql = var_extractor.vars_replace({'sql': value}, parsed_data['env'])
sql = setup_sql['sql']
sql_fetch = setup_sql.get('fetch')
mysql_client.exec_case_sql(sql, sql_fetch, parsed_data['env'])
sql_fetch = QueryFetchType.ALL
if isinstance(setup_sql, dict):
sql = setup_sql.get('sql')
sql_fetch = setup_sql.get('fetch')
else:
sql = setup_sql
mysql_client.exec_case_sql(sql, sql_fetch, parsed_data['env']) # type: ignore
elif key == SetupType.HOOK:
hook_executor.exec_hook_func(value)
elif key == SetupType.WAIT_TIME:
Expand Down Expand Up @@ -225,9 +230,9 @@ def send_request(
response_data = self.init_response_metadata
response_data['stat']['execute_time'] = get_current_time()
if request_engin == EnginType.requests:
response = self._requests_engin(**request_conf, **request_data_parsed, **kwargs)
response = self._requests_engin(**request_conf, **request_data_parsed, **kwargs) # type: ignore
elif request_engin == EnginType.httpx:
response = self._httpx_engin(**request_conf, **request_data_parsed, **kwargs)
response = self._httpx_engin(**request_conf, **request_data_parsed, **kwargs) # type: ignore
else:
raise SendRequestError('请求发起失败,请使用合法的请求引擎:requests / httpx')

Expand Down Expand Up @@ -271,18 +276,20 @@ def send_request(
for key, value in item.items():
if value is not None:
if key == TeardownType.SQL:
teardown_sql = var_extractor.vars_replace({'sql': value}, parsed_data['env'])
sql = teardown_sql['sql']
sql_fetch = teardown_sql.get('fetch')
mysql_client.exec_case_sql(sql, sql_fetch, parsed_data['env'])
teardown_sql = var_extractor.vars_replace(value, parsed_data['env'])
sql_fetch = QueryFetchType.ALL
if isinstance(teardown_sql, dict):
sql = teardown_sql.get('sql')
sql_fetch = teardown_sql.get('fetch')
else:
sql = teardown_sql
mysql_client.exec_case_sql(sql, sql_fetch, parsed_data['env']) # type: ignore
if key == TeardownType.HOOK:
hook_executor.exec_hook_func(value)
if key == TeardownType.EXTRACT:
var_extractor.teardown_var_extract(response_data, value, parsed_data['env'])
if key == TeardownType.ASSERT:
assert_text = var_extractor.vars_replace(
target={'assert_text': value}, env=parsed_data['env']
)['assert_text']
assert_text = var_extractor.vars_replace(value, env=parsed_data['env'])
asserter.exec_asserter(response_data, assert_text)
elif key == TeardownType.WAIT_TIME:
log.info(f'执行请求后等待:{value} s')
Expand Down
9 changes: 5 additions & 4 deletions httpfpt/utils/request/request_data_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,14 @@ def skip_and_log(reason: str | None = None) -> None: # noqa: ignore
elif 'skip_if' in is_run.keys():
if isinstance(is_run['skip_if'], list):
for v in is_run['skip_if']:
if not isinstance(v, str):
if isinstance(v, str):
v = var_extractor.vars_replace(v, self.env)
if hook_executor.exec_any_code(v): # type: ignore
skip_and_log(reason)
else:
raise RequestDataParseError(
_error_msg(f'参数 test_steps:is_run:skip_if:{v} 不是有效的 str 值')
)
v = var_extractor.vars_replace(v, self.env)
if hook_executor.exec_any_code(v):
skip_and_log(reason)
else:
raise RequestDataParseError(_error_msg('参数 test_steps:is_run 缺少 skip / skip_if 参数'))
else:
Expand Down

0 comments on commit 244f4a8

Please sign in to comment.