This doesn’t look like test_login(?)
I don’t know, that’s why I’m on this forum obviously, because I’m not sure. I was following the DRF docs.
Clearly if it’s not correctly running, then no the code isn’t right for the login api test
What I’m saying is that the last file you posted doesn’t look like it’s the file with the import error, it’s your other test file.
My fault
from django.urls import reverse
from rest_framework import status
from rest_framework.test import APITestCase
from ..models import User
from rest_framework.test import APIClient
class UserLoginTests(APITestCase):
def create_user(self, username, email=None, password=None, **extra_fields):
client = APIClient()
user = User.objects.create_user('username', 'email', 'Password!87')
self.assertTrue(self.client.login(username='username', password='Password!87'))
response = self.client.get(reverse('login'))
self.assertEqual(response.status_code, status.HTTP_200_OK)
I believe this is the file you were referring to
Your test function name must start with test_
. It should be called test_create_user
Thank you. Is this only error that you noticed?
Try it and see. If there’s something else wrong, it’ll tell you.
I did, an error with the missing positional argument for username
I fixed it. Thank you