From 38fcc14f29ebcd6895b6cfd9b382b422593c19e1 Mon Sep 17 00:00:00 2001 From: readyou <791100944@qq.com> Date: Wed, 11 Dec 2019 17:50:58 +0800 Subject: [PATCH 1/2] add json schema --- httprunner/loader/schemas/v2/api.schema.json | 42 +++++++ .../schemas/v2/common/config.schema.json | 25 +++++ .../schemas/v2/common/extract.schema.json | 13 +++ .../loader/schemas/v2/common/hook.schema.json | 10 ++ .../schemas/v2/common/request.schema.json | 93 ++++++++++++++++ .../schemas/v2/common/validate.schema.json | 15 +++ .../loader/schemas/v2/testcase.schema.json | 104 ++++++++++++++++++ .../loader/schemas/v2/testsuite.schema.json | 58 ++++++++++ 8 files changed, 360 insertions(+) create mode 100644 httprunner/loader/schemas/v2/api.schema.json create mode 100644 httprunner/loader/schemas/v2/common/config.schema.json create mode 100644 httprunner/loader/schemas/v2/common/extract.schema.json create mode 100644 httprunner/loader/schemas/v2/common/hook.schema.json create mode 100644 httprunner/loader/schemas/v2/common/request.schema.json create mode 100644 httprunner/loader/schemas/v2/common/validate.schema.json create mode 100644 httprunner/loader/schemas/v2/testcase.schema.json create mode 100644 httprunner/loader/schemas/v2/testsuite.schema.json diff --git a/httprunner/loader/schemas/v2/api.schema.json b/httprunner/loader/schemas/v2/api.schema.json new file mode 100644 index 00000000..431a61b8 --- /dev/null +++ b/httprunner/loader/schemas/v2/api.schema.json @@ -0,0 +1,42 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/api.schema.json", + "title": "Api for httprunner", + "description": "Api for httprunner", + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "Name of the api" + }, + "base_url": { + "type": "string", + "description": "The base_url will be added before a relative URI" + }, + "request": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/request.schema.json" + }, + "variables": { + "type": "object", + "description": "Variables for the api" + }, + "extract": { + "type": "array", + "description": "Extract rules", + "items": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/extract.schema.json" + } + }, + "validate": { + "type": "array", + "description": "Validate rules", + "items": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/validate.schema.json" + } + } + }, + "required": [ + "name", + "request" + ] +} \ No newline at end of file diff --git a/httprunner/loader/schemas/v2/common/config.schema.json b/httprunner/loader/schemas/v2/common/config.schema.json new file mode 100644 index 00000000..67de36ac --- /dev/null +++ b/httprunner/loader/schemas/v2/common/config.schema.json @@ -0,0 +1,25 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/config.schema.json", + "title": "Config for httprunner", + "description": "Used in teststep/testcase/testsuite", + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "base_url": { + "type": "string", + "description": "The base_url will be added before a relative URI" + }, + "variables": { + "type": "object" + }, + "setup_hooks": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json" + }, + "teardown_hooks": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json" + } + } +} \ No newline at end of file diff --git a/httprunner/loader/schemas/v2/common/extract.schema.json b/httprunner/loader/schemas/v2/common/extract.schema.json new file mode 100644 index 00000000..cf24863d --- /dev/null +++ b/httprunner/loader/schemas/v2/common/extract.schema.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/extract.schema.json", + "title": "Extract rules for httprunner", + "description": "Used to extract variables for later requests", + "type": "object", + "patternProperties": { + ".*": { + "description": "extracted_variable_name: extract_rule", + "type": "string" + } + } +} \ No newline at end of file diff --git a/httprunner/loader/schemas/v2/common/hook.schema.json b/httprunner/loader/schemas/v2/common/hook.schema.json new file mode 100644 index 00000000..f80be216 --- /dev/null +++ b/httprunner/loader/schemas/v2/common/hook.schema.json @@ -0,0 +1,10 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json", + "title": "setup_hooks or teardown_hooks for httprunner", + "description": "Define setup_hooks or teardown_hooks for httprunner", + "type": "array", + "items": { + "type": "string" + } +} \ No newline at end of file diff --git a/httprunner/loader/schemas/v2/common/request.schema.json b/httprunner/loader/schemas/v2/common/request.schema.json new file mode 100644 index 00000000..c9385ea0 --- /dev/null +++ b/httprunner/loader/schemas/v2/common/request.schema.json @@ -0,0 +1,93 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/request.schema.json", + "title": "request for httprunner", + "description": "Used to define a api or used in a teststep. Same parameters as python's package 'requests'", + "type": "object", + "properties": { + "method": { + "type": "string", + "description": "Request method", + "enum": [ + "GET", + "POST", + "OPTIONS", + "HEAD", + "PUT", + "PATCH", + "DELETE" + ] + }, + "url": { + "description": "Request url", + "type": "string" + }, + "params": { + "type": "object", + "description": "Used to define the parameters of a 'GET' request" + }, + "data": { + "type": "object", + "description": "Used to define the parameters of a 'POST' request in the application/x-www-form-urlencoded format" + }, + "json": { + "type": "object", + "description": "Used to define the parameters of a 'POST' request in the application/json format" + }, + "headers": { + "description": "Request headers", + "type": "object" + }, + "cookies": { + "description": "Request cookies", + "type": "object" + }, + "files": { + "type": "object" + }, + "auth": { + "type": "array" + }, + "timeout": { + "type": "number" + }, + "allow_redirects": { + "type": "boolean" + }, + "proxies": { + "type": "object" + }, + "verify": { + "oneOf": [ + { + "type": "boolean" + }, + { + "type": "string" + } + ] + }, + "stream": { + "type": "boolean" + }, + "cert": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "maxItems": 2, + "minItems": 2, + "items": { + "type": "string" + } + } + ] + } + }, + "required": [ + "method", + "url" + ] +} \ No newline at end of file diff --git a/httprunner/loader/schemas/v2/common/validate.schema.json b/httprunner/loader/schemas/v2/common/validate.schema.json new file mode 100644 index 00000000..14371992 --- /dev/null +++ b/httprunner/loader/schemas/v2/common/validate.schema.json @@ -0,0 +1,15 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/validate.schema.json", + "title": "Validate rule of httprunner", + "description": "Validate rule of httprunner", + "type": "object", + "patternProperties": { + ".*": { + "type": "array", + "description": "validate_function_name: [check_value, expect_value]", + "minItems": 2, + "maxItems": 2 + } + } +} \ No newline at end of file diff --git a/httprunner/loader/schemas/v2/testcase.schema.json b/httprunner/loader/schemas/v2/testcase.schema.json new file mode 100644 index 00000000..b4c4198c --- /dev/null +++ b/httprunner/loader/schemas/v2/testcase.schema.json @@ -0,0 +1,104 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/testcase.schema.json", + "title": "Testcase for httprunner", + "description": "Testcase for httprunner", + "type": "object", + "properties": { + "config": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/config.schema.json" + }, + "teststeps": { + "description": "Teststep of a testcase", + "type": "array", + "items": { + "$ref": "#/definitions/teststep" + } + } + }, + "required": [ + "teststeps" + ], + "definitions": { + "teststep": { + "type": "object", + "oneOf": [ + { + "properties": { + "name": { + "description": "Teststep name", + "type": "string" + }, + "api": { + "description": "Api reference, it's usually the relative path of the api", + "type": "string" + }, + "variables": { + "type": "object" + }, + "extract": { + "description": "Extract rules", + "type": "array", + "items": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/extract.schema.json" + } + }, + "validate": { + "description": "Validate rules", + "type": "array", + "items": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/validate.schema.json" + } + }, + "setup_hooks": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json" + }, + "teardown_hooks": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json" + } + }, + "required": [ + "api" + ] + }, + { + "properties": { + "name": { + "description": "Teststep name", + "type": "string" + }, + "request": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/request.schema.json" + }, + "variables": { + "type": "object" + }, + "extract": { + "description": "Extract rules", + "type": "array", + "items": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/extract.schema.json" + } + }, + "validate": { + "description": "Validate rules", + "type": "array", + "items": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/validate.schema.json" + } + }, + "setup_hooks": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json" + }, + "teardown_hooks": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json" + } + }, + "required": [ + "request" + ] + } + ] + } + } +} \ No newline at end of file diff --git a/httprunner/loader/schemas/v2/testsuite.schema.json b/httprunner/loader/schemas/v2/testsuite.schema.json new file mode 100644 index 00000000..41e0de57 --- /dev/null +++ b/httprunner/loader/schemas/v2/testsuite.schema.json @@ -0,0 +1,58 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/testsuite.schema.json", + "title": "Testsuite for httprunner", + "description": "Testsuite for httprunner", + "type": "object", + "properties": { + "config": { + "allOf": [ + { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/config.schema.json" + } + ], + "properties": { + "verify": { + "type": "boolean" + } + } + }, + "testcases": { + "type": "array", + "items": { + "$ref": "#/definitions/testcase" + } + }, + "setup_hooks": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json" + }, + "teardown_hooks": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json" + } + }, + "required": [ + "testcases" + ], + "definitions": { + "testcase": { + "type": "object", + "properties": { + "name": { + "description": "Testcase name", + "type": "string" + }, + "parameters": { + "description": "Parameters will generate cartesian product variables, each set of variables is tested once", + "type": "object" + }, + "testcase": { + "description": "Testcase reference, it's usually the relative path of the testcase", + "type": "string" + } + }, + "required": [ + "testcase" + ] + } + } +} \ No newline at end of file From c7c524ff8970d0a77a4db2eff15f585dd6ee883d Mon Sep 17 00:00:00 2001 From: "L.G" Date: Thu, 26 Dec 2019 11:05:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E6=89=B9=E9=87=8F=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=EF=BC=8C?= =?UTF-8?q?=E5=BD=93=E6=89=A7=E8=A1=8C=E6=97=B6=E9=97=B4=E5=B0=8F=E4=BA=8E?= =?UTF-8?q?1=E7=A7=92=E6=8A=A5=E5=91=8A=E4=BC=9A=E8=A2=AB=E8=A6=86?= =?UTF-8?q?=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- httprunner/report/html/gen_report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httprunner/report/html/gen_report.py b/httprunner/report/html/gen_report.py index 43092849..265acdea 100644 --- a/httprunner/report/html/gen_report.py +++ b/httprunner/report/html/gen_report.py @@ -41,7 +41,7 @@ def gen_html_report(summary, report_template=None, report_dir=None, report_file= report_file_name = os.path.basename(report_file) else: report_dir = report_dir or os.path.join(os.getcwd(), "reports") - report_file_name = "{}.html".format(start_at_timestamp) + report_file_name = "{}.html".format(int(start_at_timestamp * 1000)) if not os.path.isdir(report_dir): os.makedirs(report_dir)