Files
bin/finance/tests/test_migration_sqlite.py
2026-09-30 13:06:36 +02:00

36 lines
1.2 KiB
Python

"""Alembic-Revision e7f1a9c3b214 (A14) muss auch auf SQLite hoch/runter/hoch laufen."""
from pathlib import Path
from alembic import command
from alembic.config import Config
from sqlalchemy import create_engine, inspect
ROOT = Path(__file__).resolve().parent.parent
def test_migration_a14_sqlite_up_down_up(tmp_path, monkeypatch):
url = f"sqlite:///{tmp_path / 'mig.db'}"
monkeypatch.setenv("FB_DATABASE_URL", url)
from app.config import get_settings
get_settings.cache_clear()
try:
cfg = Config(str(ROOT / "alembic.ini"))
cfg.set_main_option("script_location", str(ROOT / "alembic"))
engine = create_engine(url)
def state():
insp = inspect(engine)
return ("scenario_recurring_items" in insp.get_table_names(),
"category_id" in {c["name"] for c in
insp.get_columns("scenario_planned_items")})
command.upgrade(cfg, "head")
assert state() == (True, True)
command.downgrade(cfg, "d5e8b3c7a410")
assert state() == (False, False)
command.upgrade(cfg, "head")
assert state() == (True, True)
engine.dispose()
finally:
get_settings.cache_clear()