From 7f4c565fcbc0452e573b20099a822de453778b3c Mon Sep 17 00:00:00 2001 From: debugtalk Date: Tue, 29 Aug 2017 21:59:42 +0800 Subject: [PATCH] rename fixture module name --- README.md | 6 +- ate/runner.py | 2 +- examples/{utils.py => debugtalk.py} | 0 examples/quickstart-demo-rev-2.yml | 2 +- examples/quickstart-demo-rev-3.yml | 2 +- tests/data/custom_functions.py | 67 ------------------- tests/data/debugtalk.py | 31 +++++++++ tests/data/demo_binds.yml | 2 +- ...demo_testset_template_import_functions.yml | 2 +- tests/test_context.py | 4 +- 10 files changed, 41 insertions(+), 77 deletions(-) rename examples/{utils.py => debugtalk.py} (100%) delete mode 100644 tests/data/custom_functions.py create mode 100644 tests/data/debugtalk.py diff --git a/README.md b/README.md index fc066194..ca4b42c2 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ To ensure the installation or upgrade is successful, you can execute command `at ```text $ ate -V -ApiTestEngine version: 0.5.1 +ApiTestEngine version: 0.5.4 ``` Execute the command `ate -h` to view command help. @@ -74,7 +74,7 @@ To install mail helper, run this command in your terminal: $ pip install -U git+https://github.com/debugtalk/jenkins-mail-py.git#egg=jenkins-mail-py $ ate -V jenkins-mail-py version: 0.2.5 -ApiTestEngine version: 0.5.1 +ApiTestEngine version: 0.5.4 ``` With [`jenkins-mail-py`][jenkins-mail-py] installed, you can see more optional arguments. @@ -133,7 +133,7 @@ And here is testset example of typical scenario: get token at the beginning, and - config: name: "create user testsets." import_module_functions: - - tests.data.custom_functions + - tests.data.debugtalk variable_binds: - user_agent: 'iOS/10.3' - device_sn: ${gen_random_string(15)} diff --git a/ate/runner.py b/ate/runner.py index 9b2a3302..b73995ad 100644 --- a/ate/runner.py +++ b/ate/runner.py @@ -25,7 +25,7 @@ class Runner(object): "lambda *str_args: hashlib.md5(''.join(str_args).\ encode('utf-8')).hexdigest()" }, - "import_module_functions": ["test.data.custom_functions"], + "import_module_functions": ["test.data.debugtalk"], "variable_binds": [ {"TOKEN": "debugtalk"}, {"random": "${gen_random_string(5)}"}, diff --git a/examples/utils.py b/examples/debugtalk.py similarity index 100% rename from examples/utils.py rename to examples/debugtalk.py diff --git a/examples/quickstart-demo-rev-2.yml b/examples/quickstart-demo-rev-2.yml index 44addc18..4380e047 100644 --- a/examples/quickstart-demo-rev-2.yml +++ b/examples/quickstart-demo-rev-2.yml @@ -1,7 +1,7 @@ - test: name: get token import_module_functions: - - examples.utils + - examples.debugtalk variable_binds: - user_agent: 'iOS/10.3' - device_sn: ${gen_random_string(15)} diff --git a/examples/quickstart-demo-rev-3.yml b/examples/quickstart-demo-rev-3.yml index 5922606f..3b3f81d0 100644 --- a/examples/quickstart-demo-rev-3.yml +++ b/examples/quickstart-demo-rev-3.yml @@ -1,7 +1,7 @@ - config: name: "smoketest for CRUD users." import_module_functions: - - examples.utils + - examples.debugtalk variable_binds: - device_sn: ${gen_random_string(15)} request: diff --git a/tests/data/custom_functions.py b/tests/data/custom_functions.py deleted file mode 100644 index da4f9c95..00000000 --- a/tests/data/custom_functions.py +++ /dev/null @@ -1,67 +0,0 @@ -import hashlib -import hmac -import json -import random -import string -import time - -try: - string_type = basestring - PYTHON_VERSION = 2 - import urllib -except NameError: - string_type = str - PYTHON_VERSION = 3 - import urllib.parse as urllib - -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 - -gen_random_string_lambda = lambda str_len: ''.join( - random.choice(string.ascii_letters + string.digits) for _ in range(str_len)) - -def get_sign(*args): - content = ''.join(args).encode('ascii') - sign_key = SECRET_KEY.encode('ascii') - sign = hmac.new(sign_key, content, hashlib.sha1).hexdigest() - return sign - -get_sign_lambda = lambda *args: hmac.new( - 'DebugTalk'.encode('ascii'), - ''.join(args).encode('ascii'), - hashlib.sha1).hexdigest() - -def gen_md5(*args): - return hashlib.md5("".join(args).encode('utf-8')).hexdigest() - -def gen_urlencode_str(**kargs): - urlencoded_str = "" - quote_times = int(kargs.pop("quote_times", 1)) - - for key, value in kargs.items(): - urlencoded_str += key - urlencoded_str += "=" - if value == "undefined": - urlencoded_str += "undefined" - else: - if isinstance(value, (dict, list)): - value = json.dumps(value) - elif isinstance(value, (int, float)): - value = str(value) - - value_str = value.encode('utf-8') - for _ in range(quote_times): - value_str = urllib.quote_plus(value_str) - urlencoded_str += value_str - - urlencoded_str += "&" - - return urlencoded_str.strip("&") diff --git a/tests/data/debugtalk.py b/tests/data/debugtalk.py new file mode 100644 index 00000000..19dd4ce8 --- /dev/null +++ b/tests/data/debugtalk.py @@ -0,0 +1,31 @@ +import hashlib +import hmac +import json +import random +import string +import time + +try: + string_type = basestring + PYTHON_VERSION = 2 + import urllib +except NameError: + string_type = str + PYTHON_VERSION = 3 + import urllib.parse as urllib + +SECRET_KEY = "DebugTalk" + +def get_sign(*args): + content = ''.join(args).encode('ascii') + sign_key = SECRET_KEY.encode('ascii') + sign = hmac.new(sign_key, content, hashlib.sha1).hexdigest() + return sign + +get_sign_lambda = lambda *args: hmac.new( + 'DebugTalk'.encode('ascii'), + ''.join(args).encode('ascii'), + hashlib.sha1).hexdigest() + +def gen_md5(*args): + return hashlib.md5("".join(args).encode('utf-8')).hexdigest() diff --git a/tests/data/demo_binds.yml b/tests/data/demo_binds.yml index f1e5327e..5a1a70d9 100644 --- a/tests/data/demo_binds.yml +++ b/tests/data/demo_binds.yml @@ -28,7 +28,7 @@ bind_lambda_functions_with_import: bind_module_functions: function_binds: import_module_functions: - - tests.data.custom_functions + - tests.data.debugtalk variable_binds: - TOKEN: debugtalk - random: ${gen_random_string(5)} diff --git a/tests/data/demo_testset_template_import_functions.yml b/tests/data/demo_testset_template_import_functions.yml index 44e7feb7..702c1df9 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_functions: - - tests.data.custom_functions + - tests.data.debugtalk variable_binds: - user_agent: 'iOS/10.3' - device_sn: ${gen_random_string(15)} diff --git a/tests/test_context.py b/tests/test_context.py index 873d6cfe..96609cac 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -142,7 +142,7 @@ class VariableBindsUnittest(unittest.TestCase): def test_import_module_functions(self): testcase1 = { - "import_module_functions": ["tests.data.custom_functions"], + "import_module_functions": ["tests.data.debugtalk"], "variable_binds": [ {"TOKEN": "debugtalk"}, {"random": "${gen_random_string(5)}"}, @@ -199,7 +199,7 @@ class VariableBindsUnittest(unittest.TestCase): def test_get_parsed_request(self): test_runner = runner.Runner() testcase = { - "import_module_functions": ["tests.data.custom_functions"], + "import_module_functions": ["tests.data.debugtalk"], "variable_binds": [ {"TOKEN": "debugtalk"}, {"random": "${gen_random_string(5)}"},