Skip to content

Commit 8ff20e3

Browse files
committed
Expanded the test code which finds urlpatterns to extract all URLs
specified in the various Django apps of the site. Also fixed the documentation of the TemplatedForm factory to be more correct. - Legacy-Id: 227
1 parent 4e25407 commit 8ff20e3

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

ietf/tests.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,33 @@
33

44
import django.test.simple
55
from django.test import TestCase
6-
from ietf.urls import urlpatterns
76
import ietf.settings
7+
import ietf.urls
88

99
def run_tests(module_list, verbosity=1, extra_tests=[]):
1010
module_list.append(ietf.tests)
1111
return django.test.simple.run_tests(module_list, verbosity, extra_tests)
1212

13+
def get_patterns(module):
14+
all = []
15+
try:
16+
patterns = module.urlpatterns
17+
except AttributeError:
18+
patterns = []
19+
for item in patterns:
20+
try:
21+
subpatterns = get_patterns(item.urlconf_module)
22+
except:
23+
subpatterns = [""]
24+
for sub in subpatterns:
25+
if not sub:
26+
all.append(item.regex.pattern)
27+
elif sub.startswith("^"):
28+
all.append(item.regex.pattern + sub[1:])
29+
else:
30+
all.append(item.regex.pattern + ".*" + sub)
31+
return all
32+
1333
class UrlTestCase(TestCase):
1434
def setUp(self):
1535
from django.test.client import Client
@@ -38,7 +58,7 @@ def setUp(self):
3858

3959
def testCoverage(self):
4060
covered = []
41-
patterns = [pattern.regex.pattern for pattern in urlpatterns]
61+
patterns = get_patterns(ietf.urls)
4262
for code, testurl, goodurl in self.testurls:
4363
for pattern in patterns:
4464
if re.match(pattern, testurl[1:]):
@@ -48,7 +68,7 @@ def testCoverage(self):
4868
#self.assertEqual(set(patterns), set(covered), "Not all the
4969
#application URLs has test cases. The missing are: %s" % (list(set(patterns) - set(covered))))
5070
if not set(patterns) == set(covered):
51-
print "Not all the application URLs has test cases. The missing are: %s" % (list(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))))
5272

5373
def testUrls(self):
5474
for code, testurl, goodurl in self.testurls:

ietf/utils/templated_form.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@
33
def makeTemplatedForm(template=None):
44
"""Create a form class which formats its fields using the provided template
55
6-
The template is provided with a dictionary containing the following keys, value
6+
The template is provided with a dictionary containing the following key-value
77
pairs:
88
99
"label": field label, if any,
1010
"errors": list of errors, if any,
11-
"field": widget rendering for an unbound form / field value for a bound form,
11+
"text": widget rendering for an unbound form / field value for a bound form,
1212
"help_text": field help text, if any
13-
1413
"""
1514
from django.template import loader
1615
import django.newforms as forms
1716

1817
class TemplatedForm(forms.BaseForm):
1918
_template = template
2019
def __getitem__(self, name):
21-
"Returns a BoundField with the given name."
20+
"Returns a rendered field with the given name."
2221
#syslog.syslog("FormattingForm.__getitem__(%s)" % (name, ))
2322
try:
2423
field = self.fields[name]

0 commit comments

Comments
 (0)