I am trying to use reverse()in unit test, but it cannot resolve the url.
tests.py:
from django.core.urlresolvers import reverse
from rest_framework import status
from rest_framework.test import APITestCase
class MyTest(APITestCase):
def test_cust_lookup(self):
url = reverse('v1:customer')
In the first line of the test, the test case fails:
NoReverseMatch: Reverse for 'customer' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Did you try “0 patterns” means the test can't even find the root urls.py? Or is there something else that I configured incorrectly?
proj/settings.py:
ROOT_URLCONF = 'proj.urls'
proj/myapp/urls.py:
from django.conf.urls import url
import views
urlpatterns = [
url(r'cust/$', views.CustomerView.as_view(), name='customer')
]
proj/urls.py:
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^api1/v1/', include('myapp1.urls', namespace='v1')),
url(r'^api2/v1/', include('myapp2.urls', namespace='v1'))
]
source
share