Thursday, July 4, 2013

Re: Namespace URLs in TestCase

As I said, it's trivial:

urlpatterns = patterns('', 
    url(r'^sso/$', include(app_patterns, 'app', 'app')))

The regexp is wrong. It should be only ^sso/ because other urls are appended after it…

Fortunatelly, Django 1.6 has more helpful exception as it prints all url patterns which 'reverse' function tried.

Sorry for spam, but it took me a while to found it.

Cheers,
  Tom


Dne čtvrtek, 4. července 2013 16:53:34 UTC+2 Tomáš Ehrlich napsal(a):
Hi there,
it's probably silly bug, but I can't figure it out:


I have one test:
###
# app/tests_functional/test_app.py
from django.core.urlresolvers import reverse
from django.test import TestCase

class TestApp(TestCase):
    urls = 'app.tests_functional.urls'

    def test_app(self):
        print(reverse('app:get'), reverse('app:retrieve'))
        self.fail()


where urls are defined:
###
# apps/tests_functional/urls.py
from django.conf.urls import patterns, url, include

# I use class-based views, which are tested and works.
def view(request): pass  

app_patterns = patterns('',
    url(r'^get/$', view, name='get'),
    url(r'^retrieve/$', view, name='retrieve'))

urlpatterns = patterns('',
    url(r'^sso/$', include(app_patterns, 'app', 'app')))


Now, when I run tests, I got Exception:
NoReverseMatch: Reverse for 'get' with arguments '()' and keyword
arguments '{}' not found.


I tried to rename app_patterns to urlpatterns and reverse('get'). It
works, but my app uses namespaced urls, so I can't change code of view
to test it that way.

I believe it's really silly think. Can you see it?


Thank you :)

Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate