Skip to content

Commit 33dae65

Browse files
committed
Fix lint
1 parent bb002bd commit 33dae65

File tree

5 files changed

+70
-37
lines changed

5 files changed

+70
-37
lines changed

stream_chat/base/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def query_threads(
568568
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
569569
"""
570570
Allows you to query threads using filter and sort. You can find the complete list of supported operators in the query syntax section of the docs.
571-
571+
572572
:param filter: Filter conditions for the query
573573
:param sort: Sort conditions for the query
574574
:return: StreamResponse containing the threads

stream_chat/base/query_threads.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ def __init__(self):
1111
@property
1212
def url(self):
1313
return "threads"
14-
14+
1515
@abc.abstractmethod
16-
def query_threads(self, filter:Dict[str, Dict[str, Any]], sort:List[Dict[str, Any]], **options:Any) -> Union[StreamResponse, Awaitable[StreamResponse]]:
16+
def query_threads(
17+
self,
18+
filter: Dict[str, Dict[str, Any]],
19+
sort: List[Dict[str, Any]],
20+
**options: Any,
21+
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
1722
"""
1823
Get a list of threads given filter and sort options
1924

stream_chat/query_threads.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
from typing import Dict, List, Any, Union, Awaitable
1+
from typing import Any, Awaitable, Dict, List, Union
2+
23
from stream_chat.base.query_threads import QueryThreadsInterface
34
from stream_chat.types.stream_response import StreamResponse
45

6+
57
class QueryThreads(QueryThreadsInterface):
6-
def query_threads(self, filter:Dict[str, Dict[str, Any]], sort:List[Dict[str, Any]], **options:Any) -> Union[StreamResponse, Awaitable[StreamResponse]]:
7-
payload = {"filter":filter, "sort":sort, **options}
8+
def query_threads(
9+
self,
10+
filter: Dict[str, Dict[str, Any]],
11+
sort: List[Dict[str, Any]],
12+
**options: Any,
13+
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
14+
payload = {"filter": filter, "sort": sort, **options}
815
return self.client.post(self.url, data=payload)

stream_chat/tests/async_chat/test_query_threads.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,73 @@
1+
from typing import Any, Dict
2+
13
import pytest
2-
from typing import Dict, Any
34

45
from stream_chat.async_chat import StreamChatAsync
56
from stream_chat.types.stream_response import StreamResponse
67

8+
79
@pytest.mark.incremental
810
class TestQueryThreads:
911
@pytest.mark.asyncio
10-
async def test_query_threads(self, client: StreamChatAsync, channel, random_user: Dict):
12+
async def test_query_threads(
13+
self, client: StreamChatAsync, channel, random_user: Dict
14+
):
1115
# Create a thread with some messages
12-
parent_message = await channel.send_message({"text": "Parent message"}, random_user["id"])
16+
parent_message = await channel.send_message(
17+
{"text": "Parent message"}, random_user["id"]
18+
)
1319
thread_message = await channel.send_message(
1420
{"text": "Thread message", "parent_id": parent_message["message"]["id"]},
15-
random_user["id"]
21+
random_user["id"],
1622
)
1723

1824
# Query threads with filter and sort
1925
filter_conditions = {"parent_id": parent_message["message"]["id"]}
2026
sort_conditions = [{"field": "created_at", "direction": -1}]
21-
27+
2228
response = await client.query_threads(
23-
filter=filter_conditions,
24-
sort=sort_conditions
29+
filter=filter_conditions, sort=sort_conditions
2530
)
26-
31+
2732
assert isinstance(response, StreamResponse)
2833
assert "threads" in response
2934
assert len(response["threads"]) > 0
30-
35+
3136
# Verify the thread message is in the response
3237
thread = response["threads"][0]
3338
assert "latest_replies" in thread
3439
assert len(thread["latest_replies"]) > 0
3540
assert thread["latest_replies"][0]["text"] == thread_message["message"]["text"]
3641

3742
@pytest.mark.asyncio
38-
async def test_query_threads_with_options(self, client: StreamChatAsync, channel, random_user: Dict):
43+
async def test_query_threads_with_options(
44+
self, client: StreamChatAsync, channel, random_user: Dict
45+
):
3946
# Create a thread with multiple messages
40-
parent_message = await channel.send_message({"text": "Parent message"}, random_user["id"])
47+
parent_message = await channel.send_message(
48+
{"text": "Parent message"}, random_user["id"]
49+
)
4150
thread_messages = []
4251
for i in range(3):
4352
msg = await channel.send_message(
44-
{"text": f"Thread message {i}", "parent_id": parent_message["message"]["id"]},
45-
random_user["id"]
53+
{
54+
"text": f"Thread message {i}",
55+
"parent_id": parent_message["message"]["id"],
56+
},
57+
random_user["id"],
4658
)
4759
thread_messages.append(msg)
4860

4961
# Query threads with limit and offset
5062
filter_conditions = {"parent_id": parent_message["message"]["id"]}
5163
sort_conditions = [{"field": "created_at", "direction": -1}]
52-
64+
5365
response = await client.query_threads(
5466
filter=filter_conditions,
5567
sort=sort_conditions,
5668
limit=1,
5769
)
58-
70+
5971
assert isinstance(response, StreamResponse)
6072
assert "threads" in response
6173
assert len(response["threads"]) == 1

stream_chat/tests/test_query_threads.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,65 @@
1+
from typing import Any, Dict
2+
13
import pytest
2-
from typing import Dict, Any
34

45
from stream_chat import StreamChat
56
from stream_chat.types.stream_response import StreamResponse
67

8+
79
@pytest.mark.incremental
810
class TestQueryThreads:
911
def test_query_threads(self, client: StreamChat, channel, random_user: Dict):
10-
parent_message = channel.send_message({"text": "Parent message"}, random_user["id"])
12+
parent_message = channel.send_message(
13+
{"text": "Parent message"}, random_user["id"]
14+
)
1115
thread_message = channel.send_message(
1216
{"text": "Thread message", "parent_id": parent_message["message"]["id"]},
13-
random_user["id"]
17+
random_user["id"],
1418
)
1519

1620
filter_conditions = {"parent_id": parent_message["message"]["id"]}
1721
sort_conditions = [{"field": "created_at", "direction": -1}]
18-
22+
1923
response = client.query_threads(
20-
filter=filter_conditions,
21-
sort=sort_conditions,
22-
user_id=random_user["id"]
24+
filter=filter_conditions, sort=sort_conditions, user_id=random_user["id"]
2325
)
24-
26+
2527
assert isinstance(response, StreamResponse)
2628
assert "threads" in response
2729
assert len(response["threads"]) > 0
28-
30+
2931
thread = response["threads"][0]
3032
assert "latest_replies" in thread
3133
assert len(thread["latest_replies"]) > 0
3234
assert thread["latest_replies"][0]["text"] == thread_message["message"]["text"]
3335

34-
def test_query_threads_with_options(self, client: StreamChat, channel, random_user: Dict):
35-
parent_message = channel.send_message({"text": "Parent message"}, random_user["id"])
36+
def test_query_threads_with_options(
37+
self, client: StreamChat, channel, random_user: Dict
38+
):
39+
parent_message = channel.send_message(
40+
{"text": "Parent message"}, random_user["id"]
41+
)
3642
thread_messages = []
3743
for i in range(3):
3844
msg = channel.send_message(
39-
{"text": f"Thread message {i}", "parent_id": parent_message["message"]["id"]},
40-
random_user["id"]
45+
{
46+
"text": f"Thread message {i}",
47+
"parent_id": parent_message["message"]["id"],
48+
},
49+
random_user["id"],
4150
)
4251
thread_messages.append(msg)
4352

4453
filter_conditions = {"parent_id": parent_message["message"]["id"]}
4554
sort_conditions = [{"field": "created_at", "direction": -1}]
46-
55+
4756
response = client.query_threads(
4857
filter=filter_conditions,
4958
sort=sort_conditions,
5059
limit=1,
51-
user_id=random_user["id"]
60+
user_id=random_user["id"],
5261
)
53-
62+
5463
assert isinstance(response, StreamResponse)
5564
assert "threads" in response
5665
assert len(response["threads"]) == 1

0 commit comments

Comments
 (0)