c326f4901d
Remove 64 Python docstrings and 39 comments, and trim prose from three noqa pragmas. The submodule had zero tracked Markdown files. Move published route descriptions into decorator arguments and the Correction schema description into ConfigDict. Drop internal docstrings, including the OAuth callback excluded from OpenAPI. Published route descriptions are unchanged in the before-and-after comparison of the nine application routers. The full application OpenAPI check requires fastapi-users, which is missing from the shared environment.
47 lines
1.9 KiB
Python
47 lines
1.9 KiB
Python
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from webapi.main import app
|
|
|
|
|
|
@pytest.fixture
|
|
def client(own_platform, monkeypatch):
|
|
monkeypatch.setenv("AUTH_ADMIN_EMAIL", "admin@isssteleon.mx")
|
|
monkeypatch.setenv("AUTH_ADMIN_PASSWORD", "una-clave-larga")
|
|
with TestClient(app) as c:
|
|
yield c
|
|
|
|
|
|
def login(client, email, password):
|
|
return client.post("/auth/login", data={"username": email, "password": password})
|
|
|
|
|
|
def test_the_first_administrator_signs_in_and_adds_a_team(client):
|
|
assert client.get("/users/me").status_code == 401
|
|
assert login(client, "admin@isssteleon.mx", "mala").status_code == 400
|
|
assert login(client, "admin@isssteleon.mx", "una-clave-larga").status_code == 204
|
|
me = client.get("/users/me").json()
|
|
assert me["is_superuser"] and me["domains"] == ["cacu", "cama", "tea"]
|
|
team = {"email": "cacu@isssteleon.mx", "password": "equipo-cacu", "name": "Equipo CaCu",
|
|
"domains": ["cacu"]} # fmt: skip
|
|
assert client.post("/users/register", json=team).status_code == 201
|
|
client.post("/auth/logout")
|
|
assert login(client, "cacu@isssteleon.mx", "equipo-cacu").status_code == 204
|
|
assert client.get("/users/me").json()["domains"] == ["cacu"]
|
|
other = {"email": "x@isssteleon.mx", "password": "otra-clave"}
|
|
assert client.post("/users/register", json=other).status_code == 403
|
|
|
|
|
|
def test_the_api_answers_without_a_session(client):
|
|
for path in ("/health", "/domains", "/ingest/schema", "/ingest/sources/types"):
|
|
assert client.get(path).status_code == 200, path
|
|
|
|
|
|
def test_a_restart_keeps_the_administrator_once_and_the_session_secret(client, own_platform):
|
|
assert login(client, "admin@isssteleon.mx", "una-clave-larga").status_code == 204
|
|
secret = (own_platform / "auth_secret").read_text()
|
|
with TestClient(app):
|
|
pass
|
|
assert (own_platform / "auth_secret").read_text() == secret
|
|
assert client.get("/users/me").status_code == 200
|