diff --git a/README.md b/README.md index 84a4a886..c0570535 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![Github Actions](https://github.com/httprunner/httprunner/actions/workflows/unittest.yml/badge.svg)](https://github.com/httprunner/httprunner/actions) [![codecov](https://codecov.io/gh/httprunner/httprunner/branch/master/graph/badge.svg)](https://codecov.io/gh/httprunner/httprunner) -[![Go Report Card](https://goreportcard.com/badge/github.com/httprunner/httprunner)](https://goreportcard.com/report/github.com/httprunner/httprunner) [![Go Reference](https://pkg.go.dev/badge/github.com/httprunner/httprunner.svg)](https://pkg.go.dev/github.com/httprunner/httprunner) [![downloads](https://pepy.tech/badge/httprunner)](https://pepy.tech/project/httprunner) [![pypi version](https://img.shields.io/pypi/v/httprunner.svg)](https://pypi.python.org/pypi/httprunner) diff --git a/tests/data/.csv b/examples/data/.csv similarity index 100% rename from tests/data/.csv rename to examples/data/.csv diff --git a/tests/data/a-b.c/1.yml b/examples/data/a-b.c/1.yml similarity index 100% rename from tests/data/a-b.c/1.yml rename to examples/data/a-b.c/1.yml diff --git a/tests/data/a-b.c/2 3.yml b/examples/data/a-b.c/2 3.yml similarity index 100% rename from tests/data/a-b.c/2 3.yml rename to examples/data/a-b.c/2 3.yml diff --git a/tests/data/a-b.c/中文case.yml b/examples/data/a-b.c/中文case.yml similarity index 100% rename from tests/data/a-b.c/中文case.yml rename to examples/data/a-b.c/中文case.yml diff --git a/examples/data/a_b_c/T1_test.py b/examples/data/a_b_c/T1_test.py new file mode 100644 index 00000000..db722b78 --- /dev/null +++ b/examples/data/a_b_c/T1_test.py @@ -0,0 +1,36 @@ +# NOTE: Generated By HttpRunner v4.0.0-alpha +# FROM: a-b.c/1.yml + + +from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase + + +class TestCaseT1(HttpRunner): + + config = ( + Config("request methods testcase with functions") + .variables(**{"foo1": "config_bar1", "foo2": "config_bar2"}) + .base_url("https://postman-echo.com") + .verify(False) + ) + + teststeps = [ + Step( + RunRequest("get with params") + .with_variables(**{"foo1": "bar1", "sum_v": "${sum_two(1, 2)}"}) + .get("/get") + .with_params(**{"foo1": "$foo1", "foo2": "$foo2", "sum_v": "$sum_v"}) + .with_headers(**{"User-Agent": "HttpRunner/${get_httprunner_version()}"}) + .extract() + .with_jmespath("body.args.foo2", "session_foo2") + .validate() + .assert_equal("status_code", 200) + .assert_equal("body.args.foo1", "bar1") + .assert_equal("body.args.sum_v", "3") + .assert_equal("body.args.foo2", "config_bar2") + ), + ] + + +if __name__ == "__main__": + TestCaseT1().test_start() diff --git a/examples/data/a_b_c/T2_3_test.py b/examples/data/a_b_c/T2_3_test.py new file mode 100644 index 00000000..eec4401b --- /dev/null +++ b/examples/data/a_b_c/T2_3_test.py @@ -0,0 +1,46 @@ +# NOTE: Generated By HttpRunner v4.0.0-alpha +# FROM: a-b.c/2 3.yml + + +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).parent.parent)) + + +from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase + +from a_b_c.T1_test import TestCaseT1 as T1 + + +class TestCaseT23(HttpRunner): + + config = ( + Config("reference testcase unittest for abnormal folder path") + .base_url("https://postman-echo.com") + .verify(False) + ) + + teststeps = [ + Step(RunTestCase("request with functions").call(T1).export(*["session_foo2"])), + Step( + RunRequest("post form data") + .with_variables(**{"foo1": "bar12"}) + .post("/post") + .with_headers( + **{ + "User-Agent": "HttpRunner/${get_httprunner_version()}", + "Content-Type": "application/x-www-form-urlencoded", + } + ) + .with_data("foo1=$foo1&foo2=$session_foo2") + .validate() + .assert_equal("status_code", 200) + .assert_equal("body.form.foo1", "bar12") + .assert_equal("body.form.foo2", "config_bar2") + ), + ] + + +if __name__ == "__main__": + TestCaseT23().test_start() diff --git a/examples/data/a_b_c/__init__.py b/examples/data/a_b_c/__init__.py new file mode 100644 index 00000000..70cfba53 --- /dev/null +++ b/examples/data/a_b_c/__init__.py @@ -0,0 +1 @@ +# NOTICE: Generated By HttpRunner. DO NOT EDIT! diff --git a/tests/data/debugtalk.py b/examples/data/debugtalk.py similarity index 100% rename from tests/data/debugtalk.py rename to examples/data/debugtalk.py diff --git a/tests/ext/har2case/data/demo-quickstart.har b/examples/data/har2case/demo-quickstart.har similarity index 100% rename from tests/ext/har2case/data/demo-quickstart.har rename to examples/data/har2case/demo-quickstart.har diff --git a/tests/ext/har2case/data/demo.har b/examples/data/har2case/demo.har similarity index 100% rename from tests/ext/har2case/data/demo.har rename to examples/data/har2case/demo.har diff --git a/tests/ext/har2case/data/profile.yml b/examples/data/har2case/profile.yml similarity index 100% rename from tests/ext/har2case/data/profile.yml rename to examples/data/har2case/profile.yml diff --git a/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_functions_test.py b/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_functions_test.py index 9836c8fb..91682f56 100644 --- a/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_functions_test.py +++ b/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_functions_test.py @@ -1,4 +1,4 @@ -# NOTE: Generated By HttpRunner v3.1.7 +# NOTE: Generated By HttpRunner v4.0.0-alpha # FROM: request_methods/request_with_functions.yml diff --git a/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_testcase_reference_test.py b/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_testcase_reference_test.py index f2b82850..ab052c17 100644 --- a/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_testcase_reference_test.py +++ b/examples/postman_echo/request_methods/demo_testsuite_yml/request_with_testcase_reference_test.py @@ -1,4 +1,4 @@ -# NOTE: Generated By HttpRunner v3.1.7 +# NOTE: Generated By HttpRunner v4.0.0-alpha # FROM: request_methods/request_with_testcase_reference.yml diff --git a/examples/postman_echo/request_methods/hardcode_test.py b/examples/postman_echo/request_methods/hardcode_test.py index 4cb70976..ba492426 100644 --- a/examples/postman_echo/request_methods/hardcode_test.py +++ b/examples/postman_echo/request_methods/hardcode_test.py @@ -1,4 +1,4 @@ -# NOTE: Generated By HttpRunner v3.1.7 +# NOTE: Generated By HttpRunner v4.0.0-alpha # FROM: request_methods/hardcode.yml diff --git a/examples/postman_echo/request_methods/request_with_functions_test.py b/examples/postman_echo/request_methods/request_with_functions_test.py index 47f848fc..3c23b94c 100644 --- a/examples/postman_echo/request_methods/request_with_functions_test.py +++ b/examples/postman_echo/request_methods/request_with_functions_test.py @@ -1,4 +1,4 @@ -# NOTE: Generated By HttpRunner v3.1.7 +# NOTE: Generated By HttpRunner v4.0.0-alpha # FROM: request_methods/request_with_functions.yml diff --git a/examples/postman_echo/request_methods/request_with_parameters_test.py b/examples/postman_echo/request_methods/request_with_parameters_test.py index 659ccc2a..5a538af5 100644 --- a/examples/postman_echo/request_methods/request_with_parameters_test.py +++ b/examples/postman_echo/request_methods/request_with_parameters_test.py @@ -1,4 +1,4 @@ -# NOTE: Generated By HttpRunner v3.1.7 +# NOTE: Generated By HttpRunner v4.0.0-alpha # FROM: request_methods/request_with_parameters.yml diff --git a/examples/postman_echo/request_methods/request_with_testcase_reference_test.py b/examples/postman_echo/request_methods/request_with_testcase_reference_test.py index 34ffd60c..71305153 100644 --- a/examples/postman_echo/request_methods/request_with_testcase_reference_test.py +++ b/examples/postman_echo/request_methods/request_with_testcase_reference_test.py @@ -1,4 +1,4 @@ -# NOTE: Generated By HttpRunner v3.1.7 +# NOTE: Generated By HttpRunner v4.0.0-alpha # FROM: request_methods/request_with_testcase_reference.yml diff --git a/examples/postman_echo/request_methods/request_with_variables_test.py b/examples/postman_echo/request_methods/request_with_variables_test.py index 39d25113..61d9382b 100644 --- a/examples/postman_echo/request_methods/request_with_variables_test.py +++ b/examples/postman_echo/request_methods/request_with_variables_test.py @@ -1,4 +1,4 @@ -# NOTE: Generated By HttpRunner v3.1.7 +# NOTE: Generated By HttpRunner v4.0.0-alpha # FROM: request_methods/request_with_variables.yml diff --git a/examples/postman_echo/request_methods/validate_with_functions_test.py b/examples/postman_echo/request_methods/validate_with_functions_test.py index f4cb8a28..d2f58894 100644 --- a/examples/postman_echo/request_methods/validate_with_functions_test.py +++ b/examples/postman_echo/request_methods/validate_with_functions_test.py @@ -1,4 +1,4 @@ -# NOTE: Generated By HttpRunner v3.1.7 +# NOTE: Generated By HttpRunner v4.0.0-alpha # FROM: request_methods/validate_with_functions.yml diff --git a/examples/postman_echo/request_methods/validate_with_variables_test.py b/examples/postman_echo/request_methods/validate_with_variables_test.py index 3cc7953f..eaa20726 100644 --- a/examples/postman_echo/request_methods/validate_with_variables_test.py +++ b/examples/postman_echo/request_methods/validate_with_variables_test.py @@ -1,4 +1,4 @@ -# NOTE: Generated By HttpRunner v3.1.7 +# NOTE: Generated By HttpRunner v4.0.0-alpha # FROM: request_methods/validate_with_variables.yml diff --git a/tests/app/debug_test.py b/httprunner/app/debug_test.py similarity index 100% rename from tests/app/debug_test.py rename to httprunner/app/debug_test.py diff --git a/tests/cli_test.py b/httprunner/cli_test.py similarity index 100% rename from tests/cli_test.py rename to httprunner/cli_test.py diff --git a/tests/compat_test.py b/httprunner/compat_test.py similarity index 95% rename from tests/compat_test.py rename to httprunner/compat_test.py index 987b1785..895ec962 100644 --- a/tests/compat_test.py +++ b/httprunner/compat_test.py @@ -11,25 +11,25 @@ class TestCompat(unittest.TestCase): def test_convert_variables(self): raw_variables = [{"var1": 1}, {"var2": "val2"}] self.assertEqual( - compat.convert_variables(raw_variables, "tests/data/a-b.c/1.yml"), + compat.convert_variables(raw_variables, "examples/data/a-b.c/1.yml"), {"var1": 1, "var2": "val2"}, ) raw_variables = {"var1": 1, "var2": "val2"} self.assertEqual( - compat.convert_variables(raw_variables, "tests/data/a-b.c/1.yml"), + compat.convert_variables(raw_variables, "examples/data/a-b.c/1.yml"), {"var1": 1, "var2": "val2"}, ) raw_variables = "${get_variables()}" self.assertEqual( - compat.convert_variables(raw_variables, "tests/data/a-b.c/1.yml"), + compat.convert_variables(raw_variables, "examples/data/a-b.c/1.yml"), {"foo1": "session_bar1"}, ) with self.assertRaises(exceptions.TestCaseFormatError): raw_variables = [{"var1": 1}, {"var2": "val2", "var3": 3}] - compat.convert_variables(raw_variables, "tests/data/a-b.c/1.yml") + compat.convert_variables(raw_variables, "examples/data/a-b.c/1.yml") with self.assertRaises(exceptions.TestCaseFormatError): - compat.convert_variables(None, "tests/data/a-b.c/1.yml") + compat.convert_variables(None, "examples/data/a-b.c/1.yml") def test_convert_jmespath(self): diff --git a/tests/ext/har2case/core_test.py b/httprunner/ext/har2case/core_test.py similarity index 93% rename from tests/ext/har2case/core_test.py rename to httprunner/ext/har2case/core_test.py index 8d79e1db..0c39df1c 100644 --- a/tests/ext/har2case/core_test.py +++ b/httprunner/ext/har2case/core_test.py @@ -2,14 +2,15 @@ import os from httprunner.ext.har2case.core import HarParser from httprunner.ext.har2case.utils import load_har_log_entries -from tests.ext.har2case.har_utils_test import TestHar2CaseUtils +from httprunner.ext.har2case.utils_test import TestHar2CaseUtils class TestHar(TestHar2CaseUtils): def setUp(self): - self.har_path = os.path.join(os.path.dirname(__file__), "data", "demo.har") + self.data_dir = os.path.join(os.getcwd(), "examples", "data", "har2case") + self.har_path = os.path.join(self.data_dir, "demo.har") self.har_parser = HarParser(self.har_path) - self.profile_path = os.path.join(os.path.dirname(__file__), "data", "profile.yml") + self.profile_path = os.path.join(self.data_dir, "profile.yml") def test_prepare_teststep(self): log_entries = load_har_log_entries(self.har_path) @@ -35,14 +36,14 @@ class TestHar(TestHar2CaseUtils): self.assertIn("validate", teststeps[0]) def test_gen_testcase_yaml(self): - yaml_file = os.path.join(os.path.dirname(__file__), "data", "demo.yml") + yaml_file = os.path.join(self.data_dir, "demo.yml") self.har_parser.gen_testcase(file_type="YAML") self.assertTrue(os.path.isfile(yaml_file)) os.remove(yaml_file) def test_gen_testcase_json(self): - json_file = os.path.join(os.path.dirname(__file__), "data", "demo.json") + json_file = os.path.join(self.data_dir, "demo.json") self.har_parser.gen_testcase(file_type="JSON") self.assertTrue(os.path.isfile(json_file)) @@ -169,7 +170,7 @@ class TestHar(TestHar2CaseUtils): def test_make_testcase(self): har_path = os.path.join( - os.path.dirname(__file__), "data", "demo-quickstart.har" + self.data_dir, "demo-quickstart.har" ) har_parser = HarParser(har_path) testcase = har_parser._make_testcase() diff --git a/tests/ext/har2case/har_utils_test.py b/httprunner/ext/har2case/utils_test.py similarity index 90% rename from tests/ext/har2case/har_utils_test.py rename to httprunner/ext/har2case/utils_test.py index 658ec3ae..6c414adc 100644 --- a/tests/ext/har2case/har_utils_test.py +++ b/httprunner/ext/har2case/utils_test.py @@ -6,10 +6,13 @@ from httprunner.ext.har2case import utils class TestHar2CaseUtils(unittest.TestCase): + + data_dir = os.path.join(os.getcwd(), "examples", "data", "har2case") + @staticmethod def create_har_file(file_name, content): file_path = os.path.join( - os.path.dirname(__file__), "data", "{}.har".format(file_name) + TestHar2CaseUtils.data_dir, "{}.har".format(file_name) ) with open(file_path, "w") as f: f.write(json.dumps(content)) @@ -17,7 +20,7 @@ class TestHar2CaseUtils(unittest.TestCase): return file_path def test_load_har_log_entries(self): - har_path = os.path.join(os.path.dirname(__file__), "data", "demo.har") + har_path = os.path.join(TestHar2CaseUtils.data_dir, "demo.har") log_entries = utils.load_har_log_entries(har_path) self.assertIsInstance(log_entries, list) self.assertIn("request", log_entries[0]) diff --git a/tests/loader_test.py b/httprunner/loader_test.py similarity index 98% rename from tests/loader_test.py rename to httprunner/loader_test.py index 9f9210e8..95449f43 100644 --- a/tests/loader_test.py +++ b/httprunner/loader_test.py @@ -41,7 +41,7 @@ class TestLoader(unittest.TestCase): os.remove(json_tmp_file) def test_load_testcases_bad_filepath(self): - testcase_file_path = os.path.join(os.getcwd(), "tests/data/demo") + testcase_file_path = os.path.join(os.getcwd(), "examples/data/demo") with self.assertRaises(exceptions.FileNotFound): loader.load_testcase_file(testcase_file_path) diff --git a/tests/make_test.py b/httprunner/make_test.py similarity index 92% rename from tests/make_test.py rename to httprunner/make_test.py index 339910ce..b6a40f20 100644 --- a/tests/make_test.py +++ b/httprunner/make_test.py @@ -18,6 +18,7 @@ class TestMake(unittest.TestCase): pytest_files_made_cache_mapping.clear() pytest_files_run_set.clear() loader.project_meta = None + self.data_dir = os.path.join(os.getcwd(), "examples", "data") def test_make_testcase(self): path = ["examples/postman_echo/request_methods/request_with_variables.yml"] @@ -94,9 +95,9 @@ from request_methods.request_with_functions_test import ( def test_ensure_file_path_valid(self): self.assertEqual( ensure_file_abs_path_valid( - os.path.join(os.getcwd(), "tests", "data", "a-b.c", "2 3.yml") + os.path.join(self.data_dir, "a-b.c", "2 3.yml") ), - os.path.join(os.getcwd(), "tests", "data", "a_b_c", "T2_3.yml"), + os.path.join(self.data_dir, "a_b_c", "T2_3.yml"), ) loader.project_meta = None self.assertEqual( @@ -117,30 +118,27 @@ from request_methods.request_with_functions_test import ( loader.project_meta = None self.assertEqual( ensure_file_abs_path_valid( - os.path.join(os.getcwd(), "tests", "data", ".csv") + os.path.join(self.data_dir, ".csv") ), - os.path.join(os.getcwd(), "tests", "data", ".csv"), + os.path.join(self.data_dir, ".csv"), ) def test_convert_testcase_path(self): self.assertEqual( convert_testcase_path( - os.path.join(os.getcwd(), "tests", "data", "a-b.c", "2 3.yml") + os.path.join(self.data_dir, "a-b.c", "2 3.yml") ), ( - os.path.join(os.getcwd(), "tests", "data", "a_b_c", "T2_3_test.py"), + os.path.join(self.data_dir, "a_b_c", "T2_3_test.py"), "T23", ), ) self.assertEqual( convert_testcase_path( - os.path.join(os.getcwd(), "tests", "data", "a-b.c", "中文case.yml") + os.path.join(self.data_dir, "a-b.c", "中文case.yml") ), ( - os.path.join( - os.getcwd(), - os.path.join("tests", "data", "a_b_c", "中文case_test.py"), - ), + os.path.join(self.data_dir, "a_b_c", "中文case_test.py"), "中文Case", ), ) diff --git a/tests/parser_test.py b/httprunner/parser_test.py similarity index 100% rename from tests/parser_test.py rename to httprunner/parser_test.py diff --git a/tests/response_test.py b/httprunner/response_test.py similarity index 100% rename from tests/response_test.py rename to httprunner/response_test.py diff --git a/tests/runner_test.py b/httprunner/runner_test.py similarity index 78% rename from tests/runner_test.py rename to httprunner/runner_test.py index 96654d3b..ef59dcdf 100644 --- a/tests/runner_test.py +++ b/httprunner/runner_test.py @@ -32,9 +32,9 @@ class TestHttpRunner(unittest.TestCase): self.assertEqual(len(result.step_datas), 2) def test_run_testcase_with_abnormal_path(self): - exit_code = main_run(["tests/data/a-b.c/2 3.yml"]) + exit_code = main_run(["examples/data/a-b.c/2 3.yml"]) self.assertEqual(exit_code, 0) - self.assertTrue(os.path.exists("tests/data/a_b_c/__init__.py")) - self.assertTrue(os.path.exists("tests/data/debugtalk.py")) - self.assertTrue(os.path.exists("tests/data/a_b_c/T1_test.py")) - self.assertTrue(os.path.exists("tests/data/a_b_c/T2_3_test.py")) + self.assertTrue(os.path.exists("examples/data/a_b_c/__init__.py")) + self.assertTrue(os.path.exists("examples/data/debugtalk.py")) + self.assertTrue(os.path.exists("examples/data/a_b_c/T1_test.py")) + self.assertTrue(os.path.exists("examples/data/a_b_c/T2_3_test.py")) diff --git a/tests/scaffold_test.py b/httprunner/scaffold_test.py similarity index 100% rename from tests/scaffold_test.py rename to httprunner/scaffold_test.py diff --git a/tests/utils_test.py b/httprunner/utils_test.py similarity index 100% rename from tests/utils_test.py rename to httprunner/utils_test.py diff --git a/pyproject.toml b/pyproject.toml index c52e6d89..2f5614e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,14 +3,14 @@ name = "httprunner" version = "4.0.0-alpha" description = "One-stop solution for HTTP(S) testing." license = "Apache-2.0" -readme = "docs/README.md" +readme = "README.md" authors = ["debugtalk "] homepage = "https://github.com/httprunner/httprunner" repository = "https://github.com/httprunner/httprunner" -documentation = "https://docs.httprunner.org" +documentation = "https://httprunner.com/docs" -keywords = ["HTTP", "api", "test", "requests", "locustio"] +keywords = ["HTTP", "apitest", "perftest", "DEM", "requests", "locustio"] classifiers = [ "Development Status :: 5 - Production/Stable", diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/app/__init__.py b/tests/app/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/ext/__init__.py b/tests/ext/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/ext/har2case/__init__.py b/tests/ext/har2case/__init__.py deleted file mode 100644 index e69de29b..00000000