diff --git a/sage_validation/file_validator/tests.py b/sage_validation/file_validator/tests.py deleted file mode 100644 index 676ebd605102ad796947e51e5e7b946f30420eb3..0000000000000000000000000000000000000000 --- a/sage_validation/file_validator/tests.py +++ /dev/null @@ -1 +0,0 @@ -"""All the tests for the file_validator app.""" diff --git a/test/conftest.py b/test/conftest.py index f32a5947d4e438df30201bec9d863bbd9e486ae5..9f0053be849e1cbdc23e7e0e584c33d0517f7260 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -2,6 +2,7 @@ from unittest.mock import MagicMock import pytest +from django.contrib.auth.models import User from django.core.files.uploadedfile import SimpleUploadedFile from faker import Faker from rest_framework.test import APIClient @@ -144,4 +145,8 @@ def mock_meo_database(mocker: MagicMock)-> None: @pytest.fixture def api_client() -> APIClient: """Fixture to return Django API test client.""" - return APIClient() + fake = Faker() + user = User.objects.create_user(username=fake.user_name(), password=fake.password()) + client = APIClient() + client.force_authenticate(user=user) + return client diff --git a/test/test_file_validator/test_file_validator_endpoints.py b/test/test_file_validator/test_file_validator_endpoints.py index 3193a62b63d3e73eb1bd9d5f46127f3adec51a49..ac78502a4b0eb99b30dbc4454863273b288cbae2 100644 --- a/test/test_file_validator/test_file_validator_endpoints.py +++ b/test/test_file_validator/test_file_validator_endpoints.py @@ -8,6 +8,15 @@ from rest_framework.test import APIClient UPLOAD_FILE_URL = reverse("upload-file") +@pytest.mark.django_db +def test_csv_upload_unauthenticated(sample_input_file: SimpleUploadedFile) -> None: + """Test that a valid CSV upload succeeds.""" + api_client = APIClient() + response = api_client.post(UPLOAD_FILE_URL, {"file": sample_input_file}, format="multipart") + + assert response.status_code == 403 + assert response.json()["detail"] == "Authentication credentials were not provided." + @pytest.mark.django_db def test_csv_upload_valid( api_client: APIClient, sample_input_file: SimpleUploadedFile, mock_meo_database: MagicMock