Plantilla inicial del taller
publicar / publicar (push) Failing after 8s

This commit is contained in:
taller committed 2026-11-22 18:51:26 +00:00
1 parent 182c87dc0a
commit 664c8e49a8
22 files changed
+1157

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
"""Tests del contrato (niveles 1 y 2). NO los modifiquéis para que pasen: arreglad la API.
Ejecutar desde api/: python -m pytest -q
"""
import importlib
import sys
from pathlib import Path
import pytest
API_DIR = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(API_DIR))
@pytest.fixture()
def cliente(tmp_path, monkeypatch):
monkeypatch.setenv("DB_PATH", str(tmp_path / "votos.db"))
monkeypatch.setenv("CENSO_PATH", str(API_DIR.parent / "alumnos.csv"))
import app as modulo
importlib.reload(modulo)
return modulo.app.test_client()
def test_opciones(cliente):
assert cliente.get("/api/opciones").get_json() == ["Ibiza", "Praga"]
def test_nivel1_voto_valido_cuenta(cliente):
r = cliente.post("/api/votos", json={"codigo": "A0001", "opcion": "Ibiza"})
assert r.status_code == 201
assert cliente.get("/api/resultados").get_json() == {"Ibiza": 1, "Praga": 0, "total": 1}
def test_nivel2_repetir_codigo_da_409(cliente):
cliente.post("/api/votos", json={"codigo": "A0002", "opcion": "Praga"})
r = cliente.post("/api/votos", json={"codigo": "A0002", "opcion": "Ibiza"})
assert r.status_code == 409
def test_nivel2_codigo_fuera_del_censo_da_403(cliente):
r = cliente.post("/api/votos", json={"codigo": "Z9999", "opcion": "Ibiza"})
assert r.status_code == 403
def test_nivel2_opcion_desconocida_da_400(cliente):
r = cliente.post("/api/votos", json={"codigo": "A0003", "opcion": "Roma"})
assert r.status_code == 400