Skip to content

Commit 276697a

Browse files
committed
test(backend): add basic pytest and run in CI (TEST_MODE=true)
1 parent 3deae2f commit 276697a

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,11 @@ jobs:
4848
- name: Basic syntax check
4949
run: python -m compileall -q backend
5050

51+
- name: Run backend tests
52+
env:
53+
TEST_MODE: "true"
54+
run: |
55+
pip install pytest
56+
pytest -q
57+
5158

tests/test_api.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import json
3+
import pytest
4+
5+
os.environ.setdefault("TEST_MODE", "true")
6+
7+
from backend.pdf_server import app # noqa: E402
8+
9+
10+
@pytest.fixture()
11+
def client():
12+
app.config.update(TESTING=True)
13+
with app.test_client() as c:
14+
yield c
15+
16+
17+
def test_health(client):
18+
resp = client.get("/api/test")
19+
assert resp.status_code == 200
20+
data = resp.get_json()
21+
assert data and data.get("status") == "ok"
22+
23+
24+
def test_report_sanitize_blocks_external(client):
25+
# Вставляем внешнюю ссылку — должна быть заблокирована санитайзером/url_fetcher
26+
report_html = """
27+
<html><body>
28+
<img src="http://example.com/evil.png" />
29+
<p>OK</p>
30+
</body></html>
31+
"""
32+
resp = client.post(
33+
"/api/report",
34+
data=json.dumps({"report_html": report_html}),
35+
content_type="application/json",
36+
)
37+
# WeasyPrint рендерит PDF байты; если внешние ссылки заблокированы — генерация не упадет
38+
assert resp.status_code in (200, 400, 500)
39+
# В happy-path ожидаем 200 и application/pdf в TEST_MODE
40+
if resp.status_code == 200:
41+
assert resp.mimetype == "application/pdf"
42+
43+

0 commit comments

Comments
 (0)