-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathtest_query_threads.py
More file actions
65 lines (52 loc) · 2.13 KB
/
test_query_threads.py
File metadata and controls
65 lines (52 loc) · 2.13 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
from typing import Dict
import pytest
from stream_chat import StreamChat
from stream_chat.types.stream_response import StreamResponse
@pytest.mark.incremental
class TestQueryThreads:
def test_query_threads(self, client: StreamChat, channel, random_user: Dict):
parent_message = channel.send_message(
{"text": "Parent message"}, random_user["id"]
)
thread_message = channel.send_message(
{"text": "Thread message", "parent_id": parent_message["message"]["id"]},
random_user["id"],
)
filter_conditions = {"parent_message_id": parent_message["message"]["id"]}
sort_conditions = [{"field": "created_at", "direction": -1}]
response = client.query_threads(
filter=filter_conditions, sort=sort_conditions, user_id=random_user["id"]
)
assert isinstance(response, StreamResponse)
assert "threads" in response
assert len(response["threads"]) > 0
thread = response["threads"][0]
assert "latest_replies" in thread
assert len(thread["latest_replies"]) > 0
assert thread["latest_replies"][0]["text"] == thread_message["message"]["text"]
def test_query_threads_with_options(
self, client: StreamChat, channel, random_user: Dict
):
for i in range(3):
parent_msg = channel.send_message(
{"text": f"Parent message {i}"}, random_user["id"]
)
channel.send_message(
{
"text": f"Thread message {i}",
"parent_id": parent_msg["message"]["id"],
},
random_user["id"],
)
filter_conditions = {"channel_cid": channel.cid}
sort_conditions = [{"field": "created_at", "direction": -1}]
response = client.query_threads(
filter=filter_conditions,
sort=sort_conditions,
limit=1,
user_id=random_user["id"],
)
assert isinstance(response, StreamResponse)
assert "threads" in response
assert len(response["threads"]) == 1
assert "next" in response