File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments