Skip to content
Snippets Groups Projects
Commit 1a7d601d authored by Neda Moeini's avatar Neda Moeini
Browse files

Update unit tests to support authentication.

parent b7456861
No related branches found
No related tags found
1 merge request!4Feature/activity log
This commit is part of merge request !4. Comments created here will be created in the context of that merge request.
"""All the tests for the file_validator app."""
......@@ -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
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment