2025-04-15 14:26:02 -03:00
|
|
|
import pytest
|
|
|
|
|
from app import create_app
|
2026-02-20 17:19:15 -03:00
|
|
|
from functions.database import init_database, get_db_session
|
2025-04-15 14:26:02 -03:00
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def app():
|
|
|
|
|
"""Cria uma instância do app para testes"""
|
|
|
|
|
app = create_app()
|
|
|
|
|
app.config['TESTING'] = True
|
|
|
|
|
app.config['WTF_CSRF_ENABLED'] = False
|
|
|
|
|
|
|
|
|
|
# Inicializar banco de dados de teste
|
|
|
|
|
init_database()
|
|
|
|
|
|
|
|
|
|
yield app
|
|
|
|
|
|
|
|
|
|
# Limpar banco após os testes
|
2026-02-20 17:19:15 -03:00
|
|
|
db = get_db_session()
|
2025-04-15 14:26:02 -03:00
|
|
|
try:
|
|
|
|
|
db.execute('DROP TABLE IF EXISTS usuarios CASCADE')
|
|
|
|
|
db.commit()
|
|
|
|
|
finally:
|
|
|
|
|
db.close()
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def client(app):
|
|
|
|
|
"""Cria um cliente de teste"""
|
|
|
|
|
return app.test_client()
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def runner(app):
|
|
|
|
|
"""Cria um runner de CLI para testes"""
|
|
|
|
|
return app.test_cli_runner()
|