22 lines
733 B
Python
22 lines
733 B
Python
from fastapi.testclient import TestClient
|
|
|
|
from app.main import app
|
|
|
|
client = TestClient(app)
|
|
|
|
|
|
def test_raiz_sem_login_pede_credenciais():
|
|
resposta = client.get("/", follow_redirects=False)
|
|
assert resposta.status_code == 401
|
|
|
|
|
|
def test_raiz_redireciona_para_clientes_com_login(monkeypatch):
|
|
from app.routers import clientes as router_clientes
|
|
|
|
monkeypatch.setattr(router_clientes.db_clientes, "listar_clientes", lambda busca=None, limite=100: [])
|
|
import base64
|
|
token = base64.b64encode(b"admin:teste123").decode()
|
|
resposta = client.get("/", headers={"Authorization": f"Basic {token}"}, follow_redirects=False)
|
|
assert resposta.status_code == 307
|
|
assert resposta.headers["location"] == "/clientes"
|