from __future__ import annotations import pytest from app import create_app from app.extensions import db from app.models import Account, Role @pytest.fixture() def app(): app = create_app( "testing", { "SECRET_KEY": "test-secret", "SQLALCHEMY_DATABASE_URI": "sqlite:///:memory:", }, ) with app.app_context(): db.create_all() yield app db.session.remove() db.drop_all() @pytest.fixture() def client(app): return app.test_client() def create_account(username: str = "admin", role: str = Role.ADMIN.value) -> Account: account = Account( username=username, email=f"{username}@example.com", full_name=username.title(), role=role, ) account.set_password("Password12345") db.session.add(account) db.session.commit() return account def login(client, username: str = "admin", password: str = "Password12345"): return client.post( "/auth/login", data={"username": username, "password": password}, follow_redirects=True, )