-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_api_endpoints.py
More file actions
119 lines (95 loc) · 4.95 KB
/
Copy pathtest_api_endpoints.py
File metadata and controls
119 lines (95 loc) · 4.95 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
from __future__ import annotations
from tests.conftest import HAPPY_BUBBLE_ID, HAPPY_COMPOSER_ID, HAPPY_WORKSPACE_ID
# ---------------------------------------------------------------------------
# GET /api/workspaces
# ---------------------------------------------------------------------------
class TestListWorkspaces:
def test_happy_path_returns_workspace_list(self, client):
response = client.get("/api/workspaces")
assert response.status_code == 200
body = response.get_json()
assert isinstance(body, list)
ids = [p["id"] for p in body]
assert HAPPY_WORKSPACE_ID in ids, f"expected {HAPPY_WORKSPACE_ID} in {ids}"
ws = next(p for p in body if p["id"] == HAPPY_WORKSPACE_ID)
assert "name" in ws
assert "conversationCount" in ws and isinstance(ws["conversationCount"], int)
assert "lastModified" in ws and "T" in ws["lastModified"]
def test_empty_storage_returns_empty_list(self, empty_workspace_client):
response = empty_workspace_client.get("/api/workspaces")
assert response.status_code == 200
assert response.get_json() == []
# ---------------------------------------------------------------------------
# GET /api/workspaces/<id>
# ---------------------------------------------------------------------------
class TestGetWorkspace:
def test_happy_path_returns_workspace_details(self, client):
response = client.get(f"/api/workspaces/{HAPPY_WORKSPACE_ID}")
assert response.status_code == 200
body = response.get_json()
assert body["id"] == HAPPY_WORKSPACE_ID
assert "name" in body
assert "folder" in body
assert "lastModified" in body and "T" in body["lastModified"]
def test_unknown_id_returns_404(self, client):
response = client.get("/api/workspaces/nonexistent-workspace-id")
assert response.status_code == 404
body = response.get_json()
assert "error" in body
def test_global_returns_other_chats(self, client):
response = client.get("/api/workspaces/global")
assert response.status_code == 200
body = response.get_json()
assert body["id"] == "global"
assert body["name"] == "Other chats"
# ---------------------------------------------------------------------------
# GET /api/workspaces/<id>/tabs
# ---------------------------------------------------------------------------
class TestGetWorkspaceTabs:
def test_happy_path_returns_tabs(self, client):
response = client.get(f"/api/workspaces/{HAPPY_WORKSPACE_ID}/tabs")
assert response.status_code == 200
body = response.get_json()
assert "tabs" in body and isinstance(body["tabs"], list)
tab_ids = [t["id"] for t in body["tabs"]]
assert HAPPY_COMPOSER_ID in tab_ids, f"expected {HAPPY_COMPOSER_ID} in {tab_ids}"
tab = next(t for t in body["tabs"] if t["id"] == HAPPY_COMPOSER_ID)
assert "title" in tab
assert "timestamp" in tab and isinstance(tab["timestamp"], int)
assert "bubbles" in tab and isinstance(tab["bubbles"], list)
# The seeded user bubble must be present
bubble_types = [b["type"] for b in tab["bubbles"]]
assert "user" in bubble_types
def test_global_returns_tabs(self, client):
response = client.get("/api/workspaces/global/tabs")
assert response.status_code == 200
body = response.get_json()
assert "tabs" in body and isinstance(body["tabs"], list)
def test_missing_global_storage_returns_404(self, empty_workspace_client):
response = empty_workspace_client.get("/api/workspaces/global/tabs")
assert response.status_code == 404
body = response.get_json()
assert "error" in body
# ---------------------------------------------------------------------------
# GET /api/search?q=...
# ---------------------------------------------------------------------------
class TestSearch:
def test_happy_path_finds_seeded_term(self, client):
response = client.get("/api/search?q=sentinel-grep")
assert response.status_code == 200
body = response.get_json()
assert "results" in body and isinstance(body["results"], list)
assert len(body["results"]) >= 1, f"expected sentinel match, got {body}"
def test_no_match_returns_empty_results(self, client):
response = client.get("/api/search?q=does-not-match-any-content-xyzzy")
assert response.status_code == 200
body = response.get_json()
assert "results" in body and body["results"] == []
def test_missing_q_returns_400_or_empty(self, client):
response = client.get("/api/search")
# Implementation may return 400 (missing required param) or 200 with empty.
# Both are reasonable for "no query supplied"; pin whichever shipped.
assert response.status_code in (200, 400)
if response.status_code == 200:
body = response.get_json()
assert "results" in body