Changes between Initial Version and Version 2 of Ticket #27597


Ignore:
Timestamp:
Dec 14, 2016, 3:18:59 AM (8 years ago)
Author:
Adrien mille
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #27597 – Description

    initial v2  
    1212
    1313class UrlConf(object):
     14    app_name = 'myapp'
     15
    1416    # those are url patterns and views that I can re-used multiple times
    1517    common_url_patterns = [
     
    1820        # here is a namespace to let's say group actions together
    1921        # I clearly set a namespace to make it more logical
    20         url(r'^actions/', include([
     22        url(r'^actions/', include(([
    2123            url(r'^action/$', my_view, name='action')
    22         ], namespace='actions'))
     24        ], app_name), namespace='actions'))
    2325    ]
    2426
    2527    urlpatterns = [
    2628        # this is a part of my app into a namespace, nothing special about it
    27         url(r'^root/', include([
     29        url(r'^root/', include(([
    2830            # depending of what are my keyword arguments
    2931            # I will use one of these two followings possibilities
    3032            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)),
    3234            # you may ask why I'm not using nested optional argument
    3335            # this is because I explicitly defined kwargs arguments for my view in one cases
    3436            # but not in the other, so I cannot solve it that way
    35         ], namespace='root'))
     37        ], app_name)))
    3638    ]
     39
    3740
    3841
    3942class TestUrlResolver(TestCase):
    4043    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)
    4246
    4347    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/')
    4549
    4650    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/')
    4852
    4953    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/')
    5155
    5256    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/')
    5458}}}
Back to Top