mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-18 11:17:38 +08:00
Merge pull request #1374 from xucong053/bugfix
fix: failed to load json/data content in api reference fix: ensure complete summary results
This commit is contained in:
@@ -47,7 +47,11 @@ func (path *APIPath) ToAPI() (*API, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// 1. deal with request body compatibility
|
||||||
|
convertCompatRequestBody(api.Request)
|
||||||
|
// 2. deal with validators compatibility
|
||||||
err = convertCompatValidator(api.Validators)
|
err = convertCompatValidator(api.Validators)
|
||||||
|
// 3. deal with extract expr including hyphen
|
||||||
convertExtract(api.Extract)
|
convertExtract(api.Extract)
|
||||||
return api, err
|
return api, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,16 +182,7 @@ func (tc *TCase) MakeCompat() (err error) {
|
|||||||
}()
|
}()
|
||||||
for _, step := range tc.TestSteps {
|
for _, step := range tc.TestSteps {
|
||||||
// 1. deal with request body compatibility
|
// 1. deal with request body compatibility
|
||||||
if step.Request != nil && step.Request.Body == nil {
|
convertCompatRequestBody(step.Request)
|
||||||
if step.Request.Json != nil {
|
|
||||||
step.Request.Headers["Content-Type"] = "application/json; charset=utf-8"
|
|
||||||
step.Request.Body = step.Request.Json
|
|
||||||
step.Request.Json = nil
|
|
||||||
} else if step.Request.Data != nil {
|
|
||||||
step.Request.Body = step.Request.Data
|
|
||||||
step.Request.Data = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. deal with validators compatibility
|
// 2. deal with validators compatibility
|
||||||
err = convertCompatValidator(step.Validators)
|
err = convertCompatValidator(step.Validators)
|
||||||
@@ -205,6 +196,19 @@ func (tc *TCase) MakeCompat() (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func convertCompatRequestBody(request *Request) {
|
||||||
|
if request != nil && request.Body == nil {
|
||||||
|
if request.Json != nil {
|
||||||
|
request.Headers["Content-Type"] = "application/json; charset=utf-8"
|
||||||
|
request.Body = request.Json
|
||||||
|
request.Json = nil
|
||||||
|
} else if request.Data != nil {
|
||||||
|
request.Body = request.Data
|
||||||
|
request.Data = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func convertCompatValidator(Validators []interface{}) (err error) {
|
func convertCompatValidator(Validators []interface{}) (err error) {
|
||||||
for i, iValidator := range Validators {
|
for i, iValidator := range Validators {
|
||||||
if _, ok := iValidator.(Validator); ok {
|
if _, ok := iValidator.(Validator); ok {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class SessionRunner(object):
|
|||||||
self.root_dir = self.root_dir or self.__project_meta.RootDir
|
self.root_dir = self.root_dir or self.__project_meta.RootDir
|
||||||
self.__log_path = os.path.join(self.root_dir, "logs", f"{self.case_id}.run.log")
|
self.__log_path = os.path.join(self.root_dir, "logs", f"{self.case_id}.run.log")
|
||||||
|
|
||||||
self.__step_results.clear()
|
self.__step_results = self.__step_results or []
|
||||||
self.session = self.session or HttpSession()
|
self.session = self.session or HttpSession()
|
||||||
self.parser = self.parser or Parser(self.__project_meta.functions)
|
self.parser = self.parser or Parser(self.__project_meta.functions)
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ def run_step_request(runner: HttpRunner, step: TStep) -> StepResult:
|
|||||||
"""run teststep: request"""
|
"""run teststep: request"""
|
||||||
step_result = StepResult(
|
step_result = StepResult(
|
||||||
name=step.name,
|
name=step.name,
|
||||||
|
step_type="request",
|
||||||
success=False,
|
success=False,
|
||||||
)
|
)
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ def run_step_sql_request(runner: HttpRunner, step: TStep) -> StepResult:
|
|||||||
|
|
||||||
step_result = StepResult(
|
step_result = StepResult(
|
||||||
name=step.name,
|
name=step.name,
|
||||||
|
step_type="sql",
|
||||||
success=False,
|
success=False,
|
||||||
)
|
)
|
||||||
step_variables = runner.merge_step_variables(step.variables)
|
step_variables = runner.merge_step_variables(step.variables)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from httprunner.step_request import call_hooks
|
|||||||
|
|
||||||
def run_step_testcase(runner: HttpRunner, step: TStep) -> StepResult:
|
def run_step_testcase(runner: HttpRunner, step: TStep) -> StepResult:
|
||||||
"""run teststep: referenced testcase"""
|
"""run teststep: referenced testcase"""
|
||||||
step_result = StepResult(name=step.name)
|
step_result = StepResult(name=step.name, step_type="testcase")
|
||||||
step_variables = runner.merge_step_variables(step.variables)
|
step_variables = runner.merge_step_variables(step.variables)
|
||||||
step_export = step.export
|
step_export = step.export
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ def run_step_thrift_request(runner: HttpRunner, step: TStep) -> StepResult:
|
|||||||
|
|
||||||
step_result = StepResult(
|
step_result = StepResult(
|
||||||
name=step.name,
|
name=step.name,
|
||||||
|
step_type="thrift",
|
||||||
success=False,
|
success=False,
|
||||||
)
|
)
|
||||||
step_variables = runner.merge_step_variables(step.variables)
|
step_variables = runner.merge_step_variables(step.variables)
|
||||||
|
|||||||
Reference in New Issue
Block a user