add support for testing paths are not redirected

Add support for tests that ensure no existing rule redirects by having
the test assume a response code of 200.

Change-Id: I2aa1ada7e85c5e8066fdae634a4cf38b64ec821b
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2017-10-11 14:54:12 -04:00
parent 7200a0657f
commit 7e37a20c79
4 changed files with 49 additions and 2 deletions

View File

@ -37,6 +37,9 @@ parts: the input path, the expected HTTP response code, and the
/no/rule 301 /should/fail
/nova/latest/man/nova-cert.html 410
# verify that this path is not redirected
/pike/index.html 200
The output from ``whereto`` includes a report of any tests that do not
match, including if no rules match and if multiple rules match. For
example:

View File

@ -78,8 +78,12 @@ def process_tests(ruleset, tests, max_hops):
for test in tests:
matches = _find_matches(ruleset, test)
if not matches:
# No rules matched at all.
mismatches.append((test, []))
# No rules matched at all. If the test was expecting
# that don't record it as a failure.
if test[2] == '200':
used.add(test[0])
else:
mismatches.append((test, []))
else:
code, expected = test[-2:]
if (code, expected) != matches[0][1:]:

View File

@ -173,3 +173,34 @@ class TestProcessTests(base.TestCase):
{1, 2, 3},
)
self.assertEqual(expected, actual)
def test_200_test(self):
self.ruleset.add(
1,
'redirect', '301', '/path', '/new/path',
)
actual = app.process_tests(
self.ruleset,
[(1, '/another/path', '200', None)],
0,
)
expected = ([], [], [], set())
self.assertEqual(expected, actual)
def test_200_test_rule_mismatch(self):
self.ruleset.add(
1,
'redirect', '301', '/path', '/new/path',
)
actual = app.process_tests(
self.ruleset,
[(1, '/path', '200', None)],
0,
)
expected = (
[((1, '/path', '200', None), [(1, '301', '/new/path')])],
[],
[],
{1},
)
self.assertEqual(expected, actual)

View File

@ -114,3 +114,12 @@ class TestParseTests(base.TestCase):
[(2, ['/releases', '410', None])],
self.parse(input),
)
def test_200_rule(self):
input = u"""
/releases 200
"""
self.assertEqual(
[(2, ['/releases', '200', None])],
self.parse(input),
)