Spaces:
Sleeping
Sleeping
| """Smoke tests for FastAPI endpoints.""" | |
| import json | |
| class TestHealthcheck: | |
| def test_health_returns_200(self, client): | |
| response = client.get("/health") | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert data["status"] == "ok" | |
| assert "timestamp" in data | |
| def test_root_returns_200(self, client): | |
| response = client.get("/") | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert data["status"] == "ready" | |
| class TestDownloadEmailNew: | |
| def test_empty_html_returns_400(self, client): | |
| response = client.post( | |
| "/api/templates/download-email-new", | |
| content=json.dumps({"html": ""}), | |
| headers={"Content-Type": "application/json"}, | |
| ) | |
| assert response.status_code == 400 | |
| assert "empty" in response.json()["detail"].lower() | |
| def test_whitespace_only_html_returns_400(self, client): | |
| response = client.post( | |
| "/api/templates/download-email-new", | |
| content=json.dumps({"html": " "}), | |
| headers={"Content-Type": "application/json"}, | |
| ) | |
| assert response.status_code == 400 | |
| def test_oversized_html_returns_400(self, client): | |
| huge_html = "<html>" + "x" * 600_000 + "</html>" | |
| response = client.post( | |
| "/api/templates/download-email-new", | |
| content=json.dumps({"html": huge_html}), | |
| headers={"Content-Type": "application/json"}, | |
| ) | |
| assert response.status_code == 400 | |
| assert "maximum size" in response.json()["detail"].lower() | |
| def test_valid_html_returns_200(self, client): | |
| response = client.post( | |
| "/api/templates/download-email-new", | |
| content=json.dumps({"html": "<html><body><p>Hello</p></body></html>"}), | |
| headers={"Content-Type": "application/json"}, | |
| ) | |
| assert response.status_code == 200 | |
| assert "html" in response.json() | |
| class TestPostProcess: | |
| def test_missing_html_returns_400(self, client): | |
| response = client.post( | |
| "/api/templates/post-process", | |
| content=json.dumps({"not_html": "value"}), | |
| headers={"Content-Type": "application/json"}, | |
| ) | |
| assert response.status_code == 400 | |