test(pipeline): cover variant metadata and correct lab endpoint

This commit is contained in:
2026-11-15 22:33:09 +03:00
parent d3e156e8a1
commit bb4e8a2254
5 changed files with 90 additions and 4 deletions
+65
View File
@@ -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()