import pytest
from app import create_app
from app.extensions import db as _db


@pytest.fixture()
def app():
    """Create application with in-memory SQLite for testing."""
    app = create_app({
        'TESTING': True,
        'SQLALCHEMY_DATABASE_URI': 'sqlite:///:memory:',
        'WTF_CSRF_ENABLED': False,
        'SECRET_KEY': 'test-secret-key',
    })
    with app.app_context():
        yield app


@pytest.fixture()
def db(app):
    """Create all tables before each test, drop after."""
    _db.create_all()
    yield _db
    _db.drop_all()


@pytest.fixture()
def client(db):
    """Flask test client — depends on db so tables always exist."""
    from flask import current_app
    return current_app.test_client()
