Skip to content

Commit 50a1a8e

Browse files
author
Slava Bobik
committed
Added restricted_visibility tests
1 parent 35da0fa commit 50a1a8e

File tree

4 files changed

+161
-0
lines changed

4 files changed

+161
-0
lines changed

stream_chat/tests/async_chat/test_channel.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,29 @@ async def test_send_message_with_options(self, channel: Channel, random_user: Di
5353
assert "message" in response
5454
assert response["message"]["text"] == "hi"
5555

56+
async def test_send_message_with_restricted_visibility(
57+
self, client: StreamChatAsync, channel: Channel, random_user: Dict
58+
):
59+
60+
# Create test users first
61+
restricted_users = [
62+
{"id": "amy", "name": "Amy"},
63+
{"id": "paul", "name": "Paul"},
64+
]
65+
await client.upsert_users(restricted_users)
66+
67+
# Add users to channel
68+
await channel.add_members([u["id"] for u in restricted_users])
69+
70+
# Send message with restricted visibility
71+
response = await channel.send_message(
72+
{"text": "hi", "restricted_visibility": ["amy", "paul"]}, random_user["id"]
73+
)
74+
75+
assert "message" in response
76+
assert response["message"]["text"] == "hi"
77+
assert response["message"]["restricted_visibility"] == ["amy", "paul"]
78+
5679
async def test_send_event(self, channel: Channel, random_user: Dict):
5780
response = await channel.send_event({"type": "typing.start"}, random_user["id"])
5881
assert "event" in response

stream_chat/tests/async_chat/test_client.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,64 @@ async def test_update_message_partial(
325325
assert response["message"]["text"] == "helloworld"
326326
assert response["message"]["awesome"] is True
327327

328+
async def test_update_message_restricted_visibility(
329+
self, client: StreamChatAsync, channel: Channel, random_user: Dict
330+
):
331+
# Create test users first
332+
restricted_users = [
333+
{"id": "amy", "name": "Amy"},
334+
{"id": "paul", "name": "Paul"},
335+
]
336+
await client.upsert_users(restricted_users)
337+
338+
# Add users to channel
339+
await channel.add_members([u["id"] for u in restricted_users])
340+
341+
# Send initial message
342+
msg_id = str(uuid.uuid4())
343+
response = await channel.send_message(
344+
{"id": msg_id, "text": "hello world"}, random_user["id"]
345+
)
346+
assert response["message"]["text"] == "hello world"
347+
348+
# Update message with restricted visibility
349+
response = await client.update_message(
350+
{
351+
"id": msg_id,
352+
"text": "helloworld",
353+
"restricted_visibility": ["amy", "paul"],
354+
"user": {"id": response["message"]["user"]["id"]},
355+
}
356+
)
357+
assert response["message"]["text"] == "helloworld"
358+
assert response["message"]["restricted_visibility"] == ["amy", "paul"]
359+
360+
async def test_update_message_partial_restricted_visibility(
361+
self, client: StreamChatAsync, channel: Channel, random_user: Dict
362+
):
363+
# Create test users first
364+
restricted_users = [
365+
{"id": "amy", "name": "Amy"},
366+
{"id": "paul", "name": "Paul"},
367+
]
368+
client.upsert_users(restricted_users)
369+
370+
# Add users to channel
371+
channel.add_members([u["id"] for u in restricted_users])
372+
373+
msg_id = str(uuid.uuid4())
374+
response = await channel.send_message(
375+
{"id": msg_id, "text": "hello world"}, random_user["id"]
376+
)
377+
assert response["message"]["text"] == "hello world"
378+
response = await client.update_message_partial(
379+
msg_id,
380+
dict(set=dict(text="helloworld", restricted_visibility=["amy"])),
381+
random_user["id"],
382+
)
383+
384+
assert response["message"]["restricted_visibility"] == ["amy"]
385+
328386
async def test_delete_message(
329387
self, client: StreamChatAsync, channel: Channel, random_user: Dict
330388
):

stream_chat/tests/test_channel.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,28 @@ def test_send_pending_message(
6363
assert "message" in response
6464
assert response["message"]["text"] == "hi"
6565

66+
def test_send_message_with_restricted_visibility(
67+
self, client: StreamChat, channel: Channel, random_user: Dict
68+
):
69+
70+
# Create test users first
71+
restricted_users = [
72+
{"id": "amy", "name": "Amy"},
73+
{"id": "paul", "name": "Paul"},
74+
]
75+
client.upsert_users(restricted_users)
76+
77+
# Add users to channel
78+
channel.add_members([u["id"] for u in restricted_users])
79+
80+
# Send message with restricted visibility
81+
response = channel.send_message(
82+
{"text": "hi", "restricted_visibility": ["amy", "paul"]}, random_user["id"]
83+
)
84+
assert "message" in response
85+
assert response["message"]["text"] == "hi"
86+
assert response["message"]["restricted_visibility"] == ["amy", "paul"]
87+
6688
def test_send_event(self, channel: Channel, random_user: Dict):
6789
response = channel.send_event({"type": "typing.start"}, random_user["id"])
6890
assert "event" in response

stream_chat/tests/test_client.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,64 @@ def test_update_message_partial(
370370
assert response["message"]["text"] == "helloworld"
371371
assert response["message"]["awesome"] is True
372372

373+
def test_update_message_restricted_visibility(
374+
self, client: StreamChat, channel: Channel, random_user: Dict
375+
):
376+
# Create test users first
377+
restricted_users = [
378+
{"id": "amy", "name": "Amy"},
379+
{"id": "paul", "name": "Paul"},
380+
]
381+
client.upsert_users(restricted_users)
382+
383+
# Add users to channel
384+
channel.add_members([u["id"] for u in restricted_users])
385+
386+
# Send initial message
387+
msg_id = str(uuid.uuid4())
388+
response = channel.send_message(
389+
{"id": msg_id, "text": "hello world"}, random_user["id"]
390+
)
391+
assert response["message"]["text"] == "hello world"
392+
393+
# Update message with restricted visibility
394+
response = client.update_message(
395+
{
396+
"id": msg_id,
397+
"text": "helloworld",
398+
"restricted_visibility": ["amy", "paul"],
399+
"user": {"id": response["message"]["user"]["id"]},
400+
}
401+
)
402+
assert response["message"]["text"] == "helloworld"
403+
assert response["message"]["restricted_visibility"] == ["amy", "paul"]
404+
405+
def test_update_message_partial_restricted_visibility(
406+
self, client: StreamChat, channel: Channel, random_user: Dict
407+
):
408+
# Create test users first
409+
restricted_users = [
410+
{"id": "amy", "name": "Amy"},
411+
{"id": "paul", "name": "Paul"},
412+
]
413+
client.upsert_users(restricted_users)
414+
415+
# Add users to channel
416+
channel.add_members([u["id"] for u in restricted_users])
417+
418+
msg_id = str(uuid.uuid4())
419+
response = channel.send_message(
420+
{"id": msg_id, "text": "hello world"}, random_user["id"]
421+
)
422+
assert response["message"]["text"] == "hello world"
423+
response = client.update_message_partial(
424+
msg_id,
425+
dict(set=dict(text="helloworld", restricted_visibility=["amy"])),
426+
random_user["id"],
427+
)
428+
429+
assert response["message"]["restricted_visibility"] == ["amy"]
430+
373431
def test_delete_message(self, client: StreamChat, channel, random_user: Dict):
374432
msg_id = str(uuid.uuid4())
375433
channel.send_message({"id": msg_id, "text": "helloworld"}, random_user["id"])

0 commit comments

Comments
 (0)