Skip to content

Commit 5713873

Browse files
feat: adding tests
1 parent 0b5a594 commit 5713873

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

stream_chat/tests/async_chat/test_channel.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,59 @@ async def test_export_channel(
380380
assert "error" not in resp
381381
break
382382
time.sleep(0.5)
383+
384+
async def test_pin_channel(
385+
self, client: StreamChatAsync, channel: Channel, random_users: List[Dict]
386+
):
387+
user_id = random_users[0]["id"]
388+
await channel.add_members([user_id])
389+
390+
# Pin the channel
391+
response = await channel.pin(user_id)
392+
assert response is not None
393+
394+
# Query for pinned channels
395+
response = await client.query_channels(
396+
{"pinned": True, "cid": channel.cid}, user_id=user_id
397+
)
398+
assert len(response["channels"]) == 1
399+
assert response["channels"][0]["channel"]["cid"] == channel.cid
400+
401+
# Unpin the channel
402+
response = await channel.unpin(user_id)
403+
assert response is not None
404+
405+
# Query for pinned channels
406+
response = await client.query_channels(
407+
{"pinned": False, "cid": channel.cid}, user_id=user_id
408+
)
409+
assert len(response["channels"]) == 1
410+
assert response["channels"][0]["channel"]["cid"] == channel.cid
411+
412+
async def test_archive_channel(
413+
self, client: StreamChatAsync, channel: Channel, random_users: List[Dict]
414+
):
415+
user_id = random_users[0]["id"]
416+
await channel.add_members([user_id])
417+
418+
# Archive the channel
419+
response = await channel.archive(user_id)
420+
assert response is not None
421+
422+
# Query for archived channels
423+
response = await client.query_channels(
424+
{"archived": True, "cid": channel.cid}, user_id=user_id
425+
)
426+
assert len(response["channels"]) == 1
427+
assert response["channels"][0]["channel"]["cid"] == channel.cid
428+
429+
# Unarchive the channel
430+
response = await channel.unarchive(user_id)
431+
assert response is not None
432+
433+
# Query for archived channels
434+
response = await client.query_channels(
435+
{"archived": False, "cid": channel.cid}, user_id=user_id
436+
)
437+
assert len(response["channels"]) == 1
438+
assert response["channels"][0]["channel"]["cid"] == channel.cid

stream_chat/tests/test_channel.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ def test_pin_channel(
392392
response = client.query_channels(
393393
{"pinned": True, "cid": channel.cid}, user_id=user_id
394394
)
395-
print(response)
396395
assert len(response["channels"]) == 1
397396
assert response["channels"][0]["channel"]["cid"] == channel.cid
398397

@@ -406,3 +405,31 @@ def test_pin_channel(
406405
)
407406
assert len(response["channels"]) == 1
408407
assert response["channels"][0]["channel"]["cid"] == channel.cid
408+
409+
def test_archive_channel(
410+
self, client: StreamChat, channel: Channel, random_users: List[Dict]
411+
):
412+
user_id = random_users[0]["id"]
413+
channel.add_members([user_id])
414+
415+
# Archive the channel
416+
response = channel.archive(user_id)
417+
assert response is not None
418+
419+
# Query for archived channels
420+
response = client.query_channels(
421+
{"archived": True, "cid": channel.cid}, user_id=user_id
422+
)
423+
assert len(response["channels"]) == 1
424+
assert response["channels"][0]["channel"]["cid"] == channel.cid
425+
426+
# Unarchive the channel
427+
response = channel.unarchive(user_id)
428+
assert response is not None
429+
430+
# Query for archhived channels
431+
response = client.query_channels(
432+
{"archived": False, "cid": channel.cid}, user_id=user_id
433+
)
434+
assert len(response["channels"]) == 1
435+
assert response["channels"][0]["channel"]["cid"] == channel.cid

0 commit comments

Comments
 (0)