Skip to content

Commit 24b7574

Browse files
add support for async export users endpoint (#186)
* add support for async export users endpoint * fix comment
1 parent efc2558 commit 24b7574

File tree

7 files changed

+45
-2
lines changed

7 files changed

+45
-2
lines changed

stream_chat/async_chat/client.py

+3
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,9 @@ async def export_channels(
776776
async def get_export_channel_status(self, task_id: str) -> StreamResponse:
777777
return await self.get(f"export_channels/{task_id}")
778778

779+
async def export_users(self, user_ids: Iterable[str]) -> StreamResponse:
780+
return await self.post("export/users", data={"user_ids": user_ids})
781+
779782
async def get_task(self, task_id: str) -> StreamResponse:
780783
return await self.get(f"tasks/{task_id}")
781784

stream_chat/base/client.py

+9
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,15 @@ def get_export_channel_status(
12131213
"""
12141214
pass
12151215

1216+
@abc.abstractmethod
1217+
def export_users(
1218+
self, user_ids: Iterable[str]
1219+
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
1220+
"""
1221+
Requests a users export
1222+
"""
1223+
pass
1224+
12161225
@abc.abstractmethod
12171226
def get_task(
12181227
self, task_id: str

stream_chat/client.py

+3
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,9 @@ def export_channels(
740740
def get_export_channel_status(self, task_id: str) -> StreamResponse:
741741
return self.get(f"export_channels/{task_id}")
742742

743+
def export_users(self, user_ids: Iterable[str]) -> StreamResponse:
744+
return self.post("export/users", data={"user_ids": user_ids})
745+
743746
def get_task(self, task_id: str) -> StreamResponse:
744747
return self.get(f"tasks/{task_id}")
745748

stream_chat/tests/async_chat/test_channel.py

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ async def test_send_message_with_options(self, channel: Channel, random_user: Di
5656
async def test_send_message_with_restricted_visibility(
5757
self, client: StreamChatAsync, channel: Channel, random_user: Dict
5858
):
59-
6059
# Create test users first
6160
restricted_users = [
6261
{"id": "amy", "name": "Amy"},

stream_chat/tests/async_chat/test_client.py

+17
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,23 @@ async def test_export_user(self, client: StreamChatAsync, fellowship_of_the_ring
207207
assert "user" in response
208208
assert response["user"]["name"] == "Gandalf the Grey"
209209

210+
async def test_export_users(self, client: StreamChatAsync, random_user: Dict):
211+
response = await client.export_users([random_user["id"]])
212+
assert "task_id" in response
213+
assert len(response["task_id"]) == 36
214+
215+
async def f():
216+
r = await client.get_task(response["task_id"])
217+
return r["status"] == "completed"
218+
219+
await wait_for_async(f)
220+
221+
response = await client.get_task(response["task_id"])
222+
assert response["status"] == "completed"
223+
assert "result" in response
224+
assert "url" in response["result"]
225+
assert "/exports/users/" in response["result"]["url"]
226+
210227
async def test_ban_user(
211228
self, client: StreamChatAsync, random_user, server_user: Dict
212229
):

stream_chat/tests/test_channel.py

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def test_send_pending_message(
6666
def test_send_message_with_restricted_visibility(
6767
self, client: StreamChat, channel: Channel, random_user: Dict
6868
):
69-
7069
# Create test users first
7170
restricted_users = [
7271
{"id": "amy", "name": "Amy"},

stream_chat/tests/test_client.py

+13
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,19 @@ def test_export_user(self, client: StreamChat, fellowship_of_the_ring):
210210
assert "user" in response
211211
assert response["user"]["name"] == "Gandalf the Grey"
212212

213+
def test_export_users(self, client: StreamChat, random_user: Dict):
214+
response = client.export_users([random_user["id"]])
215+
assert "task_id" in response
216+
assert len(response["task_id"]) == 36
217+
218+
wait_for(lambda: client.get_task(response["task_id"])["status"] == "completed")
219+
220+
response = client.get_task(response["task_id"])
221+
assert response["status"] == "completed"
222+
assert "result" in response
223+
assert "url" in response["result"]
224+
assert "/exports/users/" in response["result"]["url"]
225+
213226
def test_shadow_ban(
214227
self, client: StreamChat, random_user, server_user, channel: Channel
215228
):

0 commit comments

Comments
 (0)