From 89f26f1b212e3c81dd97dacfdc635022f5a23bcd Mon Sep 17 00:00:00 2001 From: xucong053 Date: Mon, 20 Jun 2022 10:15:30 +0800 Subject: [PATCH 1/3] fix: failed to load json/data content in api reference --- hrp/step_api.go | 4 ++++ hrp/testcase.go | 24 ++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/hrp/step_api.go b/hrp/step_api.go index c1c52c3a..cce14cd0 100644 --- a/hrp/step_api.go +++ b/hrp/step_api.go @@ -47,7 +47,11 @@ func (path *APIPath) ToAPI() (*API, error) { if err != nil { return nil, err } + // 1. deal with request body compatibility + convertCompatRequestBody(api.Request) + // 2. deal with validators compatibility err = convertCompatValidator(api.Validators) + // 3. deal with extract expr including hyphen convertExtract(api.Extract) return api, err } diff --git a/hrp/testcase.go b/hrp/testcase.go index 4182cec7..bae01478 100644 --- a/hrp/testcase.go +++ b/hrp/testcase.go @@ -182,16 +182,7 @@ func (tc *TCase) MakeCompat() (err error) { }() for _, step := range tc.TestSteps { // 1. deal with request body compatibility - if step.Request != nil && step.Request.Body == nil { - 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 - } - } + convertCompatRequestBody(step.Request) // 2. deal with validators compatibility err = convertCompatValidator(step.Validators) @@ -205,6 +196,19 @@ func (tc *TCase) MakeCompat() (err error) { 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) { for i, iValidator := range Validators { if _, ok := iValidator.(Validator); ok { From 1eac75906958b6bb9ddb1f936e53a3ca935514fa Mon Sep 17 00:00:00 2001 From: xucong053 Date: Mon, 20 Jun 2022 15:35:05 +0800 Subject: [PATCH 2/3] fix: ensure complete summary results --- httprunner/runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httprunner/runner.py b/httprunner/runner.py index 21fe4c3c..5aa6ce1a 100644 --- a/httprunner/runner.py +++ b/httprunner/runner.py @@ -67,7 +67,7 @@ class SessionRunner(object): 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.__step_results.clear() + self.__step_results = self.__step_results or [] self.session = self.session or HttpSession() self.parser = self.parser or Parser(self.__project_meta.functions) From dab042ae8031c9655755c765053aaddd4ba87ca6 Mon Sep 17 00:00:00 2001 From: xucong053 Date: Mon, 20 Jun 2022 15:56:31 +0800 Subject: [PATCH 3/3] fix: add the step type to the summary step result --- httprunner/step_request.py | 1 + httprunner/step_sql_request.py | 1 + httprunner/step_testcase.py | 2 +- httprunner/step_thrift_request.py | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/httprunner/step_request.py b/httprunner/step_request.py index a78b11b0..c4e63413 100644 --- a/httprunner/step_request.py +++ b/httprunner/step_request.py @@ -81,6 +81,7 @@ def run_step_request(runner: HttpRunner, step: TStep) -> StepResult: """run teststep: request""" step_result = StepResult( name=step.name, + step_type="request", success=False, ) start_time = time.time() diff --git a/httprunner/step_sql_request.py b/httprunner/step_sql_request.py index bef988d2..47a5405b 100644 --- a/httprunner/step_sql_request.py +++ b/httprunner/step_sql_request.py @@ -47,6 +47,7 @@ def run_step_sql_request(runner: HttpRunner, step: TStep) -> StepResult: step_result = StepResult( name=step.name, + step_type="sql", success=False, ) step_variables = runner.merge_step_variables(step.variables) diff --git a/httprunner/step_testcase.py b/httprunner/step_testcase.py index b9cdf24d..1341cc64 100644 --- a/httprunner/step_testcase.py +++ b/httprunner/step_testcase.py @@ -10,7 +10,7 @@ from httprunner.step_request import call_hooks def run_step_testcase(runner: HttpRunner, step: TStep) -> StepResult: """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_export = step.export diff --git a/httprunner/step_thrift_request.py b/httprunner/step_thrift_request.py index 50772df6..322d34e6 100644 --- a/httprunner/step_thrift_request.py +++ b/httprunner/step_thrift_request.py @@ -57,6 +57,7 @@ def run_step_thrift_request(runner: HttpRunner, step: TStep) -> StepResult: step_result = StepResult( name=step.name, + step_type="thrift", success=False, ) step_variables = runner.merge_step_variables(step.variables)