Skip to content

Commit 8eeb5c7

Browse files
amalshaji-plivobevenky
authored andcommitted
Migrate agent API test mocks to new Plivo-style response format
POST/action endpoints return 201 with api_id + message, list endpoints use objects/meta with limit/offset/total_count pagination, GET endpoints include api_id at root. Updates docstrings accordingly.
1 parent 7c3a021 commit 8eeb5c7

2 files changed

Lines changed: 64 additions & 24 deletions

File tree

src/plivo_agentstack/agent/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ async def get(self, agent_uuid: str) -> dict:
3737
async def list(self, **params: Any) -> dict:
3838
"""GET /Agent -- paginated list.
3939
40-
Optional query params: page, per_page, sort_by, sort_order,
40+
Optional query params: limit, offset, sort_by, sort_order,
4141
agent_mode, participant_mode.
4242
43-
Returns ``{"data": [...], "meta": {"page", "per_page", "total", "total_pages"}}``.
43+
Returns ``{"api_id": "...", "objects": [...],
44+
"meta": {"limit", "offset", "total_count", "previous", "next"}}``.
4445
"""
4546
return await self._http.request("GET", f"{self._prefix}/Agent", params=params)
4647

@@ -157,7 +158,7 @@ def __init__(self, http: HttpTransport, prefix: str) -> None:
157158
async def list(self, agent_uuid: str, **params: Any) -> dict:
158159
"""GET /Agent/{agent_uuid}/Session -- list sessions.
159160
160-
Optional query params: page, per_page, sort_by, sort_order, agent_mode.
161+
Optional query params: limit, offset, sort_by, sort_order, agent_mode.
161162
"""
162163
return await self._http.request(
163164
"GET", f"{self._prefix}/Agent/{agent_uuid}/Session", params=params

tests/test_agent/test_client.py

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ async def test_create_agent(mock_api, http_transport):
1414
"""POST /v1/Account/TESTAUTH123/Agent creates an agent."""
1515
mock_api.post("/v1/Account/TESTAUTH123/Agent").mock(
1616
return_value=httpx.Response(
17-
200,
18-
json={"agent_uuid": AGENT_UUID, "agent_name": "My Agent"},
17+
201,
18+
json={
19+
"api_id": "abc-123",
20+
"message": "agent created",
21+
"agent_uuid": AGENT_UUID,
22+
"agent_name": "My Agent",
23+
},
1924
)
2025
)
2126
client = AgentClient(http_transport)
@@ -29,7 +34,7 @@ async def test_get_agent(mock_api, http_transport):
2934
mock_api.get(f"/v1/Account/TESTAUTH123/Agent/{AGENT_UUID}").mock(
3035
return_value=httpx.Response(
3136
200,
32-
json={"agent_uuid": AGENT_UUID, "agent_name": "My Agent"},
37+
json={"api_id": "abc-123", "agent_uuid": AGENT_UUID, "agent_name": "My Agent"},
3338
)
3439
)
3540
client = AgentClient(http_transport)
@@ -42,21 +47,31 @@ async def test_list_agents(mock_api, http_transport):
4247
mock_api.get("/v1/Account/TESTAUTH123/Agent").mock(
4348
return_value=httpx.Response(
4449
200,
45-
json={"data": [{"agent_uuid": AGENT_UUID}], "meta": {"total": 1}},
50+
json={
51+
"api_id": "abc-123",
52+
"objects": [{"agent_uuid": AGENT_UUID}],
53+
"meta": {
54+
"limit": 10,
55+
"offset": 0,
56+
"total_count": 1,
57+
"previous": None,
58+
"next": None,
59+
},
60+
},
4661
)
4762
)
4863
client = AgentClient(http_transport)
49-
result = await client.agents.list(page=1, per_page=10)
50-
assert result["meta"]["total"] == 1
51-
assert len(result["data"]) == 1
64+
result = await client.agents.list(limit=10, offset=0)
65+
assert result["meta"]["total_count"] == 1
66+
assert len(result["objects"]) == 1
5267

5368

5469
async def test_update_agent(mock_api, http_transport):
5570
"""PATCH /v1/Account/TESTAUTH123/Agent/{uuid} updates an agent."""
5671
mock_api.patch(f"/v1/Account/TESTAUTH123/Agent/{AGENT_UUID}").mock(
5772
return_value=httpx.Response(
5873
200,
59-
json={"agent_uuid": AGENT_UUID, "agent_name": "Updated Agent"},
74+
json={"api_id": "abc-123", "agent_uuid": AGENT_UUID, "agent_name": "Updated Agent"},
6075
)
6176
)
6277
client = AgentClient(http_transport)
@@ -78,8 +93,13 @@ async def test_call_initiate(mock_api, http_transport):
7893
"""POST /v1/Account/TESTAUTH123/AgentCall initiates an outbound call."""
7994
mock_api.post("/v1/Account/TESTAUTH123/AgentCall").mock(
8095
return_value=httpx.Response(
81-
200,
82-
json={"call_uuid": CALL_UUID, "status": "initiated"},
96+
201,
97+
json={
98+
"api_id": "abc-123",
99+
"message": "call initiated",
100+
"call_uuid": CALL_UUID,
101+
"status": "initiated",
102+
},
83103
)
84104
)
85105
client = AgentClient(http_transport)
@@ -96,26 +116,37 @@ async def test_call_connect(mock_api, http_transport):
96116
"""POST /v1/Account/TESTAUTH123/AgentCall/{uuid}/connect connects a call to an agent."""
97117
mock_api.post(f"/v1/Account/TESTAUTH123/AgentCall/{CALL_UUID}/connect").mock(
98118
return_value=httpx.Response(
99-
200,
100-
json={"status": "connected"},
119+
201,
120+
json={
121+
"api_id": "abc-123",
122+
"message": "call connected",
123+
"agent_session_id": "sess-001",
124+
"status": "connecting",
125+
},
101126
)
102127
)
103128
client = AgentClient(http_transport)
104129
result = await client.calls.connect(CALL_UUID, AGENT_UUID)
105-
assert result["status"] == "connected"
130+
assert result["status"] == "connecting"
131+
assert result["agent_session_id"] == "sess-001"
106132

107133

108134
async def test_number_assign(mock_api, http_transport):
109135
"""POST /v1/Account/TESTAUTH123/Agent/{uuid}/Number assigns a number to an agent."""
110136
mock_api.post(f"/v1/Account/TESTAUTH123/Agent/{AGENT_UUID}/Number").mock(
111137
return_value=httpx.Response(
112-
200,
113-
json={"status": "assigned", "number": "+14155551234"},
138+
201,
139+
json={
140+
"api_id": "abc-123",
141+
"message": "number assigned",
142+
"agent_uuid": AGENT_UUID,
143+
"number": "+14155551234",
144+
},
114145
)
115146
)
116147
client = AgentClient(http_transport)
117148
result = await client.numbers.assign(AGENT_UUID, "+14155551234")
118-
assert result["status"] == "assigned"
149+
assert result["message"] == "number assigned"
119150
assert result["number"] == "+14155551234"
120151

121152

@@ -139,17 +170,24 @@ async def test_session_list(mock_api, http_transport):
139170
return_value=httpx.Response(
140171
200,
141172
json={
142-
"data": [
173+
"api_id": "abc-123",
174+
"objects": [
143175
{"agent_session_id": SESSION_ID, "duration_seconds": 120}
144176
],
145-
"meta": {"total": 1},
177+
"meta": {
178+
"limit": 10,
179+
"offset": 0,
180+
"total_count": 1,
181+
"previous": None,
182+
"next": None,
183+
},
146184
},
147185
)
148186
)
149187
client = AgentClient(http_transport)
150-
result = await client.sessions.list(AGENT_UUID, page=1, per_page=10)
151-
assert result["meta"]["total"] == 1
152-
assert result["data"][0]["agent_session_id"] == SESSION_ID
188+
result = await client.sessions.list(AGENT_UUID, limit=10, offset=0)
189+
assert result["meta"]["total_count"] == 1
190+
assert result["objects"][0]["agent_session_id"] == SESSION_ID
153191

154192

155193
async def test_session_get(mock_api, http_transport):
@@ -158,6 +196,7 @@ async def test_session_get(mock_api, http_transport):
158196
return_value=httpx.Response(
159197
200,
160198
json={
199+
"api_id": "abc-123",
161200
"agent_session_id": SESSION_ID,
162201
"agent_uuid": AGENT_UUID,
163202
"duration_seconds": 120,

0 commit comments

Comments
 (0)