forked from mtusi2026/mtusi2026lab5
test(pipeline): cover variant metadata and correct lab endpoint
This commit is contained in:
@@ -10,7 +10,7 @@ from jsonschema import Draft202012Validator, FormatChecker
|
||||
CONTRACT = json.loads(
|
||||
(Path(__file__).parents[1] / "contracts/openapi.json").read_text()
|
||||
)
|
||||
BASE_URL = os.environ.get("BASE_URL", "http://127.0.0.1:8084")
|
||||
BASE_URL = os.environ.get("BASE_URL", "http://127.0.0.1:8085")
|
||||
PASSWORD = "Synthetic-Password-🌍-123"
|
||||
TOKENS = {}
|
||||
|
||||
|
||||
@@ -210,3 +210,68 @@ def test_chunked_body_limit_without_content_length(client, actors, chat):
|
||||
assert r.status_code == 413
|
||||
assert r.json()["error"]["code"] == "payload_too_large"
|
||||
assert r.json()["error"]["request_id"] == r.headers["x-request-id"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("size", [(1, 17), (320, 200), (1600, 900)])
|
||||
def test_variant_geometry_and_alpha(client, actors, chat, size):
|
||||
stream = io.BytesIO()
|
||||
Image.new("RGBA", size, (0, 0, 0, 0)).save(stream, format="PNG")
|
||||
a = check(
|
||||
upload(client, actors[0], chat, data=stream.getvalue()),
|
||||
202,
|
||||
"Attachment",
|
||||
)
|
||||
a = wait_ready(client, actors[0], a)
|
||||
for v in a["variants"]:
|
||||
r = client.get(
|
||||
f"/api/v1/attachments/{a['id']}/content",
|
||||
headers=headers(actors[1]),
|
||||
params={"variant": v["name"]},
|
||||
)
|
||||
assert len(r.content) == v["size_bytes"]
|
||||
assert hashlib.sha256(r.content).hexdigest() == v["sha256"]
|
||||
with Image.open(io.BytesIO(r.content)) as image:
|
||||
assert image.size == (v["width"], v["height"])
|
||||
assert not image.getexif()
|
||||
assert min(image.convert("RGB").getpixel((0, 0))) >= 250
|
||||
if v["name"] == "crop":
|
||||
assert image.size == (128, 128)
|
||||
else:
|
||||
bound = 256 if v["name"] == "thumbnail" else 1280
|
||||
assert max(image.size) <= bound
|
||||
assert image.width <= size[0] and image.height <= size[1]
|
||||
|
||||
|
||||
def test_exif_orientation_applied_but_original_preserved(client, actors, chat):
|
||||
stream = io.BytesIO()
|
||||
exif = Image.Exif()
|
||||
exif[274] = 6
|
||||
exif[270] = "Synthetic metadata must be removed"
|
||||
Image.new("RGB", (320, 200), "red").save(stream, format="JPEG", exif=exif)
|
||||
raw = stream.getvalue()
|
||||
a = check(
|
||||
upload(
|
||||
client,
|
||||
actors[0],
|
||||
chat,
|
||||
data=raw,
|
||||
mime="image/jpeg",
|
||||
filename="exif.jpg",
|
||||
),
|
||||
202,
|
||||
"Attachment",
|
||||
)
|
||||
a = wait_ready(client, actors[0], a)
|
||||
r = client.get(
|
||||
f"/api/v1/attachments/{a['id']}/content", headers=headers(actors[1])
|
||||
)
|
||||
assert r.content == raw
|
||||
v = next(v for v in a["variants"] if v["name"] == "thumbnail")
|
||||
assert (v["width"], v["height"]) == (160, 256)
|
||||
r = client.get(
|
||||
f"/api/v1/attachments/{a['id']}/content",
|
||||
headers=headers(actors[1]),
|
||||
params={"variant": "thumbnail"},
|
||||
)
|
||||
with Image.open(io.BytesIO(r.content)) as image:
|
||||
assert image.size == (160, 256) and not image.getexif()
|
||||
|
||||
Reference in New Issue
Block a user