2026-04-25 10:38:21 +02:00
|
|
|
import logging
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
from alembic import config
|
|
|
|
|
from pytest_alembic.config import Config
|
|
|
|
|
from streamlit.testing.v1 import AppTest
|
2026-04-30 14:16:57 +02:00
|
|
|
import streamlit as st
|
2026-04-25 10:38:21 +02:00
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
|
def setup_database(alembic_runner):
|
|
|
|
|
logger.info("Running database migrations")
|
|
|
|
|
alembic_runner.migrate_up_to('heads')
|
|
|
|
|
yield
|
|
|
|
|
logger.info("Resetting database")
|
|
|
|
|
alembic_runner.migrate_down_to('base')
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def alembic_config() -> Config:
|
2026-04-30 14:16:57 +02:00
|
|
|
logger.info("Setting up alembic config")
|
2026-04-25 10:38:21 +02:00
|
|
|
alembic_cfg = config.Config(toml_file="pyproject.toml")
|
|
|
|
|
alembic_cfg.set_main_option("sqlalchemy.url", os.getenv("DATABASE_URL", ""))
|
|
|
|
|
return Config(alembic_config=alembic_cfg)
|
|
|
|
|
|
2026-04-30 14:16:57 +02:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
|
def user_config():
|
|
|
|
|
logger.info("Setting up test user")
|
|
|
|
|
st.user = None
|
|
|
|
|
st.session_state.user_id = 1
|
|
|
|
|
st.session_state.user_name = "Test User"
|
|
|
|
|
st.session_state.user_email = "test@test.local"
|
|
|
|
|
st.session_state.user_external_id = "111-2222-3333"
|
|
|
|
|
|
2026-04-25 10:38:21 +02:00
|
|
|
@pytest.fixture
|
|
|
|
|
def app() -> AppTest:
|
|
|
|
|
return AppTest.from_file("app/streamlit_app.py")
|
|
|
|
|
|
|
|
|
|
def delete_database():
|
|
|
|
|
file = os.getenv("DATABASE_FILE")
|
|
|
|
|
if file and os.path.isfile(file):
|
|
|
|
|
logger.info(f"Deleting database file {file}")
|
|
|
|
|
os.remove(file)
|