match_expected: add comparator str_len/string_length

This commit is contained in:
debugtalk
2017-06-29 17:32:49 +08:00
parent c9de871485
commit abcba302ae
2 changed files with 5 additions and 0 deletions

View File

@@ -210,6 +210,8 @@ def match_expected(value, expected, comparator="eq"):
assert value in expected
elif comparator in ["regex"]:
assert re.match(expected, value)
elif comparator in ["str_len", "string_length"]:
assert len(value) == int(expected)
else:
raise ParamsError("comparator not supported!")

View File

@@ -201,3 +201,6 @@ class TestUtils(ApiServerUnittest):
with self.assertRaises(exception.ParamsError):
utils.match_expected(1, 2, "not_supported_comparator")
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"))