add match method: startswith

This commit is contained in:
debugtalk
2017-07-05 15:14:10 +08:00
parent 7fbacea3c2
commit b7659b2ad4
2 changed files with 7 additions and 1 deletions

View File

@@ -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!")

View File

@@ -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}