How to use URL namespaces in tests?

88 views
Skip to first unread message

e.generalov

unread,
Aug 23, 2012, 3:25:54 AM8/23/12
to django...@googlegroups.com
Url patterns which provided by a django application should be addressed externally in the form of "namespace:name". I guess it will be connected to the project as follows:

project/urls.py

urlpatterns = patterns('',
    url('^something/', include('django_something.urls', namespace='something')))

URL patterns module in the application looks like:

django_something/urls.py

urlpatterns = patterns('',
    url('^$', show, name='show'))

and I write a test:

django_something/tests.py

class ShowViewTest(TestCase):
    urls = 'django_something.urls'

    def test_should_render_something_template(self):
        url = reverse('something:show') # !!!
        response = self.client.get(url)
        self.assertIn('something.html', set([t.name for t in response.templates]))

This test failes with exception "django NoReverseMatch 'something' is not a registered namespace" . How can I specify namespace 'something' in this case?

Natim

unread,
Sep 5, 2012, 10:33:35 AM9/5/12
to django...@googlegroups.com
I've got the same problem any ideas ?

Natim

unread,
Sep 5, 2012, 10:37:06 AM9/5/12
to django...@googlegroups.com
Ok it is quite easy, you are missing {% load url from future %} in your template.


Le jeudi 23 août 2012 09:25:54 UTC+2, e.generalov a écrit :

e.generalov

unread,
Sep 7, 2012, 5:44:07 AM9/7/12
to django...@googlegroups.com
Unfortunately in my case, no templates are used.

среда, 5 сентября 2012 г., 20:37:06 UTC+6 пользователь Natim написал:
Reply all
Reply to author
Forward
0 new messages