File size: 2,305 Bytes
c4a298e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""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