Skip to content

Commit 3f5a167

Browse files
committed
tests: add edge-case tests (large CSV, invalid requests); docs: testing section
1 parent 4d43c2d commit 3f5a167

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ TEST_MODE=true
177177
- Все функции работают, но без реального анализа
178178
- Полезно для тестирования интерфейса
179179

180+
## Тестирование и типизация
181+
182+
### Backend (pytest + mypy)
183+
```bash
184+
pytest -q # запустить тесты
185+
mypy backend # статическая проверка типов
186+
```
187+
В CI тесты выполняются с `TEST_MODE=true`, WeasyPrint и кэш анализа активны.
188+
180189
## Ограничения и особенности
181190

182191
### Размеры файлов

tests/test_edge_cases.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import io
2+
import os
3+
import json
4+
import pandas as pd
5+
import pytest
6+
7+
os.environ.setdefault("TEST_MODE", "true")
8+
from backend.pdf_server import app # noqa: E402
9+
10+
11+
@pytest.fixture()
12+
def client():
13+
app.config.update(TESTING=True)
14+
with app.test_client() as c:
15+
yield c
16+
17+
18+
def make_large_csv_bytes(rows=2000):
19+
df = pd.DataFrame([
20+
{
21+
"year": 2015 + (i % 5),
22+
"make": "Make" + str(i % 3),
23+
"model": "Model" + str(i % 7),
24+
"trim": "Base",
25+
"body": "Sedan",
26+
"transmission": "auto",
27+
"vin": f"VIN{i:06d}",
28+
"state": "ca",
29+
"condition": float((i % 10) + 1),
30+
"odometer": 1000 * i,
31+
"color": "black",
32+
"interior": "gray",
33+
"seller": "dealer",
34+
"mmr": 10000 + i,
35+
"sellingprice": 12000 + i,
36+
"saledate": "2015-01-01",
37+
} for i in range(rows)
38+
])
39+
bio = io.BytesIO(df.to_csv(index=False).encode("utf-8"))
40+
bio.seek(0)
41+
return bio
42+
43+
44+
def test_upload_large_csv_is_limited(client):
45+
# page_size=1000, должен вернуться ровно 1000 строк
46+
resp = client.post(
47+
"/api/upload?page=1&page_size=1000",
48+
content_type="multipart/form-data",
49+
data={"file": (make_large_csv_bytes(5000), "big.csv")},
50+
)
51+
assert resp.status_code == 200
52+
data = resp.get_json()
53+
assert len(data["table_data"]) == 1000
54+
assert data["total_rows"] >= 1000
55+
56+
57+
def test_upload_invalid_extension_rejected(client):
58+
bad_file = io.BytesIO(b"not a real data")
59+
resp = client.post(
60+
"/api/upload",
61+
content_type="multipart/form-data",
62+
data={"file": (bad_file, "data.txt")},
63+
)
64+
assert resp.status_code == 400
65+
j = resp.get_json()
66+
assert "error" in j
67+
68+
69+
def test_analyze_missing_fields_400(client):
70+
resp = client.post("/api/analyze", data=json.dumps({"provider": "openai"}), content_type="application/json")
71+
assert resp.status_code == 400
72+
73+

0 commit comments

Comments
 (0)