Accept ZIP batches to preserve every photo shared by Shortcuts
This commit is contained in:
@@ -6,6 +6,7 @@ import subprocess
|
||||
import sys
|
||||
import os
|
||||
import random
|
||||
import zipfile
|
||||
|
||||
import pytest
|
||||
from PIL import Image
|
||||
@@ -70,6 +71,38 @@ def test_multi_megabyte_multipart_file(service):
|
||||
assert response.status_code == 202, response.json
|
||||
|
||||
|
||||
def test_zip_batch_preserves_all_images_order_and_deduplicates(service):
|
||||
_, client, data = service
|
||||
images = [photo("red"), photo("blue"), photo("green")]
|
||||
archive = io.BytesIO()
|
||||
with zipfile.ZipFile(archive, "w") as output:
|
||||
for i, raw in enumerate(images):
|
||||
output.writestr(f"selection/{i}.jpg", raw)
|
||||
output.writestr("__MACOSX/._0.jpg", b"metadata")
|
||||
response = client.post("/api/photos", headers=AUTH, data={
|
||||
"archive": (io.BytesIO(archive.getvalue()), "photos.zip"),
|
||||
"caption": "Batch", "highlight": "Trip",
|
||||
})
|
||||
assert response.status_code == 202, response.json
|
||||
assert response.json["count"] == 3
|
||||
folder = data / "submissions" / response.json["id"]
|
||||
for i, raw in enumerate(images):
|
||||
assert (folder / "originals" / str(i)).read_bytes() == raw
|
||||
assert upload(client, images, "Batch", highlight="Trip").json["id"] == response.json["id"]
|
||||
|
||||
|
||||
def test_zip_invalid_or_oversized_batches_are_atomic(service):
|
||||
_, client, data = service
|
||||
for contents in ([b"bad"], [photo()] * 21):
|
||||
archive = io.BytesIO()
|
||||
with zipfile.ZipFile(archive, "w") as output:
|
||||
for i, raw in enumerate(contents):
|
||||
output.writestr(f"{i}.jpg", raw)
|
||||
response = client.post("/api/photos", headers=AUTH, data={"archive": (io.BytesIO(archive.getvalue()), "photos.zip")})
|
||||
assert response.status_code == 400
|
||||
assert not list((data / "submissions").iterdir())
|
||||
|
||||
|
||||
def test_album_caption_order_and_retry_deduplication(service):
|
||||
_, client, data = service
|
||||
caption = '<script>alert(1)</script> {% include secret %} {{ site.email }}\nsecond line'
|
||||
|
||||
Reference in New Issue
Block a user