diff --git a/ate/utils.py b/ate/utils.py index f3f00ce2..b75ddfe2 100644 --- a/ate/utils.py +++ b/ate/utils.py @@ -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!") diff --git a/test/test_utils.py b/test/test_utils.py index c648d04a..44c89c1f 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -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}