deprecate requires

This commit is contained in:
debugtalk
2018-07-26 15:17:50 +08:00
parent a8d8b26914
commit 54e151e468
7 changed files with 0 additions and 148 deletions

View File

@@ -45,9 +45,6 @@ class Context(object):
if level == "testset":
self.testcase_parser.file_path = config_dict.get("path", None)
requires = config_dict.get('requires', [])
self.import_requires(requires)
function_binds = config_dict.get('function_binds', {})
self.bind_functions(function_binds, level)
@@ -55,12 +52,6 @@ class Context(object):
or config_dict.get('variable_binds', OrderedDict())
self.bind_variables(variables, level)
def import_requires(self, modules):
""" import required modules dynamically
"""
for module_name in modules:
globals()[module_name] = utils.get_imported_module(module_name)
def bind_functions(self, function_binds, level="testcase"):
""" Bind named functions within the context
This allows for passing in self-defined functions in testing.

View File

@@ -36,7 +36,6 @@ class Runner(object):
{
"name": "smoke testset",
"path": "tests/data/demo_testset_variables.yml",
"requires": [], # optional
"function_binds": {}, # optional
"variables": [], # optional
"request": {
@@ -49,7 +48,6 @@ class Runner(object):
testcase:
{
"name": "testcase description",
"requires": [], # optional
"function_binds": {}, # optional
"variables": [], # optional
"request": {
@@ -115,7 +113,6 @@ class Runner(object):
"name": "testcase description",
"skip": "skip this test unconditionally",
"times": 3,
"requires": [], # optional, override
"function_binds": {}, # optional, override
"variables": [], # optional, override
"request": {

View File

@@ -43,7 +43,6 @@ class TestSuite(unittest.TestSuite):
"name": "testset description",
"config": {
"name": "testset description",
"requires": [],
"function_binds": {},
"parameters": {},
"variables": [],

View File

@@ -11,20 +11,6 @@ bind_lambda_functions:
- add1: ${add_one(2)}
- sum2nums: ${add_two_nums(2, 3)}
bind_lambda_functions_with_import:
requires:
- random
- string
- hashlib
function_binds:
gen_random_string: "lambda str_len: ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(str_len))"
gen_md5: "lambda *str_args: hashlib.md5(''.join(str_args).encode('utf-8')).hexdigest()"
variables:
- TOKEN: debugtalk
- random: ${gen_random_string(5)}
- data: "{'name': 'user', 'password': '123456'}"
- authorization: ${gen_md5($TOKEN, $data, $random)}
builtin_functions:
variables:
- length: ${len(debugtalk)}

View File

@@ -1,73 +0,0 @@
- config:
name: "create user testsets."
requires:
- random
- string
- hashlib
- hmac
function_binds:
gen_random_string_lambda: "lambda str_len: ''.join(
random.choice(string.ascii_letters + string.digits) for _ in range(str_len))"
get_sign_lambda: "lambda *args: hmac.new(
'DebugTalk'.encode('ascii'),
''.join(args).encode('ascii'),
hashlib.sha1).hexdigest()"
variables:
- user_agent: 'iOS/10.3'
- device_sn: ${gen_random_string_lambda(15)}
- os_platform: 'ios'
- app_version: '2.8.6'
request:
base_url: $BASE_URL
headers:
Content-Type: application/json
device_sn: $device_sn
- test:
name: get token
request:
url: /api/get-token
method: POST
headers:
user_agent: $user_agent
device_sn: $device_sn
os_platform: $os_platform
app_version: $app_version
json:
sign: ${get_sign_lambda($user_agent, $device_sn, $os_platform, $app_version)}
extract:
- token: content.token
validate:
- {"check": "status_code", "comparator": "eq", "expect": 200}
- {"check": "content.token", "comparator": "len_eq", "expect": 16}
- test:
name: create user which does not exist
variables:
- user_name: "user1"
- user_password: "123456"
request:
url: /api/users/1000
method: POST
headers:
token: $token
json:
name: $user_name
password: $user_password
validate:
- {"check": "status_code", "comparator": "eq", "expect": 201}
- {"check": "content.success", "comparator": "eq", "expect": true}
- test:
name: create user which does not exist
request:
url: /api/users/1000
method: POST
headers:
token: $token
json:
name: "user1"
password: "123456"
validate:
- {"check": "status_code", "comparator": "eq", "expect": 500}
- {"check": "content.success", "comparator": "eq", "expect": false}

View File

@@ -120,47 +120,6 @@ class VariableBindsUnittest(ApiServerUnittest):
self.assertEqual(context_variables["smallest"], 2)
self.assertEqual(context_variables["largest"], 8)
def test_context_bind_lambda_functions_with_import(self):
testcase1 = {
"requires": ["random", "string", "hashlib"],
"function_binds": {
"gen_random_string": "lambda str_len: ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(str_len))",
"gen_md5": "lambda *str_args: hashlib.md5(''.join(str_args).encode('utf-8')).hexdigest()"
},
"variables": [
{"TOKEN": "debugtalk"},
{"random": "${gen_random_string(5)}"},
{"data": '{"name": "user", "password": "123456"}'},
{"authorization": "${gen_md5($TOKEN, $data, $random)}"}
]
}
testcase2 = self.testcases["bind_lambda_functions_with_import"]
for testcase in [testcase1, testcase2]:
requires = testcase.get('requires', [])
self.context.import_requires(requires)
function_binds = testcase.get('function_binds', {})
self.context.bind_functions(function_binds)
variables = testcase['variables']
self.context.bind_variables(variables)
context_variables = self.context.testcase_variables_mapping
self.assertIn("TOKEN", context_variables)
TOKEN = context_variables["TOKEN"]
self.assertEqual(TOKEN, "debugtalk")
self.assertIn("random", context_variables)
self.assertIsInstance(context_variables["random"], str)
self.assertEqual(len(context_variables["random"]), 5)
random = context_variables["random"]
self.assertIn("data", context_variables)
data = context_variables["data"]
self.assertIn("authorization", context_variables)
self.assertEqual(len(context_variables["authorization"]), 32)
authorization = context_variables["authorization"]
self.assertEqual(gen_md5(TOKEN, data, random), authorization)
def test_import_module_items(self):
module_items = ["tests.debugtalk"]
variables = [

View File

@@ -262,13 +262,6 @@ class TestRunner(ApiServerUnittest):
summary = runner.summary
self.assertTrue(summary["success"])
def test_run_testsets_template_lambda_functions(self):
testcase_file_path = os.path.join(
os.getcwd(), 'tests/data/demo_testset_template_lambda_functions.yml')
runner = HttpRunner().run(testcase_file_path)
summary = runner.summary
self.assertTrue(summary["success"])
def test_run_testset_layered(self):
testcase_file_path = os.path.join(
os.getcwd(), 'tests/data/demo_testset_layer.yml')