31 lines
952 B
Python
Executable File
31 lines
952 B
Python
Executable File
import pytest
|
|
from rest_framework import status
|
|
from rest_framework.utils import json
|
|
|
|
|
|
@pytest.mark.django_db
|
|
class UserLoginE2ETests:
|
|
def test_missing_username_and_password_fail_validation(self, client):
|
|
# Arrange
|
|
# Act
|
|
response = client.post(
|
|
"/token/", data=json.dumps({}), content_type="application/json"
|
|
)
|
|
# Assert
|
|
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
|
|
|
def test_valid_credentials_return_token(self, user_factory, client):
|
|
# Arrange
|
|
user_factory(username="username", password="valid_password")
|
|
|
|
# Act
|
|
response = client.post(
|
|
"/token/",
|
|
data=json.dumps({"username": "username", "password": "valid_password"}),
|
|
content_type="application/json",
|
|
)
|
|
data = response.json()
|
|
# Assert
|
|
assert response.status_code == status.HTTP_200_OK
|
|
assert "token" in data
|