Skip to content

Commit

Permalink
Add tests for add_document_data
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincarrogan committed Feb 5, 2024
1 parent 296889c commit d423bb4
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions unit_tests/exporter/applications/test_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from django.core.files.uploadedfile import SimpleUploadedFile

from exporter.applications.services import add_document_data


def test_add_document_data_no_files(rf):
no_files_request = rf.post("/")
data, error = add_document_data(no_files_request)
assert data is None
assert error == "No files attached"


def test_add_document_data_multiple_files(rf):
multiple_files_request = rf.post(
"/",
{
"file": [
SimpleUploadedFile("file 1", b"File 1 contents"),
SimpleUploadedFile("file 2", b"File 2 contents"),
]
},
)
data, error = add_document_data(multiple_files_request)
assert data is None
assert error == "Multiple files attached"


def test_add_document_data_single_file_no_description(rf):
single_file_request = rf.post(
"/",
{
"file": SimpleUploadedFile("file 1", b"File 1 contents"),
},
)
data, error = add_document_data(single_file_request)
assert data == {"name": "file 1", "s3_key": "file 1", "size": 0}
assert error is None


def test_add_document_data_single_file_with_description(rf):
single_file_request = rf.post(
"/",
{
"description": "test description",
"file": SimpleUploadedFile("file 1", b"File 1 contents"),
},
)
data, error = add_document_data(single_file_request)
assert data == {"description": "test description", "name": "file 1", "s3_key": "file 1", "size": 0}
assert error is None

0 comments on commit d423bb4

Please sign in to comment.