From 7e37a20c79ff02615fbee1acc9d449195b36001a Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Wed, 11 Oct 2017 14:54:12 -0400 Subject: [PATCH] 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 --- doc/source/user/index.rst | 3 +++ whereto/app.py | 8 ++++++-- whereto/tests/test_app.py | 31 +++++++++++++++++++++++++++++++ whereto/tests/test_parser.py | 9 +++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/doc/source/user/index.rst b/doc/source/user/index.rst index 35a2803..322011f 100644 --- a/doc/source/user/index.rst +++ b/doc/source/user/index.rst @@ -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: diff --git a/whereto/app.py b/whereto/app.py index 8b3e397..c5fea5e 100644 --- a/whereto/app.py +++ b/whereto/app.py @@ -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:]: diff --git a/whereto/tests/test_app.py b/whereto/tests/test_app.py index f95fb34..b888760 100644 --- a/whereto/tests/test_app.py +++ b/whereto/tests/test_app.py @@ -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) diff --git a/whereto/tests/test_parser.py b/whereto/tests/test_parser.py index 9cfe000..3f86fbc 100644 --- a/whereto/tests/test_parser.py +++ b/whereto/tests/test_parser.py @@ -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), + )