Download tests/test_api_contract.py from vivekchakraverty/gamemaster-design-copilot: direct link, hf CLI and curl.
- Browser
- Download file 1.54 kB
-
https://huggingface.co/spaces/vivekchakraverty/gamemaster-design-copilot/resolve/main/tests/test_api_contract.py
- Command line
-
hf download hf://spaces/vivekchakraverty/gamemaster-design-copilot/tests/test_api_contract.py
-
curl -L -o test_api_contract.py https://huggingface.co/spaces/vivekchakraverty/gamemaster-design-copilot/resolve/main/tests/test_api_contract.py
1.54 kB
| import pytest | |
| fastapi = pytest.importorskip("fastapi") | |
| from fastapi.testclient import TestClient # noqa: E402 | |
| from app import app # noqa: E402 | |
| def test_root_serves_ui_without_redirect() -> None: | |
| client = TestClient(app) | |
| response = client.get("/", follow_redirects=False) | |
| assert response.status_code == 200 | |
| assert "text/html" in response.headers["content-type"] | |
| def test_api_chat_valid_request() -> None: | |
| client = TestClient(app) | |
| response = client.post( | |
| "/api/chat", | |
| json={ | |
| "message": "Give me a risk reward mechanic for stamina.", | |
| "project_context": "Tactical fantasy RPG.", | |
| "mode": "balance", | |
| "retrieval_k": 0, | |
| }, | |
| ) | |
| assert response.status_code == 200 | |
| body = response.json() | |
| assert set(body) == {"answer", "citations", "retrieved_chunks", "warnings"} | |
| assert "No approved source context" in body["answer"] | |
| def test_api_chat_rejects_empty_message() -> None: | |
| client = TestClient(app) | |
| response = client.post( | |
| "/api/chat", | |
| json={"message": " ", "project_context": "", "mode": "balance", "retrieval_k": 4}, | |
| ) | |
| assert response.status_code == 422 | |
| def test_api_chat_rejects_bad_mode_and_k() -> None: | |
| client = TestClient(app) | |
| response = client.post( | |
| "/api/chat", | |
| json={ | |
| "message": "Test", | |
| "project_context": "", | |
| "mode": "bad_mode", | |
| "retrieval_k": 20, | |
| }, | |
| ) | |
| assert response.status_code == 422 | |