Ensure that bug number is actually a number for skip_because
This commit adds a regex check that bugs numbers passed into the
skip_because decorator are actually numbers. Previously any string
could be passed into the decorator which defeats the whole purpose of
the decorator.
Change-Id: I437fd8fab8721711530249894fae2c3c13683b4d
diff --git a/tempest/test.py b/tempest/test.py
index 38b9102..984d5ca 100644
--- a/tempest/test.py
+++ b/tempest/test.py
@@ -148,6 +148,8 @@
else:
skip = True
if "bug" in kwargs and skip is True:
+ if not kwargs['bug'].isdigit():
+ raise ValueError('bug must be a valid bug number')
msg = "Skipped until Bug: %s is resolved." % kwargs["bug"]
raise testtools.TestCase.skipException(msg)
return f(self, *func_args, **func_kwargs)
diff --git a/tempest/tests/test_decorators.py b/tempest/tests/test_decorators.py
index 7fb38ff..88920dc 100644
--- a/tempest/tests/test_decorators.py
+++ b/tempest/tests/test_decorators.py
@@ -148,21 +148,21 @@
self.assertEqual(TestFoo('test_bar').test_bar(), 0)
def test_skip_because_bug(self):
- self._test_skip_because_helper(bug='critical_bug')
+ self._test_skip_because_helper(bug='12345')
def test_skip_because_bug_and_interface_match(self):
- self._test_skip_because_helper(bug='critical_bug', interface='json')
+ self._test_skip_because_helper(bug='12346', interface='json')
def test_skip_because_bug_interface_not_match(self):
self._test_skip_because_helper(expected_to_skip=False,
- bug='critical_bug', interface='xml')
+ bug='12347', interface='xml')
def test_skip_because_bug_and_condition_true(self):
- self._test_skip_because_helper(bug='critical_bug', condition=True)
+ self._test_skip_because_helper(bug='12348', condition=True)
def test_skip_because_bug_and_condition_false(self):
self._test_skip_because_helper(expected_to_skip=False,
- bug='critical_bug', condition=False)
+ bug='12349', condition=False)
def test_skip_because_bug_condition_false_and_interface_match(self):
"""
@@ -170,7 +170,7 @@
passed.
"""
self._test_skip_because_helper(expected_to_skip=False,
- bug='critical_bug', condition=False,
+ bug='12350', condition=False,
interface='json')
def test_skip_because_bug_condition_true_and_interface_not_match(self):
@@ -178,7 +178,7 @@
Assure that only condition will be evaluated if both parameters are
passed.
"""
- self._test_skip_because_helper(bug='critical_bug', condition=True,
+ self._test_skip_because_helper(bug='12351', condition=True,
interface='xml')
def test_skip_because_bug_without_bug_never_skips(self):
@@ -188,6 +188,11 @@
self._test_skip_because_helper(expected_to_skip=False,
interface='json')
+ def test_skip_because_invalid_bug_number(self):
+ """Raise ValueError if with an invalid bug number"""
+ self.assertRaises(ValueError, self._test_skip_because_helper,
+ bug='critical_bug')
+
class TestRequiresExtDecorator(BaseDecoratorsTest):
def setUp(self):