forked from CGM_Public/pretix_original
API: File upload infrastructure
This commit is contained in:
31
src/tests/api/test_upload.py
Normal file
31
src/tests/api/test_upload.py
Normal 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
|
||||
Reference in New Issue
Block a user