init app
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
"""Помощники интеграционных тестов: вызовы API и модификация блобов."""
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import json
|
||||
|
||||
import numpy as np
|
||||
|
||||
API_KEY_HEADERS = {"X-API-Key": "test-key"}
|
||||
|
||||
|
||||
def post_features(client, image: bytes, settings: dict | None = None):
|
||||
data = {"settings": json.dumps(settings)} if settings else None
|
||||
return client.post(
|
||||
"/api/v1/features",
|
||||
headers=API_KEY_HEADERS,
|
||||
files={"image": ("image.jpg", image, "image/jpeg")},
|
||||
data=data,
|
||||
)
|
||||
|
||||
|
||||
def post_verify(client, probe: bytes, references: list[tuple[str, bytes, str]], settings: dict | None = None):
|
||||
"""references — список (имя, байты, content_type)."""
|
||||
files = [("probe", ("probe.jpg", probe, "image/jpeg"))]
|
||||
files += [("reference", (name, body, ctype)) for name, body, ctype in references]
|
||||
data = {"settings": json.dumps(settings)} if settings else None
|
||||
return client.post(
|
||||
"/api/v1/verify",
|
||||
headers=API_KEY_HEADERS,
|
||||
files=files,
|
||||
data=data,
|
||||
)
|
||||
|
||||
|
||||
def make_blob_ref(blob: bytes) -> tuple[str, bytes, str]:
|
||||
return ("reference.npz", blob, "application/octet-stream")
|
||||
|
||||
|
||||
def make_image_ref(image: bytes) -> tuple[str, bytes, str]:
|
||||
return ("reference.jpg", image, "image/jpeg")
|
||||
|
||||
|
||||
def rewrite_blob_meta(blob: bytes, **overrides) -> bytes:
|
||||
"""Пересобирает блоб с изменёнными полями meta (для IT-05)."""
|
||||
npz = np.load(io.BytesIO(blob), allow_pickle=False)
|
||||
meta = json.loads(str(npz["meta"].item()))
|
||||
meta.update(overrides)
|
||||
buffer = io.BytesIO()
|
||||
np.savez_compressed(
|
||||
buffer,
|
||||
descriptors=npz["descriptors"],
|
||||
keypoints=npz["keypoints"],
|
||||
meta=np.array(json.dumps(meta)),
|
||||
)
|
||||
return buffer.getvalue()
|
||||
Reference in New Issue
Block a user