Don't list URLs which have explicit tests as Skipped during the fallback URL test.

- Legacy-Id: 307
This commit is contained in:
Henrik Levkowetz 2007-06-11 09:36:45 +00:00
parent 7f512b4889
commit deecbc9da3

View file

@ -84,6 +84,9 @@ class UrlTestCase(TestCase):
if "testurls.list" in files: if "testurls.list" in files:
self.testtuples += read_testurls(root+"/testurls.list") self.testtuples += read_testurls(root+"/testurls.list")
self.testurls = [ tuple[1] for tuple in self.testtuples ] self.testurls = [ tuple[1] for tuple in self.testtuples ]
# extract application urls:
self.patterns = get_patterns(ietf.urls)
# Use the default database for the url tests, instead of the test database # Use the default database for the url tests, instead of the test database
self.testdb = settings.DATABASE_NAME self.testdb = settings.DATABASE_NAME
connection.close() connection.close()
@ -98,16 +101,15 @@ class UrlTestCase(TestCase):
def testCoverage(self): def testCoverage(self):
covered = [] covered = []
patterns = get_patterns(ietf.urls)
for codes, testurl, goodurl in self.testtuples: for codes, testurl, goodurl in self.testtuples:
for pattern in patterns: for pattern in self.patterns:
if re.match(pattern, testurl[1:]): if re.match(pattern, testurl[1:]):
covered.append(pattern) covered.append(pattern)
# We should have at least one test case for each url pattern declared # We should have at least one test case for each url pattern declared
# in our Django application: # in our Django application:
#self.assertEqual(set(patterns), set(covered), "Not all the #self.assertEqual(set(patterns), set(covered), "Not all the
#application URLs has test cases. The missing are: %s" % (list(set(patterns) - set(covered)))) #application URLs has test cases. The missing are: %s" % (list(set(patterns) - set(covered))))
if not set(patterns) == set(covered): if not set(self.patterns) == set(covered):
#print "Not all the application URLs has test cases. The missing are: \n %s" % ("\n ".join(list(set(patterns) - set(covered)))) #print "Not all the application URLs has test cases. The missing are: \n %s" % ("\n ".join(list(set(patterns) - set(covered))))
print "Not all the application URLs has test cases." print "Not all the application URLs has test cases."
@ -183,18 +185,17 @@ class UrlTestCase(TestCase):
self.doUrlsTest(self.testtuples) self.doUrlsTest(self.testtuples)
def testUrlsFallback(self): def testUrlsFallback(self):
patterns = get_patterns(ietf.urls) print "\nFallback: Test access to URLs which don't have an explicit test entry:"
lst = [] lst = []
for pattern in patterns: for pattern in self.patterns:
if pattern.startswith("^") and pattern.endswith("$"): if pattern.startswith("^") and pattern.endswith("$"):
url = "/"+pattern[1:-1] url = "/"+pattern[1:-1]
# if there is no variable parts in the url, test it # if there is no variable parts in the url, test it
if re.search("^[-a-z0-9./_]*$", url) and not url in self.testurls and not url.startswith("/admin/"): if re.search("^[-a-z0-9./_]*$", url) and not url in self.testurls and not url.startswith("/admin/"):
lst.append((["200"], url, None)) lst.append((["200"], url, None))
else: else:
lst.append((["skip"], url, None)) print "Test exists for %s" % (url)
else: else:
lst.append((["Skip"], url, None)) lst.append((["Skip"], url, None))
print "\nTesting non-listed URLs:"
self.doUrlsTest(lst) self.doUrlsTest(lst)