Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-lymar committed Jun 3, 2024
1 parent da8192e commit e7db6f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 17 additions & 0 deletions makedoc/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
import pytest
from rest_framework.test import APIClient
from rest_framework_simplejwt.tokens import RefreshToken

from users.models import CustomUser


@pytest.fixture
def user(django_user_model):
return CustomUser.objects.create_user(email='[email protected]', full_name='Test User',
password='testpassword')


@pytest.fixture
def api_client() -> APIClient:
return APIClient()


@pytest.fixture
def authorized_client(user):
client = APIClient()
refresh = RefreshToken.for_user(user)
client.credentials(HTTP_AUTHORIZATION=f"Bearer {str(refresh.access_token)}")
return client
7 changes: 4 additions & 3 deletions makedoc/tests/test_views_makedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def test_data_doc_view_status_code(api_client: APIClient) -> None:
"destination": "New York"
}
response = api_client.post(url, data, format='json')
assert response.status_code == 200
assert response.status_code == 401 # Unauthorized


@pytest.mark.django_db
def test_data_doc_view_response_data(api_client: APIClient) -> None:
def test_data_doc_view_response_data(authorized_client) -> None:
url = reverse('data')
data = {
"client_id": 123,
Expand All @@ -31,5 +31,6 @@ def test_data_doc_view_response_data(api_client: APIClient) -> None:
"factory_id": 1,
"destination": "New York"
}
response = api_client.post(url, data, format='json')
response = authorized_client.post(url, data, format='json')
assert response.status_code == 200
assert response.json() == data

0 comments on commit e7db6f3

Please sign in to comment.