mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
#36: add debugtalk.py local per-directory plugins
This commit is contained in:
@@ -1 +1 @@
|
||||
__version__ = '0.5.3'
|
||||
__version__ = '0.5.4'
|
||||
@@ -46,6 +46,9 @@ class Context(object):
|
||||
self.testcase_parser.bind_functions(self.testcase_functions_config)
|
||||
self.testcase_parser.bind_variables(self.testcase_variables_mapping)
|
||||
|
||||
if level == "testset":
|
||||
self.import_module_functions(["ate.debugtalk"], "testset")
|
||||
|
||||
def import_requires(self, modules):
|
||||
""" import required modules dynamicly
|
||||
"""
|
||||
|
||||
26
ate/debugtalk.py
Normal file
26
ate/debugtalk.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import datetime
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
|
||||
from ate.exception import ParamsError
|
||||
|
||||
|
||||
def gen_random_string(str_len):
|
||||
""" generate random string with specified length
|
||||
"""
|
||||
return ''.join(
|
||||
random.choice(string.ascii_letters + string.digits) for _ in range(str_len))
|
||||
|
||||
def get_timestamp(str_len=13):
|
||||
""" get timestamp string, length can only between 0 and 16
|
||||
"""
|
||||
if isinstance(str_len, int) and 0 < str_len < 17:
|
||||
return str(time.time()).replace(".", "")[:str_len]
|
||||
|
||||
raise ParamsError("timestamp length can only between 0 and 16.")
|
||||
|
||||
def get_current_date(fmt="%Y-%m-%d"):
|
||||
""" get current date, default format is %Y-%m-%d
|
||||
"""
|
||||
return datetime.datetime.now().strftime(fmt)
|
||||
@@ -65,6 +65,3 @@ def gen_urlencode_str(**kargs):
|
||||
urlencoded_str += "&"
|
||||
|
||||
return urlencoded_str.strip("&")
|
||||
|
||||
def get_timestamp():
|
||||
return int(time.time() * 1000)
|
||||
|
||||
@@ -13,6 +13,20 @@ class VariableBindsUnittest(unittest.TestCase):
|
||||
testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo_binds.yml')
|
||||
self.testcases = utils.load_testcases(testcase_file_path)
|
||||
|
||||
def test_context_init_functions(self):
|
||||
self.assertIn("get_timestamp", self.context.testset_functions_config)
|
||||
self.assertIn("gen_random_string", self.context.testset_functions_config)
|
||||
|
||||
variable_binds = [
|
||||
{"random": "${gen_random_string(5)}"},
|
||||
{"timestamp10": "${get_timestamp(10)}"}
|
||||
]
|
||||
self.context.bind_variables(variable_binds)
|
||||
context_variables = self.context.get_testcase_variables_mapping()
|
||||
|
||||
self.assertEqual(len(context_variables["random"]), 5)
|
||||
self.assertEqual(len(context_variables["timestamp10"]), 10)
|
||||
|
||||
def test_context_bind_testset_variables(self):
|
||||
# testcase in JSON format
|
||||
testcase1 = {
|
||||
|
||||
Reference in New Issue
Block a user