Skip to content
19 changes: 18 additions & 1 deletion backend/core/tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
import pytest
from rest_framework.test import APIClient

from django.contrib.auth import get_user_model

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

@pytest.fixture
def authenticated_client(api_client) -> APIClient:
"""
Provides an authenticated API client for testing.

Creates a test user and forces authentication for all requests made with this client.
This eliminates the need to manually handle authentication in most test cases.
"""
User = get_user_model()
user = User.objects.create_user(
username="testuser",
password="testpass123",
email="[email protected]"
)
api_client.force_authenticate(user=user)
return api_client


@pytest.fixture(autouse=True)
def turn_off_throttling(settings, request: pytest.FixtureRequest):
Expand Down
Loading