From 677fd04811973d7a6d6c2846e3b4b93621735157 Mon Sep 17 00:00:00 2001 From: Jimmy Pettersson Date: Mon, 17 Feb 2025 14:34:43 +0100 Subject: [PATCH 1/2] add support for async export users endpoint --- stream_chat/async_chat/client.py | 3 +++ stream_chat/base/client.py | 9 +++++++++ stream_chat/client.py | 3 +++ stream_chat/tests/async_chat/test_channel.py | 1 - stream_chat/tests/async_chat/test_client.py | 17 +++++++++++++++++ stream_chat/tests/test_channel.py | 1 - stream_chat/tests/test_client.py | 13 +++++++++++++ 7 files changed, 45 insertions(+), 2 deletions(-) diff --git a/stream_chat/async_chat/client.py b/stream_chat/async_chat/client.py index 7711cd35..b7a10997 100644 --- a/stream_chat/async_chat/client.py +++ b/stream_chat/async_chat/client.py @@ -776,6 +776,9 @@ async def export_channels( async def get_export_channel_status(self, task_id: str) -> StreamResponse: return await self.get(f"export_channels/{task_id}") + async def export_users(self, user_ids: Iterable[str]) -> StreamResponse: + return await self.post("export/users", data={"user_ids": user_ids}) + async def get_task(self, task_id: str) -> StreamResponse: return await self.get(f"tasks/{task_id}") diff --git a/stream_chat/base/client.py b/stream_chat/base/client.py index 6bb968b9..22602590 100644 --- a/stream_chat/base/client.py +++ b/stream_chat/base/client.py @@ -1213,6 +1213,15 @@ def get_export_channel_status( """ pass + @abc.abstractmethod + def export_users( + self, user_ids: Iterable[str] + ) -> Union[StreamResponse, Awaitable[StreamResponse]]: + """ + Requests a channels export + """ + pass + @abc.abstractmethod def get_task( self, task_id: str diff --git a/stream_chat/client.py b/stream_chat/client.py index 5489035c..85c1e8b9 100644 --- a/stream_chat/client.py +++ b/stream_chat/client.py @@ -740,6 +740,9 @@ def export_channels( def get_export_channel_status(self, task_id: str) -> StreamResponse: return self.get(f"export_channels/{task_id}") + def export_users(self, user_ids: Iterable[str]) -> StreamResponse: + return self.post("export/users", data={"user_ids": user_ids}) + def get_task(self, task_id: str) -> StreamResponse: return self.get(f"tasks/{task_id}") diff --git a/stream_chat/tests/async_chat/test_channel.py b/stream_chat/tests/async_chat/test_channel.py index 2ec76044..62ca36d4 100644 --- a/stream_chat/tests/async_chat/test_channel.py +++ b/stream_chat/tests/async_chat/test_channel.py @@ -56,7 +56,6 @@ async def test_send_message_with_options(self, channel: Channel, random_user: Di 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"}, diff --git a/stream_chat/tests/async_chat/test_client.py b/stream_chat/tests/async_chat/test_client.py index 2190df28..550d5c83 100644 --- a/stream_chat/tests/async_chat/test_client.py +++ b/stream_chat/tests/async_chat/test_client.py @@ -207,6 +207,23 @@ async def test_export_user(self, client: StreamChatAsync, fellowship_of_the_ring assert "user" in response assert response["user"]["name"] == "Gandalf the Grey" + async def test_export_users(self, client: StreamChatAsync, random_user: Dict): + response = await client.export_users([random_user["id"]]) + assert "task_id" in response + assert len(response["task_id"]) == 36 + + async def f(): + r = await client.get_task(response["task_id"]) + return r["status"] == "completed" + + await wait_for_async(f) + + response = await client.get_task(response["task_id"]) + assert response["status"] == "completed" + assert "result" in response + assert "url" in response["result"] + assert "/exports/users/" in response["result"]["url"] + async def test_ban_user( self, client: StreamChatAsync, random_user, server_user: Dict ): diff --git a/stream_chat/tests/test_channel.py b/stream_chat/tests/test_channel.py index 5972490e..ddec1d51 100644 --- a/stream_chat/tests/test_channel.py +++ b/stream_chat/tests/test_channel.py @@ -66,7 +66,6 @@ def test_send_pending_message( 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"}, diff --git a/stream_chat/tests/test_client.py b/stream_chat/tests/test_client.py index f66c3e82..85a24b8e 100644 --- a/stream_chat/tests/test_client.py +++ b/stream_chat/tests/test_client.py @@ -210,6 +210,19 @@ def test_export_user(self, client: StreamChat, fellowship_of_the_ring): assert "user" in response assert response["user"]["name"] == "Gandalf the Grey" + def test_export_users(self, client: StreamChat, random_user: Dict): + response = client.export_users([random_user["id"]]) + assert "task_id" in response + assert len(response["task_id"]) == 36 + + wait_for(lambda: client.get_task(response["task_id"])["status"] == "completed") + + response = client.get_task(response["task_id"]) + assert response["status"] == "completed" + assert "result" in response + assert "url" in response["result"] + assert "/exports/users/" in response["result"]["url"] + def test_shadow_ban( self, client: StreamChat, random_user, server_user, channel: Channel ): From eb4af5cc5f18593e5d8fbf5161b20eb6b4ed2dae Mon Sep 17 00:00:00 2001 From: Jimmy Pettersson Date: Mon, 17 Feb 2025 14:35:53 +0100 Subject: [PATCH 2/2] fix comment --- stream_chat/base/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stream_chat/base/client.py b/stream_chat/base/client.py index 22602590..a8b624b4 100644 --- a/stream_chat/base/client.py +++ b/stream_chat/base/client.py @@ -1218,7 +1218,7 @@ def export_users( self, user_ids: Iterable[str] ) -> Union[StreamResponse, Awaitable[StreamResponse]]: """ - Requests a channels export + Requests a users export """ pass