Skip to content

Commit

Permalink
Add negative testcases for upload api
Browse files Browse the repository at this point in the history
  • Loading branch information
hv0905 committed May 20, 2024
1 parent 2e9c413 commit 0b07ef8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/api/test_upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import io
import random

from .conftest import TEST_ADMIN_TOKEN


def test_upload_bad_img_file(test_client):
bad_img_file = io.BytesIO(bytearray(random.getrandbits(8) for _ in range(1024 * 1024)))
bad_img_file.name = 'bad_image.jpg'

resp = test_client.post('/admin/upload',
files={'image_file': bad_img_file},
headers={'x-admin-token': TEST_ADMIN_TOKEN},
params={'local': True})
print(resp.content)
assert resp.status_code == 422


def test_upload_unsupported_types(test_client):
bad_img_file = io.BytesIO(bytearray(random.getrandbits(8) for _ in range(1024 * 1024)))
bad_img_file.name = 'bad_image.tga'

resp = test_client.post('/admin/upload',
files={'image_file': ('bad_img.tga', bad_img_file, 'image/tga')},
headers={'x-admin-token': TEST_ADMIN_TOKEN},
params={'local': True})
assert resp.status_code == 415

0 comments on commit 0b07ef8

Please sign in to comment.