feat. Mini UI to hide ugly 404s
This commit is contained in:
40
tests/test_main_pages.py
Normal file
40
tests/test_main_pages.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from gitea_codex_bot.main import app
|
||||
|
||||
|
||||
def test_root_returns_tailwind_landing_page() -> None:
|
||||
client = TestClient(app)
|
||||
|
||||
response = client.get("/")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers["content-type"].startswith("text/html")
|
||||
assert "Gitea Codex Review Bot" in response.text
|
||||
assert "cdn.tailwindcss.com" in response.text
|
||||
assert 'id="health-button"' in response.text
|
||||
assert 'id="health-modal"' in response.text
|
||||
assert 'fetch("/healthz"' in response.text
|
||||
|
||||
|
||||
def test_404_returns_tailwind_page_for_browser_requests() -> None:
|
||||
client = TestClient(app)
|
||||
|
||||
response = client.get("/missing", headers={"Accept": "text/html"})
|
||||
|
||||
assert response.status_code == 404
|
||||
assert response.headers["content-type"].startswith("text/html")
|
||||
assert "Error 404" in response.text
|
||||
assert "cdn.tailwindcss.com" in response.text
|
||||
|
||||
|
||||
def test_404_returns_json_for_non_browser_requests() -> None:
|
||||
client = TestClient(app)
|
||||
|
||||
response = client.get("/missing", headers={"Accept": "application/json"})
|
||||
|
||||
assert response.status_code == 404
|
||||
assert response.headers["content-type"].startswith("application/json")
|
||||
assert response.json() == {"detail": "Not Found"}
|
||||
Reference in New Issue
Block a user