33 lines
766 B
Python
33 lines
766 B
Python
|
|
import pytest
|
||
|
|
from app import create_app
|
||
|
|
from functions.database import init_database, get_db_connection
|
||
|
|
|
||
|
|
@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
|
||
|
|
db = get_db_connection()
|
||
|
|
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()
|