from pathlib import Path import pytest from app import create_app, db from config import Config @pytest.fixture() def app(tmp_path): class TestConfig(Config): TESTING = True IS_PRODUCTION = False SECRET_KEY = "test-secret-key-that-is-long-enough" CREDENTIAL_ENCRYPTION_KEY = "test-encryption-key-that-is-long-enough" SQLALCHEMY_DATABASE_URI = f"sqlite:///{tmp_path / 'test.db'}" SQLALCHEMY_ENGINE_OPTIONS = {} WTF_CSRF_ENABLED = False SESSION_COOKIE_SECURE = False ENFORCE_HTTPS = False ALLOW_WEB_SETUP = True RATELIMIT_ENABLED = False UPLOAD_FOLDER = tmp_path / "uploads" PHOTO_FOLDER = UPLOAD_FOLDER / "photos" QR_FOLDER = UPLOAD_FOLDER / "qrcodes" LOGO_FOLDER = UPLOAD_FOLDER / "logos" application = create_app(TestConfig) yield application with application.app_context(): db.session.remove() db.drop_all() @pytest.fixture() def client(app): return app.test_client() def login_as(client, user, current_event_id=None): with client.session_transaction() as session: session["user_id"] = user.id session["role"] = user.role session["session_version"] = user.session_version if current_event_id: session["current_event_id"] = current_event_id session["checkin_event_id"] = current_event_id