~ubuntu-branches/ubuntu/jaunty/python-django/jaunty-backports

« back to all changes in this revision

Viewing changes to tests/regressiontests/urlpatterns_reverse/tests.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2008-11-15 19:15:33 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20081115191533-xbt1ut2xf4fvwtvc
Tags: 1.0.1-0ubuntu1
* New upstream release:
  - Bug fixes.

* The tests/ sub-directory appaers to have been dropped upstream, so pull
  our patch to workaround the tests and modify the rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
2
 
Unit tests for reverse URL lookups.
3
 
"""
4
 
 
5
 
from django.core.urlresolvers import reverse, NoReverseMatch
6
 
from django.test import TestCase
7
 
 
8
 
test_data = (
9
 
    ('places', '/places/3/', [3], {}),
10
 
    ('places', '/places/3/', ['3'], {}),
11
 
    ('places', NoReverseMatch, ['a'], {}),
12
 
    ('places', NoReverseMatch, [], {}),
13
 
    ('places?', '/place/', [], {}),
14
 
    ('places+', '/places/', [], {}),
15
 
    ('places*', '/place/', [], {}),
16
 
    ('places2?', '/', [], {}),
17
 
    ('places2+', '/places/', [], {}),
18
 
    ('places2*', '/', [], {}),
19
 
    ('places3', '/places/4/', [4], {}),
20
 
    ('places3', '/places/harlem/', ['harlem'], {}),
21
 
    ('places3', NoReverseMatch, ['harlem64'], {}),
22
 
    ('places4', '/places/3/', [], {'id': 3}),
23
 
    ('people', NoReverseMatch, [], {}),
24
 
    ('people', '/people/adrian/', ['adrian'], {}),
25
 
    ('people', '/people/adrian/', [], {'name': 'adrian'}),
26
 
    ('people', NoReverseMatch, ['name with spaces'], {}),
27
 
    ('people', NoReverseMatch, [], {'name': 'name with spaces'}),
28
 
    ('people2', '/people/name/', [], {}),
29
 
    ('people2a', '/people/name/fred/', ['fred'], {}),
30
 
    ('optional', '/optional/fred/', [], {'name': 'fred'}),
31
 
    ('optional', '/optional/fred/', ['fred'], {}),
32
 
    ('hardcoded', '/hardcoded/', [], {}),
33
 
    ('hardcoded2', '/hardcoded/doc.pdf', [], {}),
34
 
    ('people3', '/people/il/adrian/', [], {'state': 'il', 'name': 'adrian'}),
35
 
    ('people3', NoReverseMatch, [], {'state': 'il'}),
36
 
    ('people3', NoReverseMatch, [], {'name': 'adrian'}),
37
 
    ('people4', NoReverseMatch, [], {'state': 'il', 'name': 'adrian'}),
38
 
    ('people6', '/people/il/test/adrian/', ['il/test', 'adrian'], {}),
39
 
    ('people6', '/people//adrian/', ['adrian'], {}),
40
 
    ('range', '/character_set/a/', [], {}),
41
 
    ('range2', '/character_set/x/', [], {}),
42
 
    ('price', '/price/$10/', ['10'], {}),
43
 
    ('price2', '/price/$10/', ['10'], {}),
44
 
    ('price3', '/price/$10/', ['10'], {}),
45
 
    ('product', '/product/chocolate+($2.00)/', [], {'price': '2.00', 'product': 'chocolate'}),
46
 
    ('headlines', '/headlines/2007.5.21/', [], dict(year=2007, month=5, day=21)),
47
 
    ('windows', r'/windows_path/C:%5CDocuments%20and%20Settings%5Cspam/', [], dict(drive_name='C', path=r'Documents and Settings\spam')),
48
 
    ('special', r'/special_chars/+%5C$*/', [r'+\$*'], {}),
49
 
    ('special', NoReverseMatch, [''], {}),
50
 
    ('mixed', '/john/0/', [], {'name': 'john'}),
51
 
    ('repeats', '/repeats/a/', [], {}),
52
 
    ('repeats2', '/repeats/aa/', [], {}),
53
 
    ('repeats3', '/repeats/aa/', [], {}),
54
 
    ('insensitive', '/CaseInsensitive/fred', ['fred'], {}),
55
 
    ('test', '/test/1', [], {}),
56
 
    ('test2', '/test/2', [], {}),
57
 
    ('inner-nothing', '/outer/42/', [], {'outer': '42'}),
58
 
    ('inner-nothing', '/outer/42/', ['42'], {}),
59
 
    ('inner-nothing', NoReverseMatch, ['foo'], {}),
60
 
    ('inner-extra', '/outer/42/extra/inner/', [], {'extra': 'inner', 'outer': '42'}),
61
 
    ('inner-extra', '/outer/42/extra/inner/', ['42', 'inner'], {}),
62
 
    ('inner-extra', NoReverseMatch, ['fred', 'inner'], {}),
63
 
    ('disjunction', NoReverseMatch, ['foo'], {}),
64
 
    ('inner-disjunction', NoReverseMatch, ['10', '11'], {}),
65
 
    ('extra-places', '/e-places/10/', ['10'], {}),
66
 
    ('extra-people', '/e-people/fred/', ['fred'], {}),
67
 
    ('extra-people', '/e-people/fred/', [], {'name': 'fred'}),
68
 
)
69
 
 
70
 
class URLPatternReverse(TestCase):
71
 
    urls = 'regressiontests.urlpatterns_reverse.urls'
72
 
 
73
 
    def test_urlpattern_reverse(self):
74
 
        for name, expected, args, kwargs in test_data:
75
 
            try:
76
 
                got = reverse(name, args=args, kwargs=kwargs)
77
 
            except NoReverseMatch, e:
78
 
                self.assertEqual(expected, NoReverseMatch)
79
 
            else:
80
 
                self.assertEquals(got, expected)
81