Skip to content

Commit ac8b6ee

Browse files
committed
Test redirects if there's a right-hand URL in testurl.list.
Strip off a static "https://datatracker.ietf.org" and then fetch it locally, and make sure it returns a 301 redirect to the left-hand URL. - Legacy-Id: 408
1 parent 451b203 commit ac8b6ee

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

ietf/tests.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,43 @@ def testCoverage(self):
151151
print "All the application URL patterns seem to have test cases."
152152
#print "Not all the application URLs has test cases."
153153

154+
def doRedirectsTest(self, lst):
155+
response_count = {}
156+
for codes, url, master in lst:
157+
if "skipredir" in codes or "Skipredir" in codes:
158+
print "Skipping %s" % (url)
159+
elif url and master:
160+
testurl = master.replace('https://datatracker.ietf.org','')
161+
baseurl, args = split_url(testurl)
162+
try:
163+
response = self.client.get(baseurl, args)
164+
code = str(response.status_code)
165+
if code == "301":
166+
if response['Location'] == url:
167+
print "OK %s %s -> %s" % (code, testurl, url)
168+
res = ("OK", code)
169+
else:
170+
print "Fail %s %s -> %s (wanted %s)" % (code, testurl, response['Location'], url)
171+
res = ("Fail", "wrong-reponse")
172+
else:
173+
print "Fail %s %s" % (code, testurl)
174+
res = ("Fail", code)
175+
except:
176+
res = ("Fail", "Exc")
177+
print "Exception for URL '%s'" % testurl
178+
traceback.print_exc()
179+
if not res in response_count:
180+
response_count[res] = 0
181+
response_count[res] += 1
182+
if response_count:
183+
print "Response count:"
184+
for res in response_count:
185+
ind, code = res
186+
print " %-4s %s: %s " % (ind, code, response_count[res])
187+
for res in response_count:
188+
ind, code = res
189+
self.assertEqual(ind, "OK", "Found %s cases of result code: %s" % (response_count[res], code))
190+
154191
def doUrlsTest(self, lst):
155192
response_count = {}
156193
for codes, url, master in lst:
@@ -252,6 +289,10 @@ def testUrlsList(self):
252289
print "\nTesting specified URLs:"
253290
self.doUrlsTest(self.testtuples)
254291

292+
def testRedirectsList(self):
293+
print "\nTesting specified Redirects:"
294+
self.doRedirectsTest(self.testtuples)
295+
255296
def testUrlsFallback(self):
256297
print "\nFallback: Test access to URLs which don't have an explicit test entry:"
257298
lst = []

0 commit comments

Comments
 (0)