old_console/console/tests/test_auth.py
2024-11-02 14:12:45 +03:00

42 lines
1.2 KiB
Python

import pytest
from rest_framework import status
from rest_framework.reverse import reverse
@pytest.mark.unit
@pytest.mark.django_db
class TestAuth:
@pytest.fixture(autouse=True)
def setup_tests(self, django_user_model):
self.admin_user = django_user_model.objects.get(username='admin')
def test_login_with_active_user(self, api_client):
url = reverse('api_login')
credentials = {
'username': 'admin',
'password': 'nimda'
}
response = api_client.post(url, data=credentials)
assert response.status_code == status.HTTP_200_OK
credentials = {
'username': 'admin',
'password': 'invalid_password'
}
response = api_client.post(url, data=credentials)
assert response.status_code == status.HTTP_400_BAD_REQUEST
def test_login_with_non_active_user(self, api_client):
url = reverse('api_login')
self.admin_user.is_active = False
self.admin_user.save()
credentials = {
'username': 'admin',
'password': 'nimda'
}
response = api_client.post(url, data=credentials)
assert response.status_code == status.HTTP_400_BAD_REQUEST