"""Общие фикстуры: конфиг, приложение, клиент, синтетические изображения. Лимиты входа в тестовом конфиге меньше боевых (1 МБ на изображение), чтобы сценарии 413/IT-07 не генерировали десятки мегабайт. """ from __future__ import annotations import pytest from fastapi.testclient import TestClient from app.config import Config from app.main import create_app from tests import synth TEST_API_KEY = "test-key" def make_config(**overrides) -> Config: values = dict( api_key=TEST_API_KEY, host="127.0.0.1", port=8000, workers=1, log_level="WARNING", max_image_bytes=1 * 1024 * 1024, verify_max_body_bytes=8 * 1024 * 1024, max_references=32, sift_max_image_size=1600, sift_max_keypoints=16384, lowe_ratio=0.75, ransac_reproj_threshold=5.0, match_inliers_min=50, match_inliers_ratio_min=0.30, match_coverage_min=0.05, uncertain_inliers_min=20, ) values.update(overrides) return Config(**values) @pytest.fixture(scope="session") def config() -> Config: return make_config() @pytest.fixture(scope="session") def app(config: Config): return create_app(config) @pytest.fixture(scope="session") def client(app) -> TestClient: with TestClient(app, raise_server_exceptions=False) as test_client: yield test_client @pytest.fixture(scope="session") def blob_a(client: TestClient, facade_a: bytes) -> bytes: """Блоб признаков базового «фасада», вычисленный через боевой эндпоинт.""" from tests.api.helpers import post_features response = post_features(client, facade_a) assert response.status_code == 200 return response.content # ------------------------------------------------------------ изображения @pytest.fixture(scope="session") def facade_a() -> bytes: return synth.encode_jpg(synth.make_facade(seed=7)) @pytest.fixture(scope="session") def facade_a_warp() -> bytes: return synth.encode_jpg(synth.warp_perspective(synth.make_facade(seed=7))) @pytest.fixture(scope="session") def facade_a_half() -> bytes: return synth.encode_jpg(synth.scale_half(synth.make_facade(seed=7))) @pytest.fixture(scope="session") def facade_a_crop() -> bytes: return synth.encode_jpg(synth.crop_center(synth.make_facade(seed=7))) @pytest.fixture(scope="session") def facade_b() -> bytes: return synth.encode_jpg(synth.make_facade(seed=99)) @pytest.fixture(scope="session") def flat_image() -> bytes: return synth.encode_jpg(synth.make_flat()) @pytest.fixture(scope="session") def tiny_image() -> bytes: return synth.encode_jpg(synth.make_flat(width=300, height=200)) @pytest.fixture(scope="session") def exif_image() -> bytes: return synth.encode_exif_oriented(synth.make_facade(seed=11))