"""Pytest configuration and shared fixtures for Sneaky Klaus tests.""" import pytest from src.app import create_app from src.app import db as _db from src.models import Admin @pytest.fixture(scope="session") def app(): """Create and configure a test Flask application instance. This fixture is scoped to the session so the app is created once for all tests. Yields: Flask application configured for testing. """ app = create_app("testing") yield app @pytest.fixture(scope="function") def db(app): """Create a clean database for each test. This fixture creates all tables before each test and drops them after each test to ensure isolation. Args: app: Flask application instance from app fixture. Yields: SQLAlchemy database instance. """ with app.app_context(): _db.create_all() yield _db _db.session.remove() _db.drop_all() @pytest.fixture(scope="function") def client(app, db): # noqa: ARG001 """Create a test client for the Flask application. Args: app: Flask application instance. db: Database instance (ensures db is set up first). Yields: Flask test client. """ with app.test_client() as client: yield client @pytest.fixture def admin(db): """Create an admin user for testing. Args: db: Database instance. Returns: Admin model instance. """ from src.app import bcrypt admin = Admin( email="admin@example.com", password_hash=bcrypt.generate_password_hash("testpassword123").decode("utf-8"), ) db.session.add(admin) db.session.commit() return admin