C1a: code only, no comments, no Markdown
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.
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
"""The Conectar dialog's API: an operator who knows nothing of dlt picks a kind of source,
|
||||
answers its questions, and "Probar conexión" says in plain words what it found."""
|
||||
|
||||
import sqlite3
|
||||
|
||||
import pytest
|
||||
@@ -87,13 +84,13 @@ def test_a_sign_in_button_without_an_app_registration_says_who_must_register_one
|
||||
def test_signing_in_hands_the_account_to_the_dialog(client, monkeypatch, tmp_path):
|
||||
from authlib.integrations.httpx_client import OAuth2Client, oauth2_client
|
||||
|
||||
httpx = oauth2_client.httpx2 # the HTTP library this authlib is built on
|
||||
httpx = oauth2_client.httpx2
|
||||
|
||||
monkeypatch.setenv("MICROSOFT_CLIENT_ID", "app")
|
||||
monkeypatch.setenv("MICROSOFT_CLIENT_SECRET", "app-secret")
|
||||
exchanged = {}
|
||||
|
||||
def provider(request: httpx.Request) -> httpx.Response: # the token endpoint
|
||||
def provider(request: httpx.Request) -> httpx.Response:
|
||||
exchanged["body"] = request.content.decode()
|
||||
return httpx.Response(200, json={"access_token": "at", "refresh_token": "rt",
|
||||
"token_type": "Bearer", "expires_in": 3600}) # fmt: skip
|
||||
@@ -104,7 +101,7 @@ def test_signing_in_hands_the_account_to_the_dialog(client, monkeypatch, tmp_pat
|
||||
transport=httpx.MockTransport(provider)) # fmt: skip
|
||||
|
||||
monkeypatch.setattr(sources, "_client", client_for)
|
||||
monkeypatch.setattr(sources, "PENDING", tmp_path / "pending") # any worker's callback
|
||||
monkeypatch.setattr(sources, "PENDING", tmp_path / "pending")
|
||||
monkeypatch.setattr(sources, "account", lambda p, token, env: {
|
||||
"user": "ana@hospital.mx", "drive_id": "d1",
|
||||
"oauth2_client_params": {"client_id": env["client_id"], "token": token}}) # fmt: skip
|
||||
@@ -119,7 +116,7 @@ def test_signing_in_hands_the_account_to_the_dialog(client, monkeypatch, tmp_pat
|
||||
assert "code_verifier=" in exchanged["body"] and "code=c0de" in exchanged["body"]
|
||||
again = client.get("/ingest/sources/oauth/microsoft/callback",
|
||||
params={"state": start["state"], "code": "c0de"}) # fmt: skip
|
||||
assert again.status_code == 400 # a sign-in is used once
|
||||
assert again.status_code == 400
|
||||
|
||||
|
||||
def test_a_saved_account_shows_who_but_never_its_tokens():
|
||||
|
||||
+3
-7
@@ -1,6 +1,3 @@
|
||||
"""Sign-in for the web app: an administrator from the environment, users who see some
|
||||
domains, a session cookie, and an API that answers everyone as before."""
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
@@ -32,11 +29,10 @@ def test_the_first_administrator_signs_in_and_adds_a_team(client):
|
||||
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 # not an admin
|
||||
assert client.post("/users/register", json=other).status_code == 403
|
||||
|
||||
|
||||
def test_the_api_answers_without_a_session(client):
|
||||
# routes that read no platform data (the in-process app's database is the default one)
|
||||
for path in ("/health", "/domains", "/ingest/schema", "/ingest/sources/types"):
|
||||
assert client.get(path).status_code == 200, path
|
||||
|
||||
@@ -44,7 +40,7 @@ def test_the_api_answers_without_a_session(client):
|
||||
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): # the app starts again on the same data
|
||||
with TestClient(app):
|
||||
pass
|
||||
assert (own_platform / "auth_secret").read_text() == secret
|
||||
assert client.get("/users/me").status_code == 200 # the session still holds
|
||||
assert client.get("/users/me").status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user