|
1 | | -"""Tests for GET /api/search limit validation (issue #1 / Monday prerequisite).""" |
| 1 | +"""Tests for GET /api/search limit validation (issue #1 / Monday prerequisite). |
2 | 2 |
|
3 | | -from __future__ import annotations |
4 | | - |
5 | | -import shutil |
6 | | -from pathlib import Path |
7 | | - |
8 | | -import pytest |
9 | | - |
10 | | -from app import create_app |
| 3 | +The `client_single` fixture (one seeded session) is provided by tests/conftest.py. |
| 4 | +""" |
11 | 5 |
|
12 | | -FIXTURES = Path(__file__).parent / "fixtures" |
13 | | - |
14 | | - |
15 | | -@pytest.fixture |
16 | | -def client(tmp_path): |
17 | | - project_dir = tmp_path / "test-project" |
18 | | - project_dir.mkdir(parents=True) |
19 | | - shutil.copy(FIXTURES / "session_minimal.jsonl", project_dir / "session_abc123.jsonl") |
20 | | - app = create_app(base_dir=str(tmp_path)) |
21 | | - app.config["TESTING"] = True |
22 | | - return app.test_client() |
| 6 | +from __future__ import annotations |
23 | 7 |
|
24 | 8 |
|
25 | | -def test_limit_integer_string(client): |
26 | | - resp = client.get("/api/search?q=Hello&limit=10") |
| 9 | +def test_limit_integer_string(client_single): |
| 10 | + resp = client_single.get("/api/search?q=Hello&limit=10") |
27 | 11 | assert resp.status_code == 200 |
28 | 12 | assert isinstance(resp.get_json(), list) |
29 | 13 |
|
30 | 14 |
|
31 | | -def test_limit_float_string(client): |
32 | | - resp = client.get("/api/search?q=Hello&limit=1.5") |
| 15 | +def test_limit_float_string(client_single): |
| 16 | + resp = client_single.get("/api/search?q=Hello&limit=1.5") |
33 | 17 | assert resp.status_code == 400 |
34 | 18 | assert "error" in resp.get_json() |
35 | 19 |
|
36 | 20 |
|
37 | | -def test_limit_non_numeric(client): |
38 | | - resp = client.get("/api/search?q=Hello&limit=abc") |
| 21 | +def test_limit_non_numeric(client_single): |
| 22 | + resp = client_single.get("/api/search?q=Hello&limit=abc") |
39 | 23 | assert resp.status_code == 400 |
40 | 24 | assert "error" in resp.get_json() |
41 | 25 |
|
42 | 26 |
|
43 | | -def test_limit_default(client): |
44 | | - resp = client.get("/api/search?q=Hello") |
| 27 | +def test_limit_default(client_single): |
| 28 | + resp = client_single.get("/api/search?q=Hello") |
45 | 29 | assert resp.status_code == 200 |
46 | 30 |
|
47 | 31 |
|
48 | | -def test_limit_whitespace_defaults(client): |
49 | | - resp = client.get("/api/search?q=Hello&limit=%20%20%20") |
| 32 | +def test_limit_whitespace_defaults(client_single): |
| 33 | + resp = client_single.get("/api/search?q=Hello&limit=%20%20%20") |
50 | 34 | assert resp.status_code == 200 |
51 | 35 |
|
52 | 36 |
|
53 | | -def test_limit_zero(client): |
54 | | - resp = client.get("/api/search?q=Hello&limit=0") |
| 37 | +def test_limit_zero(client_single): |
| 38 | + resp = client_single.get("/api/search?q=Hello&limit=0") |
55 | 39 | assert resp.status_code == 400 |
56 | 40 | assert "error" in resp.get_json() |
57 | 41 |
|
58 | 42 |
|
59 | | -def test_limit_negative(client): |
60 | | - resp = client.get("/api/search?q=Hello&limit=-1") |
| 43 | +def test_limit_negative(client_single): |
| 44 | + resp = client_single.get("/api/search?q=Hello&limit=-1") |
61 | 45 | assert resp.status_code == 400 |
62 | 46 | assert "error" in resp.get_json() |
63 | 47 |
|
64 | 48 |
|
65 | | -def test_empty_query(client): |
66 | | - resp = client.get("/api/search?q=") |
| 49 | +def test_empty_query(client_single): |
| 50 | + resp = client_single.get("/api/search?q=") |
67 | 51 | assert resp.status_code == 200 |
68 | 52 | assert resp.get_json() == [] |
0 commit comments