Разработана первая версия приложений
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import base64
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import yaml
|
||||
|
||||
from app.main import app, websocket_token
|
||||
|
||||
EXPECTED_PATHS = {
|
||||
"/health/live",
|
||||
"/health/ready",
|
||||
"/api/v1/public/app-config",
|
||||
"/api/v1/public/content",
|
||||
"/api/v1/auth/bootstrap",
|
||||
"/api/v1/consents",
|
||||
"/api/v1/analytics/session-start",
|
||||
"/api/v1/me",
|
||||
"/api/v1/me/documents",
|
||||
"/api/v1/documents/{document_id}",
|
||||
"/api/v1/documents/{document_id}/download-url",
|
||||
"/api/v1/dialogs",
|
||||
"/api/v1/dialogs/{dialog_id}",
|
||||
"/api/v1/dialogs/{dialog_id}/messages",
|
||||
"/api/v1/dialogs/{dialog_id}/attachments/init",
|
||||
"/api/v1/dialogs/{dialog_id}/attachments/{attachment_id}/complete",
|
||||
"/api/v1/dialogs/{dialog_id}/attachments/{attachment_id}/download-url",
|
||||
"/internal/openlines/v1/inbox",
|
||||
"/internal/settings/v1/otp",
|
||||
}
|
||||
|
||||
|
||||
def test_openapi_31_contains_all_http_contracts() -> None:
|
||||
schema = app.openapi()
|
||||
assert schema["openapi"].startswith("3.1.")
|
||||
assert EXPECTED_PATHS <= schema["paths"].keys()
|
||||
assert all(not path.startswith("/internal/safety") for path in schema["paths"])
|
||||
committed = yaml.safe_load(Path("openapi.yaml").read_text(encoding="utf-8"))
|
||||
assert committed["openapi"] == "3.1.0"
|
||||
assert committed["paths"].keys() == schema["paths"].keys()
|
||||
|
||||
|
||||
def test_websocket_route_is_registered() -> None:
|
||||
assert any(getattr(route, "path", None) == "/api/v1/realtime" for route in app.routes)
|
||||
|
||||
|
||||
def test_websocket_accepts_canonical_base64url_jwt_protocol() -> None:
|
||||
jwt = "header.payload.signature"
|
||||
encoded = base64.urlsafe_b64encode(jwt.encode()).decode().rstrip("=")
|
||||
websocket = SimpleNamespace(
|
||||
headers={"sec-websocket-protocol": f"han-chat-v1, han.jwt.{encoded}"},
|
||||
query_params={},
|
||||
)
|
||||
assert websocket_token(websocket) == (jwt, f"han.jwt.{encoded}")
|
||||
|
||||
|
||||
def test_committed_openapi_server_does_not_double_api_prefix() -> None:
|
||||
committed = yaml.safe_load(Path("openapi.yaml").read_text(encoding="utf-8"))
|
||||
assert committed["servers"] == [{"url": "/"}]
|
||||
Reference in New Issue
Block a user