bugfix: match_expected should raise ParamsError when comparator is not supported

This commit is contained in:
debugtalk
2017-06-29 17:27:23 +08:00
parent 63c9d209e9
commit c9de871485
2 changed files with 6 additions and 1 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)
else:
raise ParamsError("comparator not supported!")
return True
except AssertionError:

View File

@@ -197,4 +197,7 @@ class TestUtils(ApiServerUnittest):
self.assertTrue(utils.match_expected("3ab", "123abc456", "contained_by"))
self.assertTrue(utils.match_expected("123abc456", "^123.*456$", "regex"))
self.assertFalse(utils.match_expected("123abc456", "^12b.*456$", "regex"))
self.assertFalse(utils.match_expected("123abc456", "^12b.*456$", "regex"))
with self.assertRaises(exception.ParamsError):
utils.match_expected(1, 2, "not_supported_comparator")