Changes between Initial Version and Version 2 of Ticket #27597
- Timestamp:
- Dec 14, 2016, 3:18:59 AM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #27597 – Description
initial v2 12 12 13 13 class UrlConf(object): 14 app_name = 'myapp' 15 14 16 # those are url patterns and views that I can re-used multiple times 15 17 common_url_patterns = [ … … 18 20 # here is a namespace to let's say group actions together 19 21 # I clearly set a namespace to make it more logical 20 url(r'^actions/', include( [22 url(r'^actions/', include(([ 21 23 url(r'^action/$', my_view, name='action') 22 ], namespace='actions'))24 ], app_name), namespace='actions')) 23 25 ] 24 26 25 27 urlpatterns = [ 26 28 # this is a part of my app into a namespace, nothing special about it 27 url(r'^root/', include( [29 url(r'^root/', include(([ 28 30 # depending of what are my keyword arguments 29 31 # I will use one of these two followings possibilities 30 32 url(r'^without-context/', include(common_url_patterns), kwargs={'additional_arg': -21}), 31 url(r'^with-context/(?P<var>[0-9]+)/', include(common_url_patterns)) 33 url(r'^with-context/(?P<var>[0-9]+)/', include(common_url_patterns)), 32 34 # you may ask why I'm not using nested optional argument 33 35 # this is because I explicitly defined kwargs arguments for my view in one cases 34 36 # but not in the other, so I cannot solve it that way 35 ], namespace='root'))37 ], app_name))) 36 38 ] 39 37 40 38 41 39 42 class TestUrlResolver(TestCase): 40 43 def _test_reverse_for(self, viewname, kwargs, expected): 41 self.assertEqual(reverse(viewname, kwargs=kwargs, urlconf=UrlConf), expected) 44 uri = reverse(viewname, kwargs=kwargs, urlconf=UrlConf) 45 self.assertEqual(uri, expected) 42 46 43 47 def test_page_without_var(self): 44 self._test_reverse_for(' root:page', None, '/root/without-context/')48 self._test_reverse_for('myapp:page', None, '/root/without-context/') 45 49 46 50 def test_page_with_var(self): 47 self._test_reverse_for(' root:page', {'var': 42}, '/root/with-context/42/')51 self._test_reverse_for('myapp:page', {'var': 42}, '/root/with-context/42/') 48 52 49 53 def test_action_without_var(self): 50 self._test_reverse_for(' root:actions:action', None, '/root/without-context/actions/action/')54 self._test_reverse_for('myapp:actions:action', None, '/root/without-context/actions/action/') 51 55 52 56 def test_action_with_var(self): 53 self._test_reverse_for(' root:actions:action', {'var': 42}, '/root/with-context/42/actions/action/')57 self._test_reverse_for('myapp:actions:action', {'var': 42}, '/root/with-context/42/actions/action/') 54 58 }}}