I am writing tests for my views in django app. Previously they were in same directory in which my views are. They were working fine. But then I moved them in folder name 'tests' in django app. There are no import errors but I am getting 'NoReverseMatch' error. My directory structure is as follow.
Project
settings.py
|my_app
|tests
|tests.py
|__init__.py
|migrations
|__init__.py
|views.py
|models.py
|urls.py
My code is as follow
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django
django.setup()
from rest_framework.reverse import reverse
from rest_framework import status
from rest_framework.test import APITestCase
class MyTests(APITestCase):
def test_01(self):
url = reverse('login')
data = {'username': 'username', 'password': 'StrongPassword'}
response = self.client.post(url, data)
self.assertEqual(response.data, my_expected_output)
The error which I am getting is
NoReverseMatch: Reverse for 'login' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Can anyone tell me where I am doing something wrong
Aucun commentaire:
Enregistrer un commentaire