API: File upload infrastructure

This commit is contained in:
Raphael Michel
2021-01-05 12:49:58 +01:00
parent 9d70fd675c
commit 8b08b43e77
6 changed files with 149 additions and 1 deletions

View File

@@ -0,0 +1,31 @@
import pytest
from django.core.files.base import ContentFile
@pytest.mark.django_db
def test_upload_file(token_client):
r = token_client.post(
'/api/v1/upload',
data={
'media_type': 'application/pdf',
'file': ContentFile('file.pdf', 'invalid pdf content')
},
format='upload',
HTTP_CONTENT_DISPOSITION='attachment; filename="file.pdf"',
)
assert r.status_code == 201
assert r.data['id'].startswith('file:')
@pytest.mark.django_db
def test_upload_file_extension_mismatch(token_client):
r = token_client.post(
'/api/v1/upload',
data={
'media_type': 'application/pdf',
'file': ContentFile('file.png', 'invalid pdf content')
},
format='upload',
HTTP_CONTENT_DISPOSITION='attachment; filename="file.png"',
)
assert r.status_code == 400