Hi,
I am using pytest for testing the login API and it is failing.
import pytest
from rest_framework import status
from core.fixtures.user import user
class TestAuthenticationViewSet:
endpoint = "/api/auth/"
def test_login(self, client, user):
data = {"username": user.username, "password": "test_password"}
response = client.post(self.endpoint + "login/", data)
assert response.status_code == status.HTTP_200_OK
assert response.data["access"]
assert response.data["user"]["id"] == user.public_id.hex
assert response.data["user"]["username"] == user.username
assert response.data["user"]["email"] == user.email
I get the following warning and a subsequent Error
assert response.status_code == status.HTTP_200_OK
E assert 400 == 200
E + where 400 = <Response status_code=400, “application/json”>.status_code
E + and 200 = status.HTTP_200_OK
core/auth/tests.py:14: AssertionError
----------------------------------------------- Captured log call -----------------------------------------------
WARNING django.request:log.py:225 Bad Request: /api/auth/login/
FAILED core/auth/tests.py::TestAuthenticationViewSet::test_login - assert 400 == 200
The login API works fine via Postman or Browser. What am I missing?
Cheers,
Nithin