Files
g2s-aggregator/tests/smoke/test_app_import.py
T
Раис Юсупалиев 7c5be003c1 014 add json logging
2026-03-13 17:19:03 +03:00

52 lines
1.6 KiB
Python

import importlib
import sys
from pathlib import Path
from fastapi import FastAPI
from app import config as config_module
from app.config import Settings, get_settings
from app.runtime import logging as logging_module
TEST_CONFIG_FILE = Path(__file__).resolve().parents[2] / "config.test.yaml"
def _import_main_module(monkeypatch):
get_settings.cache_clear()
monkeypatch.setattr(config_module, "TEST_CONFIG_FILE", str(TEST_CONFIG_FILE))
sys.modules.pop("app.main", None)
return importlib.import_module("app.main")
def test_app_import_smoke(monkeypatch) -> None:
bootstrap_calls: list[None] = []
def fake_configure_logging() -> None:
bootstrap_calls.append(None)
monkeypatch.setattr(logging_module, "configure_logging", fake_configure_logging)
main_module = _import_main_module(monkeypatch)
assert isinstance(main_module.app, FastAPI)
assert isinstance(main_module.app.state.settings, Settings)
assert bootstrap_calls == [None]
get_settings.cache_clear()
def test_app_created_with_provided_settings(monkeypatch) -> None:
bootstrap_calls: list[None] = []
def fake_configure_logging() -> None:
bootstrap_calls.append(None)
monkeypatch.setattr(logging_module, "configure_logging", fake_configure_logging)
main_module = _import_main_module(monkeypatch)
monkeypatch.setattr(config_module, "TEST_CONFIG_FILE", str(TEST_CONFIG_FILE))
settings = Settings()
instance = main_module.create_app(settings=settings)
assert instance.state.settings is settings
assert bootstrap_calls == [None, None]
get_settings.cache_clear()