﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27411	Django namespaced reverse not working in test environment	atkawa7	nobody	"I am have the following error when testing an app

{{{
ERROR: test_registration (accounts.tests.test_models.AccountTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""C:\Users\username\Downloads\djangoworkspace\src\accounts\tests\test_models.py"", line 41, in test_registration
    url, user, format='json')
  File ""C:\Python35\lib\site-packages\rest_framework\test.py"", line 172, in post
    path, data=data, format=format, content_type=content_type, **extra)
  File ""C:\Python35\lib\site-packages\rest_framework\test.py"", line 94, in post
    return self.generic('POST', path, data, content_type, **extra)
  File ""C:\Python35\lib\site-packages\django\test\client.py"", line 387, in generic
    parsed = urlparse(force_str(path))
  File ""C:\Python35\lib\site-packages\django\utils\encoding.py"", line 76, in force_text
    s = six.text_type(s)
  File ""C:\Python35\lib\site-packages\django\utils\functional.py"", line 116, in __text_cast
    return func(*self.__args, **self.__kw)
  File ""C:\Python35\lib\site-packages\django\urls\base.py"", line 91, in reverse
    return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
  File ""C:\Python35\lib\site-packages\django\urls\resolvers.py"", line 392, in _reverse_with_prefix
    (lookup_view_s, args, kwargs, len(patterns), patterns)
django.urls.exceptions.NoReverseMatch: Reverse for 'registration' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
}}}

Here is my urls.py


{{{
   urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^accounts/', include('rest_framework.urls', namespace='rest_framework')),
    url(r'^api/v1/accounts/login/', obtain_auth_token, name='obtain_auth_token'),
    url(r'^api/v1/accounts/', include('accounts.urls', namespace='accounts')),
    url(r'', include('app.urls', namespace='app')),
]
}}}

accounts urls.py 

{{{
from django.conf.urls import url
from . import views
urlpatterns = [
    url(r'^register/$', views.RegistrationView.as_view(), name='registration'),
    url(r'^users/$', views.AdminCreateUserView.as_view(), name='users'),
    url(r'^groups/$', views.GroupsCreateView.as_view(), name='groups'),
]

}}}
here is my example test


{{{
from rest_framework import test, status

from django.core.urlresolvers import reverse, reverse_lazy
from django.contrib.auth.models import User


class AccountTestCase(test.APITestCase):

    def test_registration(self):
        url = reverse_lazy('registration', current_app='accounts')
        user = {
            'username': 'John',
            'first_name': 'John',
            'last_name': 'Doe',
            'password': 'johnDoe12345*#$',
            'email': 'johndoe@example.com'
        }
        user2 = {
            'username': 'John2',
            'first_name': 'John',
            'last_name': 'Doe',
            'password': 'johnDoe12345*#$',
            'email': 'johndoe@example.com'
        }
        user3 = {
            'username': 'John2',
            'first_name': 'John',
            'last_name': 'Doe',
            'email': 'johndoe@example.com'
        }
        user4 = {
            'username': 'John4',
            'first_name': 'John',
            'last_name': 'Doe',
            'email': 'johndoe@example.com',
            'password': 'johnDoe12345*#$',
            'is_staff': True,
            'is_superuser': True
        }
        response = self.client.post(
            url, user, format='json')
}}}

However when I change urls.py  to  


{{{
   urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^accounts/', include('rest_framework.urls', namespace='rest_framework')),
    url(r'^api/v1/accounts/login/', obtain_auth_token, name='obtain_auth_token'),
    url(r'^api/v1/accounts/', include('accounts.urls')),
    url(r'', include('app.urls', namespace='app')),
]
}}}

It works fine.


"	Bug	closed	Testing framework	1.10	Normal	invalid			Unreviewed	0	0	0	0	0	0
