Download test_api_v14.py from Hfzune/Test: direct link, hf CLI and curl.
- Browser
- Download file 1.67 kB
-
https://huggingface.co/spaces/Hfzune/Test/resolve/main/test_api_v14.py
- Command line
-
hf download hf://spaces/Hfzune/Test/test_api_v14.py
-
curl -L -o test_api_v14.py https://huggingface.co/spaces/Hfzune/Test/resolve/main/test_api_v14.py
1.67 kB
| #!/usr/bin/env python3 | |
| """FastAPI smoke tests for the TTT v1.4 Space app.""" | |
| from fastapi.testclient import TestClient | |
| import app as ttt_app | |
| from ttt_codec_v14 import HEADER, MAGIC, NAME_TO_CODEC | |
| def main() -> int: | |
| client = TestClient(ttt_app.app) | |
| r = client.get("/health") | |
| assert r.status_code == 200 and r.json()["packet_format"] == "TTT4" | |
| print("PASS GET /health") | |
| original = "TTT v1.4 API — exact bytes 🌏".encode("utf-8") | |
| encoded = client.post("/encode?mode=auto", content=original) | |
| assert encoded.status_code == 200, encoded.text | |
| assert encoded.headers.get("x-ttt-version") == "1.4.0" | |
| print(f"PASS POST /encode ({len(original)} -> {len(encoded.content)} bytes)") | |
| decoded = client.post("/decode", content=encoded.content) | |
| assert decoded.status_code == 200 and decoded.content == original | |
| print("PASS POST /decode exact byte match") | |
| bad = client.post("/decode", content=b"not a packet") | |
| assert bad.status_code == 400 | |
| malformed_gzip = HEADER.pack(MAGIC, NAME_TO_CODEC["gzip"], 12, 0) + b"not gzip" | |
| bad_payload = client.post("/decode", content=malformed_gzip) | |
| assert bad_payload.status_code == 400, bad_payload.text | |
| print("PASS POST /decode rejects invalid/corrupt packets") | |
| root = client.get("/", follow_redirects=False) | |
| assert root.status_code in (307, 308) and root.headers.get("location", "").startswith("/ui"), root.status_code | |
| ui = client.get("/ui/") | |
| assert ui.status_code == 200, ui.status_code | |
| print("PASS root redirect and mounted Gradio UI") | |
| print("ALL TTT v1.4 API TESTS PASSED") | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |