"""Хелперы HTTP-тестов: post_verify собирает multipart с повторяемой частью reference.""" from __future__ import annotations import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) # tests/ для synth from synth import make_blocks # noqa: E402 # Блочные паттерны 4x4 (16 бит, по строкам): A и B делят ровно половину единиц, # C не пересекается с A — косинусы для FakeEmbedder: A/A=1.0, A/B=0.5, A/C=0.0 PATTERN_A = (1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0) PATTERN_B = (1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0) PATTERN_C = (0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1) def block_jpeg(pattern) -> bytes: from synth import encode return encode(make_blocks(list(pattern), size=256), fmt="JPEG") def post_verify(client, probe: bytes, references: list[bytes], headers: dict | None = None): files = [("probe", ("probe.jpg", probe, "image/jpeg"))] files += [ ("reference", (f"ref_{i}.jpg", blob, "image/jpeg")) for i, blob in enumerate(references) ] return client.post("/api/v1/verify", files=files, headers=headers)