Browse Source

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>
Doug Hellmann 1 year ago
parent
commit
7e37a20c79
4 changed files with 49 additions and 2 deletions
  1. 3
    0
      doc/source/user/index.rst
  2. 6
    2
      whereto/app.py
  3. 31
    0
      whereto/tests/test_app.py
  4. 9
    0
      whereto/tests/test_parser.py

+ 3
- 0
doc/source/user/index.rst View File

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

+ 6
- 2
whereto/app.py View File

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

+ 31
- 0
whereto/tests/test_app.py View File

@@ -173,3 +173,34 @@ class TestProcessTests(base.TestCase):
173 173
             {1, 2, 3},
174 174
         )
175 175
         self.assertEqual(expected, actual)
176
+
177
+    def test_200_test(self):
178
+        self.ruleset.add(
179
+            1,
180
+            'redirect', '301', '/path', '/new/path',
181
+        )
182
+        actual = app.process_tests(
183
+            self.ruleset,
184
+            [(1, '/another/path', '200', None)],
185
+            0,
186
+        )
187
+        expected = ([], [], [], set())
188
+        self.assertEqual(expected, actual)
189
+
190
+    def test_200_test_rule_mismatch(self):
191
+        self.ruleset.add(
192
+            1,
193
+            'redirect', '301', '/path', '/new/path',
194
+        )
195
+        actual = app.process_tests(
196
+            self.ruleset,
197
+            [(1, '/path', '200', None)],
198
+            0,
199
+        )
200
+        expected = (
201
+            [((1, '/path', '200', None), [(1, '301', '/new/path')])],
202
+            [],
203
+            [],
204
+            {1},
205
+        )
206
+        self.assertEqual(expected, actual)

+ 9
- 0
whereto/tests/test_parser.py View File

@@ -114,3 +114,12 @@ class TestParseTests(base.TestCase):
114 114
             [(2, ['/releases', '410', None])],
115 115
             self.parse(input),
116 116
         )
117
+
118
+    def test_200_rule(self):
119
+        input = u"""
120
+        /releases 200
121
+        """
122
+        self.assertEqual(
123
+            [(2, ['/releases', '200', None])],
124
+            self.parse(input),
125
+        )

Loading…
Cancel
Save