from pathlib import Path from study_dashboard.services.database import ( DatabaseBootstrapper, DatabaseConfig, ) from study_dashboard.services.sqlite_repository import SQLiteStudyRepository def create_bootstrapped_repo(tmp_path) -> SQLiteStudyRepository: db_path = Path(tmp_path) / "study.db" bootstrapper = DatabaseBootstrapper(DatabaseConfig(db_path=db_path)) bootstrapper.initialize() return SQLiteStudyRepository(db_path) def test_bootstrap_creates_demo_modules(tmp_path): repo = create_bootstrapped_repo(tmp_path) modules = repo.list_modules() assert len(modules) >= 3 module_codes = {module.module_id for module in modules} assert module_codes >= {"MAT101", "CS201", "ENG150"} def test_bootstrap_is_idempotent(tmp_path): db_path = Path(tmp_path) / "study.db" bootstrapper = DatabaseBootstrapper(DatabaseConfig(db_path=db_path)) bootstrapper.initialize() # running twice must not raise nor duplicate rows bootstrapper.initialize() repo = SQLiteStudyRepository(db_path) exams = repo.list_upcoming_exams() assert len(exams) >= 2 assert exams[0].exam_date <= exams[1].exam_date def test_calendar_tile_lists_upcoming_appointments(tmp_path): repo = create_bootstrapped_repo(tmp_path) appointments = repo.list_upcoming_appointments(limit=1) assert len(appointments) == 1 assert appointments[0].title in {"Mentoring", "Lerngruppe"}