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 /no/rule 301 /should/fail
/nova/latest/man/nova-cert.html 410 /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 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 match, including if no rules match and if multiple rules match. For
example: example:

View File

@ -78,7 +78,11 @@ def process_tests(ruleset, tests, max_hops):
for test in tests: for test in tests:
matches = _find_matches(ruleset, test) matches = _find_matches(ruleset, test)
if not matches: if not matches:
# No rules matched at all. # 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, [])) mismatches.append((test, []))
else: else:
code, expected = test[-2:] code, expected = test[-2:]

View File

@ -173,3 +173,34 @@ class TestProcessTests(base.TestCase):
{1, 2, 3}, {1, 2, 3},
) )
self.assertEqual(expected, actual) 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])], [(2, ['/releases', '410', None])],
self.parse(input), self.parse(input),
) )
def test_200_rule(self):
input = u"""
/releases 200
"""
self.assertEqual(
[(2, ['/releases', '200', None])],
self.parse(input),
)