From ac8b6ee6afd4b91e92eeaad4c8f8da150170236e Mon Sep 17 00:00:00 2001 From: Bill Fenner <fenner@fenron.net> Date: Fri, 15 Jun 2007 16:47:40 +0000 Subject: [PATCH] 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 --- ietf/tests.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/ietf/tests.py b/ietf/tests.py index df669f4b6..1142467fe 100644 --- a/ietf/tests.py +++ b/ietf/tests.py @@ -151,6 +151,43 @@ class UrlTestCase(TestCase): print "All the application URL patterns seem to have test cases." #print "Not all the application URLs has test cases." + def doRedirectsTest(self, lst): + response_count = {} + for codes, url, master in lst: + if "skipredir" in codes or "Skipredir" in codes: + print "Skipping %s" % (url) + elif url and master: + testurl = master.replace('https://datatracker.ietf.org','') + baseurl, args = split_url(testurl) + try: + response = self.client.get(baseurl, args) + code = str(response.status_code) + if code == "301": + if response['Location'] == url: + print "OK %s %s -> %s" % (code, testurl, url) + res = ("OK", code) + else: + print "Fail %s %s -> %s (wanted %s)" % (code, testurl, response['Location'], url) + res = ("Fail", "wrong-reponse") + else: + print "Fail %s %s" % (code, testurl) + res = ("Fail", code) + except: + res = ("Fail", "Exc") + print "Exception for URL '%s'" % testurl + traceback.print_exc() + if not res in response_count: + response_count[res] = 0 + response_count[res] += 1 + if response_count: + print "Response count:" + for res in response_count: + ind, code = res + print " %-4s %s: %s " % (ind, code, response_count[res]) + for res in response_count: + ind, code = res + self.assertEqual(ind, "OK", "Found %s cases of result code: %s" % (response_count[res], code)) + def doUrlsTest(self, lst): response_count = {} for codes, url, master in lst: @@ -252,6 +289,10 @@ class UrlTestCase(TestCase): print "\nTesting specified URLs:" self.doUrlsTest(self.testtuples) + def testRedirectsList(self): + print "\nTesting specified Redirects:" + self.doRedirectsTest(self.testtuples) + def testUrlsFallback(self): print "\nFallback: Test access to URLs which don't have an explicit test entry:" lst = []