"""Fixtures: minimale Flask-testapp + tijdelijke sqlite-DB (zelfde interface als database.py).""" import os import sqlite3 import sys import pytest from flask import Flask, session sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from agenda_module import (init_agenda_db, load_agenda_seed, register_agenda_routes, render_agenda_alerts_html) REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SEED_PATH = os.path.join(REPO, 'data', 'agenda-seed-nieuwsbrief1.json') class FakeDb: """Minimalistische stand-in voor database.py (get_db() -> sqlite3 conn met Row-factory).""" def __init__(self, path): self.path = path def get_db(self): conn = sqlite3.connect(self.path) conn.row_factory = sqlite3.Row conn.execute("PRAGMA journal_mode=WAL") return conn def page_stub(body_html, active='dashboard', page_title='LGCC', **kwargs): """Minimalistische stand-in voor app.py page().""" return f'{page_title}{body_html}' @pytest.fixture def db(tmp_path): fake = FakeDb(str(tmp_path / 'test_lions.db')) init_agenda_db(fake) init_agenda_db(fake) # idempotentie-check: tweede keer mag geen fout geven return fake @pytest.fixture def client(db): app = Flask(__name__) app.secret_key = 'test-secret' register_agenda_routes(app, page_stub, '', lambda msgs: 'ok', db) app.test_client_class = None with app.test_client() as c: yield c def login(client): """Simuleer een geauthenticeerde (admin-)sessie, zoals de productie-app die zet.""" with client.session_transaction() as s: s['authenticated'] = True s['user_id'] = 'admin'