This commit is contained in:
timka123 committed 2026-10-18 18:02:05 +03:00
commit 17a0a3c4c9
121 files changed
+17641

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
"""Test fixtures.
The engine is built at import time from the environment, so the database URL has
to be set before anything from `app` is imported — hence the env juggling here
rather than in a fixture.
"""
from __future__ import annotations
import os
import tempfile
import pytest
os.environ.setdefault("DATABASE_URL", "sqlite:///" + tempfile.mktemp(suffix=".db"))
os.environ["SCHEDULER_ENABLED"] = "false"
os.environ["TELEGRAM_BOT_ENABLED"] = "false"
# Keep the seeded settings empty so tests never reach a real Jira/Todoist.
for name in (
"JIRA_BASE_URL",
"JIRA_EMAIL",
"JIRA_API_TOKEN",
"TODOIST_API_TOKEN",
"GOOGLE_CLIENT_ID",
"GOOGLE_CLIENT_SECRET",
"GOOGLE_REFRESH_TOKEN",
"LAUNDRY_SESSION",
"TELEGRAM_BOT_TOKEN",
"TELEGRAM_CHAT_ID",
"SLACK_WEBHOOK_URL",
):
os.environ.pop(name, None)
from app.db import Base, SessionLocal, engine, init_db # noqa: E402
from app.services import settings_service # noqa: E402
from app.settings_schema import AppSettings # noqa: E402
@pytest.fixture()
def session():
Base.metadata.drop_all(bind=engine)
init_db()
db = SessionLocal()
try:
yield db
finally:
db.close()
@pytest.fixture()
def settings(session) -> AppSettings:
return settings_service.load_settings(session)
@pytest.fixture()
def client():
from fastapi.testclient import TestClient
from app.main import app
Base.metadata.drop_all(bind=engine)
init_db()
with TestClient(app) as test_client:
yield test_client