Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added restricted_visibility tests #184

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions stream_chat/tests/async_chat/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ async def test_send_message_with_options(self, channel: Channel, random_user: Di
assert "message" in response
assert response["message"]["text"] == "hi"

async def test_send_message_with_restricted_visibility(
self, client: StreamChatAsync, channel: Channel, random_user: Dict
):

# Create test users first
restricted_users = [
{"id": "amy", "name": "Amy"},
{"id": "paul", "name": "Paul"},
]
await client.upsert_users(restricted_users)

# Add users to channel
await channel.add_members([u["id"] for u in restricted_users])

# Send message with restricted visibility
response = await channel.send_message(
{"text": "hi", "restricted_visibility": ["amy", "paul"]}, random_user["id"]
)

assert "message" in response
assert response["message"]["text"] == "hi"
assert response["message"]["restricted_visibility"] == ["amy", "paul"]

async def test_send_event(self, channel: Channel, random_user: Dict):
response = await channel.send_event({"type": "typing.start"}, random_user["id"])
assert "event" in response
Expand Down
58 changes: 58 additions & 0 deletions stream_chat/tests/async_chat/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,64 @@ async def test_update_message_partial(
assert response["message"]["text"] == "helloworld"
assert response["message"]["awesome"] is True

async def test_update_message_restricted_visibility(
self, client: StreamChatAsync, channel: Channel, random_user: Dict
):
# Create test users first
restricted_users = [
{"id": "amy", "name": "Amy"},
{"id": "paul", "name": "Paul"},
]
await client.upsert_users(restricted_users)

# Add users to channel
await channel.add_members([u["id"] for u in restricted_users])

# Send initial message
msg_id = str(uuid.uuid4())
response = await channel.send_message(
{"id": msg_id, "text": "hello world"}, random_user["id"]
)
assert response["message"]["text"] == "hello world"

# Update message with restricted visibility
response = await client.update_message(
{
"id": msg_id,
"text": "helloworld",
"restricted_visibility": ["amy", "paul"],
"user": {"id": response["message"]["user"]["id"]},
}
)
assert response["message"]["text"] == "helloworld"
assert response["message"]["restricted_visibility"] == ["amy", "paul"]

async def test_update_message_partial_restricted_visibility(
self, client: StreamChatAsync, channel: Channel, random_user: Dict
):
# Create test users first
restricted_users = [
{"id": "amy", "name": "Amy"},
{"id": "paul", "name": "Paul"},
]
client.upsert_users(restricted_users)

# Add users to channel
channel.add_members([u["id"] for u in restricted_users])

msg_id = str(uuid.uuid4())
response = await channel.send_message(
{"id": msg_id, "text": "hello world"}, random_user["id"]
)
assert response["message"]["text"] == "hello world"
response = await client.update_message_partial(
msg_id,
dict(set=dict(text="helloworld", restricted_visibility=["amy"])),
random_user["id"],
)

assert response["message"]["restricted_visibility"] == ["amy"]

async def test_delete_message(
self, client: StreamChatAsync, channel: Channel, random_user: Dict
):
Expand Down
22 changes: 22 additions & 0 deletions stream_chat/tests/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ def test_send_pending_message(
assert "message" in response
assert response["message"]["text"] == "hi"

def test_send_message_with_restricted_visibility(
self, client: StreamChat, channel: Channel, random_user: Dict
):

# Create test users first
restricted_users = [
{"id": "amy", "name": "Amy"},
{"id": "paul", "name": "Paul"},
]
client.upsert_users(restricted_users)

# Add users to channel
channel.add_members([u["id"] for u in restricted_users])

# Send message with restricted visibility
response = channel.send_message(
{"text": "hi", "restricted_visibility": ["amy", "paul"]}, random_user["id"]
)
assert "message" in response
assert response["message"]["text"] == "hi"
assert response["message"]["restricted_visibility"] == ["amy", "paul"]

def test_send_event(self, channel: Channel, random_user: Dict):
response = channel.send_event({"type": "typing.start"}, random_user["id"])
assert "event" in response
Expand Down
58 changes: 58 additions & 0 deletions stream_chat/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,64 @@ def test_update_message_partial(
assert response["message"]["text"] == "helloworld"
assert response["message"]["awesome"] is True

def test_update_message_restricted_visibility(
self, client: StreamChat, channel: Channel, random_user: Dict
):
# Create test users first
restricted_users = [
{"id": "amy", "name": "Amy"},
{"id": "paul", "name": "Paul"},
]
client.upsert_users(restricted_users)

# Add users to channel
channel.add_members([u["id"] for u in restricted_users])

# Send initial message
msg_id = str(uuid.uuid4())
response = channel.send_message(
{"id": msg_id, "text": "hello world"}, random_user["id"]
)
assert response["message"]["text"] == "hello world"

# Update message with restricted visibility
response = client.update_message(
{
"id": msg_id,
"text": "helloworld",
"restricted_visibility": ["amy", "paul"],
"user": {"id": response["message"]["user"]["id"]},
}
)
assert response["message"]["text"] == "helloworld"
assert response["message"]["restricted_visibility"] == ["amy", "paul"]

def test_update_message_partial_restricted_visibility(
self, client: StreamChat, channel: Channel, random_user: Dict
):
# Create test users first
restricted_users = [
{"id": "amy", "name": "Amy"},
{"id": "paul", "name": "Paul"},
]
client.upsert_users(restricted_users)

# Add users to channel
channel.add_members([u["id"] for u in restricted_users])

msg_id = str(uuid.uuid4())
response = channel.send_message(
{"id": msg_id, "text": "hello world"}, random_user["id"]
)
assert response["message"]["text"] == "hello world"
response = client.update_message_partial(
msg_id,
dict(set=dict(text="helloworld", restricted_visibility=["amy"])),
random_user["id"],
)

assert response["message"]["restricted_visibility"] == ["amy"]

def test_delete_message(self, client: StreamChat, channel, random_user: Dict):
msg_id = str(uuid.uuid4())
channel.send_message({"id": msg_id, "text": "helloworld"}, random_user["id"])
Expand Down