Django

Code

Changeset 7849

Show
Ignore:
Timestamp:
07/06/08 09:16:43 (5 months ago)
Author:
mtredinnick
Message:

Some tests for the new features. These pretty much fail at the moment. Based on

SmileyChris?'s original work.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/tests/regressiontests/urlpatterns_reverse/tests.py

    r7660 r7849  
    1 "Unit tests for reverse URL lookup" 
     1""" 
     2Unit tests for reverse URL lookups. 
     3""" 
     4 
     5import re 
     6import unittest 
    27 
    38from django.core.urlresolvers import reverse_helper, NoReverseMatch 
    4 import re, unittest 
    59 
    610test_data = ( 
     
    913    ('^places/(\d+)/$', NoReverseMatch, ['a'], {}), 
    1014    ('^places/(\d+)/$', NoReverseMatch, [], {}), 
     15    ('^places?/$', '/', [], {}), 
     16    ('^places+/$', 'places/', [], {}), 
     17    ('^places*/$', '/', [], {}), 
     18    (r'^places/(\d+|[a-z_]+)/', 'places/4/', [4], {}), 
     19    (r'^places/(\d+|[a-z_]+)/', 'places/harlem/', ['harlem'], {}), 
     20    (r'^places/(\d+|[a-z_]+)/', NoReverseMatch, ['harlem64'], {}), 
    1121    ('^places/(?P<id>\d+)/$', 'places/3/', [], {'id': 3}), 
     22    ('^people/(?P<name>\w+)/$', NoReverseMatch, [], {}), 
    1223    ('^people/(?P<name>\w+)/$', 'people/adrian/', ['adrian'], {}), 
    1324    ('^people/(?P<name>\w+)/$', 'people/adrian/', [], {'name': 'adrian'}), 
    1425    ('^people/(?P<name>\w+)/$', NoReverseMatch, ['name with spaces'], {}), 
    1526    ('^people/(?P<name>\w+)/$', NoReverseMatch, [], {'name': 'name with spaces'}), 
    16     ('^people/(?P<name>\w+)/$', NoReverseMatch, [], {}), 
     27    ('^people/(?:name/)', 'people/name/', [], {}), 
     28    ('^people/(?:name/)?', 'people/', [], {}), 
     29    ('^people/(?:name/(\w+)/)?', 'people/name/fred/', ['fred'], {}), 
    1730    ('^hardcoded/$', 'hardcoded/', [], {}), 
    1831    ('^hardcoded/$', 'hardcoded/', ['any arg'], {}), 
     
    2538    ('^people/(?P<state>\w\w)/(\w+)/$', NoReverseMatch, ['il'], {'name': 'adrian'}), 
    2639    ('^people/(?P<state>\w\w)/(\w+)/$', 'people/il/adrian/', ['adrian'], {'state': 'il'}), 
     40    (r'^people/((?P<state>\w\w)/test)?/(\w+)/$', 'people/il/test/adrian/', ['adrian'], {'state': 'il'}), 
     41    (r'^people/((?P<state>\w\w)/test)?/(\w+)/$', NoReverseMatch, ['adrian'], {}), 
     42    ('^character_set/[abcdef0-9]/$', 'character_set/a/', [], {}), 
     43    ('^character_set/[\w]/$', 'character_set/a/', [], {}), 
     44    (r'^price/\$(\d+)/$', 'price/$10/', ['10'], {}), 
     45    (r'^price/[$](\d+)/$', 'price/$10/', ['10'], {}), 
     46    (r'^price/[\$](\d+)/$', 'price/$10/', ['10'], {}), 
     47    (r'^product/(?P<product>\w+)\+\(\$(?P<price>\d+(\.\d+)?)\)/$', 'product/chocolate+($2.00)/', ['2.00'], {'product': 'chocolate'}), 
     48    (r'^headlines/(?P<year>\d+)\.(?P<month>\d+)\.(?P<day>\d+)/$', 'headlines/2007.5.21/', [], dict(year=2007, month=5, day=21)), 
     49    (r'^windows_path/(?P<drive_name>[A-Z]):\\(?P<path>.+)/$', r'windows_path/C:\Documents and Settings\spam/', [], dict(drive_name='C', path=r'Documents and Settings\spam')), 
     50    (r'^special_chars/(.+)/$', r'special_chars/+\$*/', [r'+\$*'], {}), 
     51    (r'^special_chars/(.+)/$', NoReverseMatch, [''], {}), 
     52    (r'^(?P<name>.+)/\d+/$', NoReverseMatch, [], {'name': 'john'}), 
     53    (r'^repeats/a{1,2}/$', 'repeats/a/', [], {}), 
     54    (r'^repeats/a{2,4}/$', 'repeats/aa/', [], {}), 
     55    (r'^people/(?:(?:wilma|fred)/)$', '/people/wilma', [], {}), 
    2756) 
    2857 
     
    3160        for regex, expected, args, kwargs in test_data: 
    3261            try: 
    33                 got = reverse_helper(re.compile(regex), *args, **kwargs) 
     62                got = reverse_helper(regex, *args, **kwargs) 
    3463            except NoReverseMatch, e: 
    3564                self.assertEqual(expected, NoReverseMatch) 
     
    3766                self.assertEquals(got, expected) 
    3867 
    39 if __name__ == "__main__": 
    40     run_tests(1)