-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
296889c
commit d423bb4
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |