Skip to content

Commit 7ce5634

Browse files
committed
Add tests for streaming, close_thread, multi-recipient
1 parent a624fa9 commit 7ce5634

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

tests/test_client.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,49 @@ def test_sync_shutdown(monkeypatch):
158158
resp = MockResponse()
159159
monkeypatch.setattr(client._http, "request", lambda *a, **kw: resp)
160160
client.shutdown() # should not raise
161+
162+
163+
def test_sync_send_close_thread(monkeypatch):
164+
client = toq.connect("http://localhost:9010")
165+
resp = MockResponse(json_data={"id": "m1", "status": "delivered", "thread_id": "t1", "timestamp": "now"})
166+
monkeypatch.setattr(client._http, "request", lambda *a, **kw: resp)
167+
result = client.send("toq://host/agent", "goodbye", close_thread=True)
168+
assert result["status"] == "delivered"
169+
170+
171+
def test_sync_send_multi_recipient(monkeypatch):
172+
client = toq.connect("http://localhost:9010")
173+
resp = MockResponse(json_data={
174+
"results": [
175+
{"to": "toq://host/a", "id": "m1", "thread_id": "t1", "status": "queued"},
176+
{"to": "toq://host/b", "id": "m2", "thread_id": "t2", "status": "queued"},
177+
],
178+
"timestamp": "now",
179+
})
180+
monkeypatch.setattr(client._http, "request", lambda *a, **kw: resp)
181+
result = client.send(["toq://host/a", "toq://host/b"], "hello both")
182+
assert len(result["results"]) == 2
183+
184+
185+
def test_sync_stream_start(monkeypatch):
186+
client = toq.connect("http://localhost:9010")
187+
resp = MockResponse(json_data={"stream_id": "s1", "thread_id": "t1"})
188+
monkeypatch.setattr(client._http, "request", lambda *a, **kw: resp)
189+
result = client.stream_start("toq://host/agent")
190+
assert result["stream_id"] == "s1"
191+
192+
193+
def test_sync_stream_chunk(monkeypatch):
194+
client = toq.connect("http://localhost:9010")
195+
resp = MockResponse(json_data={"chunk_id": "c1"})
196+
monkeypatch.setattr(client._http, "request", lambda *a, **kw: resp)
197+
result = client.stream_chunk("s1", "hello ")
198+
assert result["chunk_id"] == "c1"
199+
200+
201+
def test_sync_stream_end(monkeypatch):
202+
client = toq.connect("http://localhost:9010")
203+
resp = MockResponse(json_data={"chunk_id": "e1"})
204+
monkeypatch.setattr(client._http, "request", lambda *a, **kw: resp)
205+
result = client.stream_end("s1", close_thread=True)
206+
assert result["chunk_id"] == "e1"

0 commit comments

Comments
 (0)