mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-03 14:59:38 +08:00
Merge branch 'dev' of https://github.com/httprunner/HttpRunner into dev
This commit is contained in:
@@ -30,6 +30,7 @@ def gen_random_string(str_len):
|
||||
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
|
||||
"""
|
||||
@@ -38,12 +39,19 @@ def get_timestamp(str_len=13):
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def sleep(n_secs):
|
||||
""" sleep n seconds
|
||||
"""
|
||||
time.sleep(n_secs)
|
||||
|
||||
|
||||
###############################################################################
|
||||
## upload files with requests-toolbelt
|
||||
# e.g.
|
||||
@@ -66,6 +74,7 @@ def get_current_date(fmt="%Y-%m-%d"):
|
||||
def multipart_encoder(**kwargs):
|
||||
""" initialize MultipartEncoder with uploading fields.
|
||||
"""
|
||||
|
||||
def get_filetype(file_path):
|
||||
file_type = filetype.guess(file_path)
|
||||
if file_type:
|
||||
@@ -108,52 +117,66 @@ def multipart_content_type(multipart_encoder):
|
||||
def equals(check_value, expect_value):
|
||||
assert check_value == expect_value
|
||||
|
||||
|
||||
def less_than(check_value, expect_value):
|
||||
assert check_value < expect_value
|
||||
|
||||
|
||||
def less_than_or_equals(check_value, expect_value):
|
||||
assert check_value <= expect_value
|
||||
|
||||
|
||||
def greater_than(check_value, expect_value):
|
||||
assert check_value > expect_value
|
||||
|
||||
|
||||
def greater_than_or_equals(check_value, expect_value):
|
||||
assert check_value >= expect_value
|
||||
|
||||
|
||||
def not_equals(check_value, expect_value):
|
||||
assert check_value != expect_value
|
||||
|
||||
|
||||
def string_equals(check_value, expect_value):
|
||||
assert builtin_str(check_value) == builtin_str(expect_value)
|
||||
|
||||
|
||||
def length_equals(check_value, expect_value):
|
||||
assert isinstance(expect_value, integer_types)
|
||||
assert len(check_value) == expect_value
|
||||
|
||||
|
||||
def length_greater_than(check_value, expect_value):
|
||||
assert isinstance(expect_value, integer_types)
|
||||
assert len(check_value) > expect_value
|
||||
|
||||
|
||||
def length_greater_than_or_equals(check_value, expect_value):
|
||||
assert isinstance(expect_value, integer_types)
|
||||
assert len(check_value) >= expect_value
|
||||
|
||||
|
||||
def length_less_than(check_value, expect_value):
|
||||
assert isinstance(expect_value, integer_types)
|
||||
assert len(check_value) < expect_value
|
||||
|
||||
|
||||
def length_less_than_or_equals(check_value, expect_value):
|
||||
assert isinstance(expect_value, integer_types)
|
||||
assert len(check_value) <= expect_value
|
||||
|
||||
|
||||
def contains(check_value, expect_value):
|
||||
assert isinstance(check_value, (list, tuple, dict, basestring))
|
||||
assert expect_value in check_value
|
||||
|
||||
|
||||
def contained_by(check_value, expect_value):
|
||||
assert isinstance(expect_value, (list, tuple, dict, basestring))
|
||||
assert check_value in expect_value
|
||||
|
||||
|
||||
def type_match(check_value, expect_value):
|
||||
def get_type(name):
|
||||
if isinstance(name, type):
|
||||
@@ -168,20 +191,16 @@ def type_match(check_value, expect_value):
|
||||
|
||||
assert isinstance(check_value, get_type(expect_value))
|
||||
|
||||
|
||||
def regex_match(check_value, expect_value):
|
||||
assert isinstance(expect_value, basestring)
|
||||
assert isinstance(check_value, basestring)
|
||||
assert re.match(expect_value, check_value)
|
||||
|
||||
|
||||
def startswith(check_value, expect_value):
|
||||
assert builtin_str(check_value).startswith(builtin_str(expect_value))
|
||||
|
||||
|
||||
def endswith(check_value, expect_value):
|
||||
assert builtin_str(check_value).endswith(builtin_str(expect_value))
|
||||
|
||||
""" built-in hooks
|
||||
"""
|
||||
def sleep_N_secs(n_secs):
|
||||
""" sleep n seconds
|
||||
"""
|
||||
time.sleep(n_secs)
|
||||
|
||||
Reference in New Issue
Block a user