Previously I was working on Django in its version 1.11 and go to version 2.0
This brought with it that some tests that I had defined do not work for me.
Below I put the code of one:
from rest_framework.test import APITestCase
from django.urls import reverse
class PingApiTestCase(APITestCase):
def setUp(self):
self.access_token = self.create_access_token() # metodo que me crea un token para el test
def test_increase_token_time(self):
url = reverse('ping')
data = { 'token': self.access_token.token }
response = self.client.patch(url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
This is the definition of the url corresponding to the name 'ping':
from django.conf.urls import url
urlpatterns = [
url(r'^ping/$',
ping_view.PingView.as_view(),
name='ping')
]
In the test, when it reaches the line to invoke the reverse, it sends the following error:
{NoReverseMatch} Reverse for 'ping' not found. 'ping' is not valid view function or pattern name.
Any ideas?
Thank you very much in advance