forked from mtusi2026/mtusi2026lab7
Source: mtusi2026lab6-safronov, solution/bvt2301-safronov, 6c6a065. Files follow AGENTS.md, "Переход в следующую лабу". Contracts, public tests, README, REPORT and evidence of lab 6 are not carried over; infra and scripts of the lab 7 skeleton stay as they are. Makefile is the lab 6 one with the lab 7 skeleton part restored (HTTPS BASE_URL on 8443, test-security); .gitignore and .dockerignore are taken from lab 6 because both skeletons have the same files; .env.example is the lab 6 one without changes. The compose project, image and CI prefix are renamed to lab7, and references to the previous lab now name lab6. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
2.4 KiB
Python
85 lines
2.4 KiB
Python
"""Быстрые тесты сервисов: без PostgreSQL, Valkey, S3, брокера, docker и сети.
|
|
|
|
`settings` читает `.env` и `config.toml` по абсолютному пути, поэтому поля, от
|
|
которых зависят ветки сервисов, подставляются здесь: результат не зависит от
|
|
локальных файлов и окружения (design change `unit-of-work`, решение 13).
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from fakes import (
|
|
FakeCache,
|
|
FakeDatabase,
|
|
FakeJobPublisher,
|
|
FakeObjectStorage,
|
|
FakeUnitOfWork,
|
|
)
|
|
from src.config import settings
|
|
from src.schemas.enums import MetricBucketsEnum
|
|
|
|
|
|
@pytest.fixture
|
|
def anyio_backend() -> str:
|
|
return "asyncio"
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def fixed_settings(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
fixed = (
|
|
(
|
|
settings.worker,
|
|
{
|
|
"max_attempts": 3,
|
|
"job_timeout_seconds": 60,
|
|
"lease_margin_seconds": 10,
|
|
"retry_base_delay_seconds": 5,
|
|
"retry_max_delay_seconds": 300,
|
|
"reconnect_seconds": 0.01,
|
|
},
|
|
),
|
|
(settings.auth, {"session_ttl_seconds": 3600}),
|
|
(settings.idempotency, {"ttl_seconds": 86400}),
|
|
(settings.cache, {"chat_ttl_seconds": 600}),
|
|
(
|
|
settings.uploads,
|
|
{"body_timeout_seconds": 1, "max_unfinished_jobs": 0},
|
|
),
|
|
(settings.app, {"instance_id": "test-instance"}),
|
|
(
|
|
settings.telemetry,
|
|
{
|
|
"trace_sample_ratio": 1.0,
|
|
"metric_buckets": MetricBucketsEnum.DEFAULT,
|
|
"metric_export_interval_seconds": 15,
|
|
},
|
|
),
|
|
)
|
|
for section, fields in fixed:
|
|
for name, value in fields.items():
|
|
monkeypatch.setattr(section, name, value)
|
|
|
|
|
|
@pytest.fixture
|
|
def database() -> FakeDatabase:
|
|
return FakeDatabase()
|
|
|
|
|
|
@pytest.fixture
|
|
def uow(database: FakeDatabase) -> FakeUnitOfWork:
|
|
return FakeUnitOfWork(database)
|
|
|
|
|
|
@pytest.fixture
|
|
def cache(database: FakeDatabase) -> FakeCache:
|
|
return FakeCache(database)
|
|
|
|
|
|
@pytest.fixture
|
|
def storage(database: FakeDatabase) -> FakeObjectStorage:
|
|
return FakeObjectStorage(database)
|
|
|
|
|
|
@pytest.fixture
|
|
def publisher(database: FakeDatabase) -> FakeJobPublisher:
|
|
return FakeJobPublisher(database)
|