Ticket #17173: specialchar-unittest.patch

File specialchar-unittest.patch, 9.2 KB (added by kaiser.yann@…, 13 years ago)

Patch against SVN HEAD. Adds a few unittests for urlpatterns_reverse

  • tests/regressiontests/urlpatterns_reverse/namespace_urls.py

     
    1414        return patterns('',
    1515            url(r'^inner/$', 'empty_view', name='urlobject-view'),
    1616            url(r'^inner/(?P<arg1>\d+)/(?P<arg2>\d+)/$', 'empty_view', name='urlobject-view'),
     17            url(r'^inner/\+\\\$\*/$', 'empty_view', name='urlobject-special-view'),
    1718        ), self.app_name, self.namespace
    1819    urls = property(urls)
    1920
     
    2829    url(r'^normal/$', 'empty_view', name='normal-view'),
    2930    url(r'^normal/(?P<arg1>\d+)/(?P<arg2>\d+)/$', 'empty_view', name='normal-view'),
    3031
     32    url(r'^\+\\\$\*/$', 'empty_view', name='special-view'),
     33
    3134    url(r'^mixed_args/(\d+)/(?P<arg2>\d+)/$', 'empty_view', name='mixed-args'),
    3235    url(r'^no_kwargs/(\d+)/(\d+)/$', 'empty_view', name='no-kwargs'),
    3336
     
    5053
    5154    (r'^ns-outer/(?P<outer>\d+)/', include('regressiontests.urlpatterns_reverse.included_namespace_urls', namespace='inc-outer')),
    5255
     56    (r'^\+\\\$\*/', include('regressiontests.urlpatterns_reverse.namespace_urls', namespace='special')),
    5357)
  • tests/regressiontests/urlpatterns_reverse/tests.py

     
    294294        self.assertEqual('/normal/', reverse('normal-view'))
    295295        self.assertEqual('/normal/37/42/', reverse('normal-view', args=[37,42]))
    296296        self.assertEqual('/normal/42/37/', reverse('normal-view', kwargs={'arg1':42, 'arg2':37}))
     297        self.assertEqual('/+%5C$*/', reverse('special-view'))
    297298
    298299    def test_simple_included_name(self):
    299300        "Normal lookups work on names included from other patterns"
    300301        self.assertEqual('/included/normal/', reverse('inc-normal-view'))
    301302        self.assertEqual('/included/normal/37/42/', reverse('inc-normal-view', args=[37,42]))
    302303        self.assertEqual('/included/normal/42/37/', reverse('inc-normal-view', kwargs={'arg1':42, 'arg2':37}))
     304        self.assertEqual('/included/+%5C$*/', reverse('inc-special-view'))
    303305
    304306    def test_namespace_object(self):
    305307        "Dynamic URL objects can be found using a namespace"
    306308        self.assertEqual('/test1/inner/', reverse('test-ns1:urlobject-view'))
    307309        self.assertEqual('/test1/inner/37/42/', reverse('test-ns1:urlobject-view', args=[37,42]))
    308310        self.assertEqual('/test1/inner/42/37/', reverse('test-ns1:urlobject-view', kwargs={'arg1':42, 'arg2':37}))
     311        self.assertEqual('/test1/inner/+%5C$*/', reverse('test-ns1:urlobject-special-view'))
    309312
    310313    def test_embedded_namespace_object(self):
    311314        "Namespaces can be installed anywhere in the URL pattern tree"
    312315        self.assertEqual('/included/test3/inner/', reverse('test-ns3:urlobject-view'))
    313316        self.assertEqual('/included/test3/inner/37/42/', reverse('test-ns3:urlobject-view', args=[37,42]))
    314317        self.assertEqual('/included/test3/inner/42/37/', reverse('test-ns3:urlobject-view', kwargs={'arg1':42, 'arg2':37}))
     318        self.assertEqual('/included/test3/inner/+%5C$*/', reverse('test-ns3:urlobject-special-view'))
    315319
    316320    def test_namespace_pattern(self):
    317321        "Namespaces can be applied to include()'d urlpatterns"
    318322        self.assertEqual('/ns-included1/normal/', reverse('inc-ns1:inc-normal-view'))
    319323        self.assertEqual('/ns-included1/normal/37/42/', reverse('inc-ns1:inc-normal-view', args=[37,42]))
    320324        self.assertEqual('/ns-included1/normal/42/37/', reverse('inc-ns1:inc-normal-view', kwargs={'arg1':42, 'arg2':37}))
     325        self.assertEqual('/ns-included1/+%5C$*/', reverse('inc-ns1:inc-special-view'))
    321326
    322327    def test_namespace_pattern_with_variable_prefix(self):
    323328        "When using a include with namespaces when there is a regex variable in front of it"
     
    325330        self.assertEqual('/ns-outer/42/normal/', reverse('inc-outer:inc-normal-view', args=[42]))
    326331        self.assertEqual('/ns-outer/42/normal/37/4/', reverse('inc-outer:inc-normal-view', kwargs={'outer':42, 'arg1': 37, 'arg2': 4}))
    327332        self.assertEqual('/ns-outer/42/normal/37/4/', reverse('inc-outer:inc-normal-view', args=[42, 37, 4]))
     333        self.assertEqual('/ns-outer/42/+%5C$*/', reverse('inc-outer:inc-special-view',  kwargs={'outer':42}))
     334        self.assertEqual('/ns-outer/42/+%5C$*/', reverse('inc-outer:inc-special-view',  args=[42]))
    328335
    329336    def test_multiple_namespace_pattern(self):
    330337        "Namespaces can be embedded"
    331338        self.assertEqual('/ns-included1/test3/inner/', reverse('inc-ns1:test-ns3:urlobject-view'))
    332339        self.assertEqual('/ns-included1/test3/inner/37/42/', reverse('inc-ns1:test-ns3:urlobject-view', args=[37,42]))
    333340        self.assertEqual('/ns-included1/test3/inner/42/37/', reverse('inc-ns1:test-ns3:urlobject-view', kwargs={'arg1':42, 'arg2':37}))
     341        self.assertEqual('/ns-included1/test3/inner/+%5C$*/', reverse('inc-ns1:test-ns3:urlobject-special-view'))
    334342
    335343    def test_nested_namespace_pattern(self):
    336344        "Namespaces can be nested"
    337345        self.assertEqual('/ns-included1/ns-included4/ns-included1/test3/inner/', reverse('inc-ns1:inc-ns4:inc-ns1:test-ns3:urlobject-view'))
    338346        self.assertEqual('/ns-included1/ns-included4/ns-included1/test3/inner/37/42/', reverse('inc-ns1:inc-ns4:inc-ns1:test-ns3:urlobject-view', args=[37,42]))
    339347        self.assertEqual('/ns-included1/ns-included4/ns-included1/test3/inner/42/37/', reverse('inc-ns1:inc-ns4:inc-ns1:test-ns3:urlobject-view', kwargs={'arg1':42, 'arg2':37}))
     348        self.assertEqual('/ns-included1/ns-included4/ns-included1/test3/inner/+%5C$*/', reverse('inc-ns1:inc-ns4:inc-ns1:test-ns3:urlobject-special-view'))
    340349
    341350    def test_app_lookup_object(self):
    342351        "A default application namespace can be used for lookup"
    343352        self.assertEqual('/default/inner/', reverse('testapp:urlobject-view'))
    344353        self.assertEqual('/default/inner/37/42/', reverse('testapp:urlobject-view', args=[37,42]))
    345354        self.assertEqual('/default/inner/42/37/', reverse('testapp:urlobject-view', kwargs={'arg1':42, 'arg2':37}))
     355        self.assertEqual('/default/inner/+%5C$*/', reverse('testapp:urlobject-special-view'))
    346356
    347357    def test_app_lookup_object_with_default(self):
    348358        "A default application namespace is sensitive to the 'current' app can be used for lookup"
    349359        self.assertEqual('/included/test3/inner/', reverse('testapp:urlobject-view', current_app='test-ns3'))
    350360        self.assertEqual('/included/test3/inner/37/42/', reverse('testapp:urlobject-view', args=[37,42], current_app='test-ns3'))
    351361        self.assertEqual('/included/test3/inner/42/37/', reverse('testapp:urlobject-view', kwargs={'arg1':42, 'arg2':37}, current_app='test-ns3'))
     362        self.assertEqual('/included/test3/inner/+%5C$*/', reverse('testapp:urlobject-special-view', current_app='test-ns3'))
    352363
    353364    def test_app_lookup_object_without_default(self):
    354365        "An application namespace without a default is sensitive to the 'current' app can be used for lookup"
    355366        self.assertEqual('/other2/inner/', reverse('nodefault:urlobject-view'))
    356367        self.assertEqual('/other2/inner/37/42/', reverse('nodefault:urlobject-view', args=[37,42]))
    357368        self.assertEqual('/other2/inner/42/37/', reverse('nodefault:urlobject-view', kwargs={'arg1':42, 'arg2':37}))
     369        self.assertEqual('/other2/inner/+%5C$*/', reverse('nodefault:urlobject-special-view'))
    358370
    359371        self.assertEqual('/other1/inner/', reverse('nodefault:urlobject-view', current_app='other-ns1'))
    360372        self.assertEqual('/other1/inner/37/42/', reverse('nodefault:urlobject-view', args=[37,42], current_app='other-ns1'))
    361373        self.assertEqual('/other1/inner/42/37/', reverse('nodefault:urlobject-view', kwargs={'arg1':42, 'arg2':37}, current_app='other-ns1'))
     374        self.assertEqual('/other1/inner/+%5C$*/', reverse('nodefault:urlobject-special-view', current_app='other-ns1'))
    362375
     376    def test_special_chars_namespace(self):
     377        self.assertEqual('/+%5C$*/included/normal/', reverse('special:inc-normal-view'))
     378        self.assertEqual('/+%5C$*/included/normal/37/42/', reverse('special:inc-normal-view', args=[37,42]))
     379        self.assertEqual('/+%5C$*/included/normal/42/37/', reverse('special:inc-normal-view', kwargs={'arg1':42, 'arg2':37}))
     380        self.assertEqual('/+%5C$*/included/+%5C$*/', reverse('special:inc-special-view'))
     381
    363382class RequestURLconfTests(TestCase):
    364383    def setUp(self):
    365384        self.root_urlconf = settings.ROOT_URLCONF
  • tests/regressiontests/urlpatterns_reverse/included_namespace_urls.py

     
    1212    url(r'^normal/$', 'empty_view', name='inc-normal-view'),
    1313    url(r'^normal/(?P<arg1>\d+)/(?P<arg2>\d+)/$', 'empty_view', name='inc-normal-view'),
    1414
     15    url(r'^\+\\\$\*/$', 'empty_view', name='inc-special-view'),
     16
    1517    url(r'^mixed_args/(\d+)/(?P<arg2>\d+)/$', 'empty_view', name='inc-mixed-args'),
    1618    url(r'^no_kwargs/(\d+)/(\d+)/$', 'empty_view', name='inc-no-kwargs'),
    1719
Back to Top