010 fix config
This commit is contained in:
@@ -1,16 +1,35 @@
|
||||
import importlib
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from app.config import Settings
|
||||
from app.main import app, create_app
|
||||
from app import config as config_module
|
||||
from app.config import Settings, get_settings
|
||||
|
||||
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() -> None:
|
||||
assert isinstance(app, FastAPI)
|
||||
assert isinstance(app.state.settings, Settings)
|
||||
def test_app_import_smoke(monkeypatch) -> None:
|
||||
main_module = _import_main_module(monkeypatch)
|
||||
|
||||
assert isinstance(main_module.app, FastAPI)
|
||||
assert isinstance(main_module.app.state.settings, Settings)
|
||||
get_settings.cache_clear()
|
||||
|
||||
|
||||
def test_app_created_with_provided_settings() -> None:
|
||||
def test_app_created_with_provided_settings(monkeypatch) -> None:
|
||||
main_module = _import_main_module(monkeypatch)
|
||||
monkeypatch.setattr(config_module, "TEST_CONFIG_FILE", str(TEST_CONFIG_FILE))
|
||||
|
||||
settings = Settings()
|
||||
instance = create_app(settings=settings)
|
||||
instance = main_module.create_app(settings=settings)
|
||||
|
||||
assert instance.state.settings is settings
|
||||
get_settings.cache_clear()
|
||||
|
||||
Reference in New Issue
Block a user