mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-12 03:09:43 +08:00
Merge pull request #1391 from xucong053/bugfix
fix: failed to parse variable referenced in upload
This commit is contained in:
@@ -46,7 +46,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
from typing import Text
|
from typing import Text
|
||||||
|
|
||||||
from httprunner.models import FunctionsMapping, TStep
|
from httprunner.models import VariablesMapping, FunctionsMapping, TStep
|
||||||
from httprunner.parser import parse_data, parse_variables_mapping
|
from httprunner.parser import parse_data, parse_variables_mapping
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ def ensure_upload_ready():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def prepare_upload_step(step: TStep, functions: FunctionsMapping):
|
def prepare_upload_step(step: TStep, step_variables: VariablesMapping, functions: FunctionsMapping):
|
||||||
"""preprocess for upload test
|
"""preprocess for upload test
|
||||||
replace `upload` info with MultipartEncoder
|
replace `upload` info with MultipartEncoder
|
||||||
|
|
||||||
@@ -102,19 +102,16 @@ def prepare_upload_step(step: TStep, functions: FunctionsMapping):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# parse upload info
|
# parse upload info
|
||||||
step.request.upload = parse_data(step.request.upload, step.variables, functions)
|
step.request.upload = parse_data(step.request.upload, step_variables, functions)
|
||||||
|
|
||||||
ensure_upload_ready()
|
ensure_upload_ready()
|
||||||
params_list = []
|
params_list = []
|
||||||
for key, value in step.request.upload.items():
|
for key, value in step.request.upload.items():
|
||||||
step.variables[key] = value
|
step_variables[key] = value
|
||||||
params_list.append(f"{key}=${key}")
|
params_list.append(f"{key}=${key}")
|
||||||
|
|
||||||
params_str = ", ".join(params_list)
|
params_str = ", ".join(params_list)
|
||||||
step.variables["m_encoder"] = "${multipart_encoder(" + params_str + ")}"
|
step_variables["m_encoder"] = "${multipart_encoder(" + params_str + ")}"
|
||||||
|
|
||||||
# parse variables
|
|
||||||
step.variables = parse_variables_mapping(step.variables, functions)
|
|
||||||
|
|
||||||
step.request.headers["Content-Type"] = "${multipart_content_type($m_encoder)}"
|
step.request.headers["Content-Type"] = "${multipart_content_type($m_encoder)}"
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ from httprunner.models import (
|
|||||||
TStep,
|
TStep,
|
||||||
VariablesMapping,
|
VariablesMapping,
|
||||||
)
|
)
|
||||||
from httprunner.parser import build_url
|
from httprunner.parser import build_url, parse_variables_mapping
|
||||||
from httprunner.response import ResponseObject
|
from httprunner.response import ResponseObject
|
||||||
from httprunner.runner import ALLURE, HttpRunner
|
from httprunner.runner import ALLURE, HttpRunner
|
||||||
|
|
||||||
@@ -88,9 +88,11 @@ def run_step_request(runner: HttpRunner, step: TStep) -> StepResult:
|
|||||||
|
|
||||||
# parse
|
# parse
|
||||||
functions = runner.parser.functions_mapping
|
functions = runner.parser.functions_mapping
|
||||||
prepare_upload_step(step, functions)
|
|
||||||
# step_variables should be defined after prepare_upload_step
|
|
||||||
step_variables = runner.merge_step_variables(step.variables)
|
step_variables = runner.merge_step_variables(step.variables)
|
||||||
|
prepare_upload_step(step, step_variables, functions)
|
||||||
|
# parse variables
|
||||||
|
step_variables = parse_variables_mapping(step_variables, functions)
|
||||||
|
|
||||||
request_dict = step.request.dict()
|
request_dict = step.request.dict()
|
||||||
request_dict.pop("upload", None)
|
request_dict.pop("upload", None)
|
||||||
parsed_request_dict = runner.parser.parse_data(request_dict, step_variables)
|
parsed_request_dict = runner.parser.parse_data(request_dict, step_variables)
|
||||||
|
|||||||
Reference in New Issue
Block a user