1010from stream_chat .base .exceptions import StreamAPIException
1111
1212
13- @pytest .mark .incremental
1413class TestClient (object ):
1514 def test_normalize_sort (self , client ):
1615 expected = [
@@ -315,8 +314,36 @@ async def test_get_rate_limits(self, event_loop, client):
315314 > response ["server_side" ]["GetRateLimits" ]["remaining" ]
316315 )
317316
317+ @pytest .mark .xfail
318318 @pytest .mark .asyncio
319- async def test_search (self , event_loop , client , channel , random_user ):
319+ async def test_search_with_sort (self , client , channel , random_user ):
320+ text = str (uuid .uuid4 ())
321+ ids = ["0" + text , "1" + text ]
322+ await channel .send_message (
323+ {"text" : text , "id" : ids [0 ]},
324+ random_user ["id" ],
325+ )
326+ await channel .send_message (
327+ {"text" : text , "id" : ids [1 ]},
328+ random_user ["id" ],
329+ )
330+ response = await client .search (
331+ {"type" : "messaging" }, text , ** {"limit" : 1 , "sort" : [{"created_at" : - 1 }]}
332+ )
333+ # searches all channels so make sure at least one is found
334+ assert len (response ["results" ]) >= 1
335+ assert response ["next" ] is not None
336+ assert ids [1 ] == response ["results" ][0 ]["message" ]["id" ]
337+ response = await client .search (
338+ {"type" : "messaging" }, text , ** {"limit" : 1 , "next" : response ["next" ]}
339+ )
340+ assert len (response ["results" ]) >= 1
341+ assert response ["previous" ] is not None
342+ assert response ["next" ] is None
343+ assert ids [0 ] == response ["results" ][0 ]["message" ]["id" ]
344+
345+ @pytest .mark .asyncio
346+ async def test_search (self , client , channel , random_user ):
320347 query = "supercalifragilisticexpialidocious"
321348 await channel .send_message (
322349 {"text" : f"How many syllables are there in { query } ?" },
@@ -337,6 +364,45 @@ async def test_search(self, event_loop, client, channel, random_user):
337364 for message in response ["results" ]:
338365 assert query not in message ["message" ]["text" ]
339366
367+ @pytest .mark .asyncio
368+ async def test_search_message_filters (self , client , channel , random_user ):
369+ query = "supercalifragilisticexpialidocious"
370+ await channel .send_message (
371+ {"text" : f"How many syllables are there in { query } ?" },
372+ random_user ["id" ],
373+ )
374+ await channel .send_message (
375+ {"text" : "Does 'cious' count as one or two?" }, random_user ["id" ]
376+ )
377+ response = await client .search (
378+ {"type" : "messaging" },
379+ {"text" : {"$q" : query }},
380+ ** {
381+ "limit" : 2 ,
382+ "offset" : 0 ,
383+ },
384+ )
385+ assert len (response ["results" ]) >= 1
386+ assert query in response ["results" ][0 ]["message" ]["text" ]
387+
388+ @pytest .mark .asyncio
389+ async def test_search_offset_with_sort (self , client ):
390+ query = "supercalifragilisticexpialidocious"
391+ with pytest .raises (ValueError ):
392+ await client .search (
393+ {"type" : "messaging" },
394+ query ,
395+ ** {"limit" : 2 , "offset" : 1 , "sort" : [{"created_at" : - 1 }]},
396+ )
397+
398+ @pytest .mark .asyncio
399+ async def test_search_offset_with_next (self , client ):
400+ query = "supercalifragilisticexpialidocious"
401+ with pytest .raises (ValueError ):
402+ await client .search (
403+ {"type" : "messaging" }, query , ** {"limit" : 2 , "offset" : 1 , "next" : query }
404+ )
405+
340406 @pytest .mark .asyncio
341407 async def test_query_channels_members_in (
342408 self , event_loop , client , fellowship_of_the_ring
0 commit comments