From 29ac00fabf4d9d333ee98cf20658b22cf908952a Mon Sep 17 00:00:00 2001 From: debugtalk Date: Mon, 7 May 2018 15:19:14 +0800 Subject: [PATCH] move tests/data/debugtalk.py to tests/debugtalk.py --- tests/data/__init__.py | 0 .../demo_testset_template_import_functions.yml | 2 +- tests/{data => }/debugtalk.py | 17 +++++++++++++++++ tests/suite/create_and_get.yml | 6 +++++- tests/suite/setup.yml | 6 +++++- tests/test_context.py | 4 ++-- tests/test_utils.py | 4 ++-- tests/testcases/smoketest.yml | 6 +++++- 8 files changed, 37 insertions(+), 8 deletions(-) delete mode 100644 tests/data/__init__.py rename tests/{data => }/debugtalk.py (74%) diff --git a/tests/data/__init__.py b/tests/data/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/data/demo_testset_template_import_functions.yml b/tests/data/demo_testset_template_import_functions.yml index 05a6806b..6d2a0117 100644 --- a/tests/data/demo_testset_template_import_functions.yml +++ b/tests/data/demo_testset_template_import_functions.yml @@ -1,7 +1,7 @@ - config: name: "create user testsets." import_module_items: - - tests.data.debugtalk + - tests.debugtalk variables: - user_agent: 'iOS/10.3' - device_sn: ${gen_random_string(15)} diff --git a/tests/data/debugtalk.py b/tests/debugtalk.py similarity index 74% rename from tests/data/debugtalk.py rename to tests/debugtalk.py index b6553f70..f9330b3d 100644 --- a/tests/data/debugtalk.py +++ b/tests/debugtalk.py @@ -56,3 +56,20 @@ def get_account(): {"username": "user1", "password": "111111"}, {"username": "user2", "password": "222222"} ] + +SECRET_KEY = "DebugTalk" + +def gen_random_string(str_len): + random_char_list = [] + for _ in range(str_len): + random_char = random.choice(string.ascii_letters + string.digits) + random_char_list.append(random_char) + + random_string = ''.join(random_char_list) + return random_string + +def setup_hook_add_kwargs(method, url, kwargs): + kwargs["key"] = "value" + +def setup_hook_remove_kwargs(method, url, kwargs): + kwargs.pop("key") diff --git a/tests/suite/create_and_get.yml b/tests/suite/create_and_get.yml index e1d3e7e8..425ee621 100644 --- a/tests/suite/create_and_get.yml +++ b/tests/suite/create_and_get.yml @@ -2,7 +2,11 @@ - config: name: "create user and check result." def: create_and_check($uid, $token) - request: $default_request + request: + "base_url": "http://127.0.0.1:5000" + "headers": + "Content-Type": "application/json" + "device_sn": "$device_sn" output: - token diff --git a/tests/suite/setup.yml b/tests/suite/setup.yml index 782aaaef..126e026b 100644 --- a/tests/suite/setup.yml +++ b/tests/suite/setup.yml @@ -6,7 +6,11 @@ - device_sn: ${gen_random_string(15)} - os_platform: 'ios' - app_version: '2.8.6' - request: $default_request + request: + "base_url": "http://127.0.0.1:5000" + "headers": + "Content-Type": "application/json" + "device_sn": "$device_sn" output: - token diff --git a/tests/test_context.py b/tests/test_context.py index 8b490a53..fb652107 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -163,7 +163,7 @@ class VariableBindsUnittest(ApiServerUnittest): def test_import_module_items(self): testcase1 = { - "import_module_items": ["tests.data.debugtalk"], + "import_module_items": ["tests.debugtalk"], "variables": [ {"TOKEN": "debugtalk"}, {"random": "${gen_random_string(5)}"}, @@ -201,7 +201,7 @@ class VariableBindsUnittest(ApiServerUnittest): def test_get_parsed_request(self): test_runner = runner.Runner() testcase = { - "import_module_items": ["tests.data.debugtalk"], + "import_module_items": ["tests.debugtalk"], "variables": [ {"TOKEN": "debugtalk"}, {"random": "${gen_random_string(5)}"}, diff --git a/tests/test_utils.py b/tests/test_utils.py index 23d2ce42..d7c7bc62 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -300,7 +300,7 @@ class TestUtils(ApiServerUnittest): self.assertNotIn("is_py3", functions_dict) def test_get_imported_module_from_file(self): - imported_module = utils.get_imported_module_from_file("tests/data/debugtalk.py") + imported_module = utils.get_imported_module_from_file("tests/debugtalk.py") self.assertIn("gen_md5", dir(imported_module)) functions_dict = utils.filter_module(imported_module, "function") @@ -308,7 +308,7 @@ class TestUtils(ApiServerUnittest): self.assertNotIn("urllib", functions_dict) with self.assertRaises(exception.FileNotFoundError): - utils.get_imported_module_from_file("tests/data/debugtalk2.py") + utils.get_imported_module_from_file("tests/debugtalk2.py") def test_search_conf_function(self): gen_md5 = utils.search_conf_item("tests/data/demo_binds.yml", "function", "gen_md5") diff --git a/tests/testcases/smoketest.yml b/tests/testcases/smoketest.yml index e2a22d5b..d14c61ce 100644 --- a/tests/testcases/smoketest.yml +++ b/tests/testcases/smoketest.yml @@ -2,7 +2,11 @@ name: smoketest variables: - device_sn: ${gen_random_string(15)} - request: $default_request + request: + "base_url": "http://127.0.0.1:5000" + "headers": + "Content-Type": "application/json" + "device_sn": "$device_sn" - test: name: setup and reset all.