Skip to content

Commit

Permalink
更新请求数据日志记录 (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-clan authored Aug 31, 2024
1 parent cefbb3e commit 36241a9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
26 changes: 14 additions & 12 deletions httpfpt/common/send_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,6 @@ def send_request(
raise e
log.info('请求前置处理完成')

# 日志记录请求数据
if log_data:
self.log_request_up(parsed_data)
self.allure_request_up(parsed_data)

# allure 记录动态数据
self.allure_dynamic_data(parsed_data)

Expand Down Expand Up @@ -222,10 +217,20 @@ def send_request(
request_data_parsed.update({'data': request_data_parsed.pop('body')})
try:
request_data_parsed = var_extractor.vars_replace(request_data_parsed, parsed_data['env'])
parsed_data.update(
body=request_data_parsed.get('json')

Check failure on line 221 in httpfpt/common/send_request.py

View workflow job for this annotation

GitHub Actions / lint 3.8

Cannot access member "get" for type "str"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 221 in httpfpt/common/send_request.py

View workflow job for this annotation

GitHub Actions / lint 3.9

Cannot access member "get" for type "str"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 221 in httpfpt/common/send_request.py

View workflow job for this annotation

GitHub Actions / lint 3.10

Cannot access member "get" for type "str"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 221 in httpfpt/common/send_request.py

View workflow job for this annotation

GitHub Actions / lint 3.11

Cannot access member "get" for type "str"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 221 in httpfpt/common/send_request.py

View workflow job for this annotation

GitHub Actions / lint 3.12

Cannot access member "get" for type "str"   Member "get" is unknown (reportAttributeAccessIssue)
or request_data_parsed.get('data')

Check failure on line 222 in httpfpt/common/send_request.py

View workflow job for this annotation

GitHub Actions / lint 3.8

Cannot access member "get" for type "str"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 222 in httpfpt/common/send_request.py

View workflow job for this annotation

GitHub Actions / lint 3.9

Cannot access member "get" for type "str"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 222 in httpfpt/common/send_request.py

View workflow job for this annotation

GitHub Actions / lint 3.10

Cannot access member "get" for type "str"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 222 in httpfpt/common/send_request.py

View workflow job for this annotation

GitHub Actions / lint 3.11

Cannot access member "get" for type "str"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 222 in httpfpt/common/send_request.py

View workflow job for this annotation

GitHub Actions / lint 3.12

Cannot access member "get" for type "str"   Member "get" is unknown (reportAttributeAccessIssue)
or request_data_parsed.get('content')

Check failure on line 223 in httpfpt/common/send_request.py

View workflow job for this annotation

GitHub Actions / lint 3.8

Cannot access member "get" for type "str"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 223 in httpfpt/common/send_request.py

View workflow job for this annotation

GitHub Actions / lint 3.9

Cannot access member "get" for type "str"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 223 in httpfpt/common/send_request.py

View workflow job for this annotation

GitHub Actions / lint 3.10

Cannot access member "get" for type "str"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 223 in httpfpt/common/send_request.py

View workflow job for this annotation

GitHub Actions / lint 3.11

Cannot access member "get" for type "str"   Member "get" is unknown (reportAttributeAccessIssue)

Check failure on line 223 in httpfpt/common/send_request.py

View workflow job for this annotation

GitHub Actions / lint 3.12

Cannot access member "get" for type "str"   Member "get" is unknown (reportAttributeAccessIssue)
)
except Exception as e:
log.error(e)
raise e

# 日志记录请求数据
if log_data:
self.log_request_up(parsed_data)
self.allure_request_up(parsed_data)

# 发送请求
response_data = self.init_response_metadata
response_data['stat']['execute_time'] = get_current_time()
Expand Down Expand Up @@ -330,11 +335,8 @@ def log_request_up(parsed_data: dict) -> None:
log.info(f"请求 url: {parsed_data['url']}")
log.info(f"请求 params: {parsed_data['params']}")
log.info(f"请求 headers: {parsed_data['headers']}")
log.info(f"请求 data_type:{parsed_data['body_type']}")
if parsed_data['body_type'] != BodyType.JSON:
log.info(f"请求 data:{parsed_data['body']}")
else:
log.info(f"请求 json: {parsed_data['body']}")
log.info(f"请求 body_type:{parsed_data['body_type']}")
log.info(f"请求 body:{parsed_data['body']}")
log.info(f"请求 files: {parsed_data['files_no_parse']}")

def log_request_teardown(self, teardown: list) -> None:
Expand Down Expand Up @@ -384,8 +386,8 @@ def allure_request_up(parsed_data: dict) -> None:
'url': parsed_data['url'],
'params': parsed_data['params'],
'headers': parsed_data['headers'],
'data_type': parsed_data['body_type'],
'data': parsed_data['body'],
'body_type': parsed_data['body_type'],
'body': parsed_data['body'],
'files': parsed_data['files_no_parse'],
},
)
Expand Down
7 changes: 1 addition & 6 deletions httpfpt/data/global_vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ headers:
Accept-Language: zh-CN,zh;q=0.9
User-Agent: ''' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/86.0.4240.198 Safari/537.36 '''
proxies:
http: null
https: null
redirects: null
test: https://jsonplaceholder.typicode.com
test_global: '200'
timeout: null
verify: null
timeout: 5
2 changes: 1 addition & 1 deletion httpfpt/data/test_data/test_project/only_skip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test_steps:
is_run:
skip_if:
- ${random_phone()} == 2
- ${timeout} == None
- ${timeout} == 5
reason: 条件判断为真跳过
request:
method: GET
Expand Down

0 comments on commit 36241a9

Please sign in to comment.