89 lines
2.2 KiB
Python
89 lines
2.2 KiB
Python
import pytest
|
|
from flask import url_for
|
|
from app import create_app
|
|
from functions.database import get_db_connection, init_database
|
|
import os
|
|
|
|
@pytest.fixture
|
|
def app():
|
|
app = create_app()
|
|
app.config['TESTING'] = True
|
|
app.config['WTF_CSRF_ENABLED'] = False
|
|
|
|
# Criar banco de dados temporário para testes
|
|
with app.app_context():
|
|
init_database()
|
|
|
|
yield app
|
|
|
|
@pytest.fixture
|
|
def client(app):
|
|
return app.test_client()
|
|
|
|
@pytest.fixture
|
|
def runner(app):
|
|
return app.test_cli_runner()
|
|
|
|
def test_home_page(client):
|
|
response = client.get('/')
|
|
assert response.status_code == 302 # Redireciona para login
|
|
|
|
def test_login_page(client):
|
|
response = client.get('/login')
|
|
assert response.status_code == 200
|
|
assert b'Login' in response.data
|
|
|
|
def test_listar_assinaturas_jornal(client):
|
|
# Primeiro fazer login
|
|
client.post('/login', data={
|
|
'username': 'admin',
|
|
'password': 'admin123'
|
|
})
|
|
|
|
response = client.get('/assinaturas/jornal')
|
|
assert response.status_code == 200
|
|
assert b'Assinaturas de Jornal' in response.data
|
|
|
|
def test_nova_assinatura_jornal(client):
|
|
# Primeiro fazer login
|
|
client.post('/login', data={
|
|
'username': 'admin',
|
|
'password': 'admin123'
|
|
})
|
|
|
|
response = client.get('/assinaturas/jornal/novo')
|
|
assert response.status_code == 200
|
|
assert b'Registrar Nova Assinatura Anual' in response.data
|
|
|
|
def test_listar_militantes(client):
|
|
# Primeiro fazer login
|
|
client.post('/login', data={
|
|
'username': 'admin',
|
|
'password': 'admin123'
|
|
})
|
|
|
|
response = client.get('/militantes')
|
|
assert response.status_code == 200
|
|
assert b'Militantes' in response.data
|
|
|
|
def test_listar_cotas(client):
|
|
# Primeiro fazer login
|
|
client.post('/login', data={
|
|
'username': 'admin',
|
|
'password': 'admin123'
|
|
})
|
|
|
|
response = client.get('/cotas')
|
|
assert response.status_code == 200
|
|
assert b'Cotas' in response.data
|
|
|
|
def test_listar_materiais(client):
|
|
# Primeiro fazer login
|
|
client.post('/login', data={
|
|
'username': 'admin',
|
|
'password': 'admin123'
|
|
})
|
|
|
|
response = client.get('/materiais')
|
|
assert response.status_code == 200
|
|
assert b'Materiais' in response.data |