mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 11:29:48 +08:00
add match method: startswith
This commit is contained in:
@@ -288,6 +288,8 @@ def match_expected(value, expected, comparator="eq"):
|
||||
assert re.match(expected, value)
|
||||
elif comparator in ["str_len", "string_length"]:
|
||||
assert len(value) == int(expected)
|
||||
elif comparator in ["startswith"]:
|
||||
assert str(value).startswith(str(expected))
|
||||
else:
|
||||
raise ParamsError("comparator not supported!")
|
||||
|
||||
|
||||
@@ -247,7 +247,7 @@ class TestUtils(ApiServerUnittest):
|
||||
result = utils.query_json(json_content, query)
|
||||
self.assertEqual(result, "Leo")
|
||||
|
||||
def test_compare(self):
|
||||
def test_match_expected(self):
|
||||
self.assertTrue(utils.match_expected(1, 1, "eq"))
|
||||
self.assertTrue(utils.match_expected("abc", "abc", "eq"))
|
||||
self.assertTrue(utils.match_expected("abc", "abc"))
|
||||
@@ -280,6 +280,10 @@ class TestUtils(ApiServerUnittest):
|
||||
self.assertTrue(utils.match_expected("2017-06-29 17:29:58", 19, "str_len"))
|
||||
self.assertTrue(utils.match_expected("2017-06-29 17:29:58", "19", "str_len"))
|
||||
|
||||
self.assertTrue(utils.match_expected("abc123", "ab", "startswith"))
|
||||
self.assertTrue(utils.match_expected("123abc", 12, "startswith"))
|
||||
self.assertTrue(utils.match_expected(12345, 123, "startswith"))
|
||||
|
||||
def test_deep_update_dict(self):
|
||||
origin_dict = {'a': 1, 'b': {'c': 3, 'd': 4}, 'f': 6}
|
||||
override_dict = {'a': 2, 'b': {'c': 33, 'e': 5}, 'g': 7}
|
||||
|
||||
Reference in New Issue
Block a user