Skip to content

Commit b7c816c

Browse files
committed
Added test functionality to extract all URLs in the apps and access those that
doesn't seem to take parameters. - Legacy-Id: 230
1 parent 745ae10 commit b7c816c

2 files changed

Lines changed: 51 additions & 14 deletions

File tree

ietf/tests.py

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import os
22
import re
3+
import traceback
34

45
import django.test.simple
56
from django.test import TestCase
67
import ietf.settings
78
import ietf.urls
89

910
def run_tests(module_list, verbosity=1, extra_tests=[]):
10-
module_list.append(ietf.tests)
11+
module_list.append(ietf.urls)
12+
# If we append 'ietf.tests', we get it twice, first as itself, then
13+
# during the search for a 'tests' module ...
1114
return django.test.simple.run_tests(module_list, verbosity, extra_tests)
1215

1316
def get_patterns(module):
@@ -36,6 +39,7 @@ def setUp(self):
3639
self.client = Client()
3740

3841
# find test urls
42+
self.testtuples = []
3943
self.testurls = []
4044
for root, dirs, files in os.walk(ietf.settings.BASE_DIR):
4145
if "testurl.list" in files:
@@ -52,14 +56,15 @@ def setUp(self):
5256
code, testurl, goodurl = urlspec
5357
else:
5458
raise ValueError("Expected 'HTTP_CODE TESTURL [GOODURL]' in %s line, found '%s'." % (filename, line))
55-
self.testurls += [ (code, testurl, goodurl) ]
59+
self.testtuples += [ (code, testurl, goodurl) ]
60+
self.testurls += [ testurl ]
5661
#print "(%s, %s, %s)" % (code, testurl, goodurl)
57-
#print self.testurls
62+
#print self.testtuples
5863

5964
def testCoverage(self):
6065
covered = []
6166
patterns = get_patterns(ietf.urls)
62-
for code, testurl, goodurl in self.testurls:
67+
for code, testurl, goodurl in self.testtuples:
6368
for pattern in patterns:
6469
if re.match(pattern, testurl[1:]):
6570
covered.append(pattern)
@@ -68,15 +73,46 @@ def testCoverage(self):
6873
#self.assertEqual(set(patterns), set(covered), "Not all the
6974
#application URLs has test cases. The missing are: %s" % (list(set(patterns) - set(covered))))
7075
if not set(patterns) == set(covered):
71-
print "Not all the application URLs has test cases. The missing are: %s" % ("\n ".join(list(set(patterns) - set(covered))))
76+
#print "Not all the application URLs has test cases. The missing are: \n %s" % ("\n ".join(list(set(patterns) - set(covered))))
77+
print "Not all the application URLs has test cases."
7278

7379
def testUrls(self):
74-
for code, testurl, goodurl in self.testurls:
75-
try:
76-
response = self.client.get(testurl)
77-
print "Got code %s for %s" % (response.status_code, testurl)
78-
#self.assertEqual(response.status_code, code, "Unexpected response code (%s) for URL '%s'" % (response.status_code, testurl))
79-
# TODO: Add comparison with goodurl
80-
except:
81-
print "Got exception for URL '%s'" % testurl
82-
raise
80+
for code, testurl, goodurl in self.testtuples:
81+
if code in ["skip", "Skip"]:
82+
print "Skipping %s" % (testurl)
83+
else:
84+
try:
85+
response = self.client.get(testurl)
86+
print "Got code %s for %s" % (response.status_code, testurl)
87+
#self.assertEqual(response.status_code, code, "Unexpected response code (%s) for URL '%s'" % (response.status_code, testurl))
88+
# TODO: Add comparison with goodurl
89+
except:
90+
print "Exception for URL '%s'" % testurl
91+
traceback.print_exc()
92+
93+
def testUrlsFallback(self):
94+
patterns = get_patterns(ietf.urls)
95+
response_count = {}
96+
for pattern in patterns:
97+
if pattern.startswith("^") and pattern.endswith("$"):
98+
url = "/"+pattern[1:-1]
99+
# if there is no variable parts in the url, test it
100+
if re.search("^[-a-z0-9./_]*$", url) and not url in self.testurls and not url.startswith("/admin/"):
101+
try:
102+
response = self.client.get(url)
103+
if not response.status_code in response_count:
104+
response_count[response.status_code] = 0
105+
response_count[response.status_code] += 1
106+
if response.status_code != 200:
107+
print "Bad code %s for %s" % (response.status_code, url)
108+
except:
109+
if not "Exc" in response_count:
110+
response_count["Exc"] = 0
111+
response_count["Exc"] += 1
112+
print "Exception for URL '%s'" % url
113+
traceback.print_exc()
114+
else:
115+
print "Skipping %s" % (url)
116+
print "testUrlsFallback() response count:\n code count"
117+
for code in response_count:
118+
print " %s: %s " % (code, response_count[code])

ietf/testurl.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
200 /ipr/new-generic/
3636
200 /ipr/new-specific/
3737
200 /ipr/new-third-party/
38+
skip /my/
3839
#200 /liaisons/
3940
#200 /liaisons/329/
4041
#200 /mailing-lists/area-lists/

0 commit comments

Comments
 (0)