First commit with entire first rendition of the project
This commit is contained in:
38
tests/test_gallery.py
Normal file
38
tests/test_gallery.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import io
|
||||
|
||||
from PIL import Image as PILImage
|
||||
|
||||
|
||||
def _upload_image(client, filename="test_photo.jpg", color=(128, 64, 200)):
|
||||
img = PILImage.new("RGB", (800, 600), color=color)
|
||||
buf = io.BytesIO()
|
||||
img.save(buf, format="JPEG")
|
||||
buf.seek(0)
|
||||
return client.post(
|
||||
"/api/images",
|
||||
data={"file": (buf, filename)},
|
||||
content_type="multipart/form-data",
|
||||
)
|
||||
|
||||
|
||||
class TestGalleryDelete:
|
||||
def test_upload_delete_flow(self, client):
|
||||
resp = _upload_image(client)
|
||||
assert resp.status_code == 201
|
||||
data = resp.get_json()
|
||||
image_id = data["id"]
|
||||
|
||||
resp = client.get("/api/images")
|
||||
assert resp.status_code == 200
|
||||
data = resp.get_json()
|
||||
total_before = data["total"]
|
||||
assert total_before >= 1
|
||||
|
||||
resp = client.delete(f"/api/images/{image_id}")
|
||||
assert resp.status_code == 200
|
||||
assert resp.get_json() == {"status": "deleted"}
|
||||
|
||||
resp = client.get("/api/images")
|
||||
assert resp.status_code == 200
|
||||
data = resp.get_json()
|
||||
assert data["total"] == total_before - 1
|
||||
Reference in New Issue
Block a user