summaryrefslogtreecommitdiff
path: root/tests/regressiontests/urlpatterns_reverse/tests.py
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-08-31 11:11:20 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-08-31 11:11:20 +0000
commita63a83e5d88cd1696d1c40e89f254f69116c6800 (patch)
treedb8933fe7c50afade878ac37996c76259f266044 /tests/regressiontests/urlpatterns_reverse/tests.py
parent84ef4a9b1decce8e319359a018eef46a9556b630 (diff)
A rewrite of the reverse URL parsing: the reverse() call and the "url" template tag.
This is fully backwards compatible, but it fixes a bunch of little bugs. Thanks to SmileyChris and Ilya Semenov for some early patches in this area that were incorporated into this change. Fixed #2977, #4915, #6934, #7206. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8760 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/urlpatterns_reverse/tests.py')
-rw-r--r--tests/regressiontests/urlpatterns_reverse/tests.py93
1 files changed, 65 insertions, 28 deletions
diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
index 610c3f7bc7..fbea3cb570 100644
--- a/tests/regressiontests/urlpatterns_reverse/tests.py
+++ b/tests/regressiontests/urlpatterns_reverse/tests.py
@@ -1,40 +1,77 @@
-"Unit tests for reverse URL lookup"
+"""
+Unit tests for reverse URL lookups.
+"""
-from django.core.urlresolvers import reverse_helper, NoReverseMatch
-import re, unittest
+from django.core.urlresolvers import reverse, NoReverseMatch
+from django.test import TestCase
test_data = (
- ('^places/(\d+)/$', 'places/3/', [3], {}),
- ('^places/(\d+)/$', 'places/3/', ['3'], {}),
- ('^places/(\d+)/$', NoReverseMatch, ['a'], {}),
- ('^places/(\d+)/$', NoReverseMatch, [], {}),
- ('^places/(?P<id>\d+)/$', 'places/3/', [], {'id': 3}),
- ('^people/(?P<name>\w+)/$', 'people/adrian/', ['adrian'], {}),
- ('^people/(?P<name>\w+)/$', 'people/adrian/', [], {'name': 'adrian'}),
- ('^people/(?P<name>\w+)/$', NoReverseMatch, ['name with spaces'], {}),
- ('^people/(?P<name>\w+)/$', NoReverseMatch, [], {'name': 'name with spaces'}),
- ('^people/(?P<name>\w+)/$', NoReverseMatch, [], {}),
- ('^hardcoded/$', 'hardcoded/', [], {}),
- ('^hardcoded/$', 'hardcoded/', ['any arg'], {}),
- ('^hardcoded/$', 'hardcoded/', [], {'kwarg': 'foo'}),
- ('^hardcoded/doc\\.pdf$', 'hardcoded/doc.pdf', [], {}),
- ('^people/(?P<state>\w\w)/(?P<name>\w+)/$', 'people/il/adrian/', [], {'state': 'il', 'name': 'adrian'}),
- ('^people/(?P<state>\w\w)/(?P<name>\d)/$', NoReverseMatch, [], {'state': 'il', 'name': 'adrian'}),
- ('^people/(?P<state>\w\w)/(?P<name>\w+)/$', NoReverseMatch, [], {'state': 'il'}),
- ('^people/(?P<state>\w\w)/(?P<name>\w+)/$', NoReverseMatch, [], {'name': 'adrian'}),
- ('^people/(?P<state>\w\w)/(\w+)/$', NoReverseMatch, ['il'], {'name': 'adrian'}),
- ('^people/(?P<state>\w\w)/(\w+)/$', 'people/il/adrian/', ['adrian'], {'state': 'il'}),
+ ('places', '/places/3/', [3], {}),
+ ('places', '/places/3/', ['3'], {}),
+ ('places', NoReverseMatch, ['a'], {}),
+ ('places', NoReverseMatch, [], {}),
+ ('places?', '/place/', [], {}),
+ ('places+', '/places/', [], {}),
+ ('places*', '/place/', [], {}),
+ ('places2?', '/', [], {}),
+ ('places2+', '/places/', [], {}),
+ ('places2*', '/', [], {}),
+ ('places3', '/places/4/', [4], {}),
+ ('places3', '/places/harlem/', ['harlem'], {}),
+ ('places3', NoReverseMatch, ['harlem64'], {}),
+ ('places4', '/places/3/', [], {'id': 3}),
+ ('people', NoReverseMatch, [], {}),
+ ('people', '/people/adrian/', ['adrian'], {}),
+ ('people', '/people/adrian/', [], {'name': 'adrian'}),
+ ('people', NoReverseMatch, ['name with spaces'], {}),
+ ('people', NoReverseMatch, [], {'name': 'name with spaces'}),
+ ('people2', '/people/name/', [], {}),
+ ('people2a', '/people/name/fred/', ['fred'], {}),
+ ('optional', '/optional/fred/', [], {'name': 'fred'}),
+ ('optional', '/optional/fred/', ['fred'], {}),
+ ('hardcoded', '/hardcoded/', [], {}),
+ ('hardcoded2', '/hardcoded/doc.pdf', [], {}),
+ ('people3', '/people/il/adrian/', [], {'state': 'il', 'name': 'adrian'}),
+ ('people3', NoReverseMatch, [], {'state': 'il'}),
+ ('people3', NoReverseMatch, [], {'name': 'adrian'}),
+ ('people4', NoReverseMatch, [], {'state': 'il', 'name': 'adrian'}),
+ ('people6', '/people/il/test/adrian/', ['il/test', 'adrian'], {}),
+ ('people6', '/people//adrian/', ['adrian'], {}),
+ ('range', '/character_set/a/', [], {}),
+ ('range2', '/character_set/x/', [], {}),
+ ('price', '/price/$10/', ['10'], {}),
+ ('price2', '/price/$10/', ['10'], {}),
+ ('price3', '/price/$10/', ['10'], {}),
+ ('product', '/product/chocolate+($2.00)/', [], {'price': '2.00', 'product': 'chocolate'}),
+ ('headlines', '/headlines/2007.5.21/', [], dict(year=2007, month=5, day=21)),
+ ('windows', r'/windows_path/C:%5CDocuments%20and%20Settings%5Cspam/', [], dict(drive_name='C', path=r'Documents and Settings\spam')),
+ ('special', r'/special_chars/+%5C$*/', [r'+\$*'], {}),
+ ('special', NoReverseMatch, [''], {}),
+ ('mixed', '/john/0/', [], {'name': 'john'}),
+ ('repeats', '/repeats/a/', [], {}),
+ ('repeats2', '/repeats/aa/', [], {}),
+ ('insensitive', '/CaseInsensitive/fred', ['fred'], {}),
+ ('test', '/test/1', [], {}),
+ ('test2', '/test/2', [], {}),
+ ('inner-nothing', '/outer/42/', [], {'outer': '42'}),
+ ('inner-nothing', '/outer/42/', ['42'], {}),
+ ('inner-nothing', NoReverseMatch, ['foo'], {}),
+ ('inner-extra', '/outer/42/extra/inner/', [], {'extra': 'inner', 'outer': '42'}),
+ ('inner-extra', '/outer/42/extra/inner/', ['42', 'inner'], {}),
+ ('inner-extra', NoReverseMatch, ['fred', 'inner'], {}),
+ ('disjunction', NoReverseMatch, ['foo'], {}),
+ ('inner-disjunction', NoReverseMatch, ['10', '11'], {}),
)
-class URLPatternReverse(unittest.TestCase):
+class URLPatternReverse(TestCase):
+ urls = 'regressiontests.urlpatterns_reverse.urls'
+
def test_urlpattern_reverse(self):
- for regex, expected, args, kwargs in test_data:
+ for name, expected, args, kwargs in test_data:
try:
- got = reverse_helper(re.compile(regex), *args, **kwargs)
+ got = reverse(name, args=args, kwargs=kwargs)
except NoReverseMatch, e:
self.assertEqual(expected, NoReverseMatch)
else:
self.assertEquals(got, expected)
-if __name__ == "__main__":
- run_tests(1)