Skip to content

Commit 12572bf

Browse files
committed
fix: attempt to fix tests
1 parent 81c17e6 commit 12572bf

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

stream_chat/tests/async_chat/conftest.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,27 @@ async def channel(client: StreamChatAsync, random_user: Dict):
9393

9494
@pytest.fixture(scope="function")
9595
async def command(client: StreamChatAsync):
96+
try:
97+
commands = await client.list_commands()
98+
for cmd in commands.get("commands", []):
99+
if cmd.get("name") not in ("giphy", "imgur", "flag", "ban", "unban", "mute", "unmute"):
100+
try:
101+
await client.delete_command(cmd["name"])
102+
except Exception:
103+
pass
104+
except Exception:
105+
pass
106+
96107
response = await client.create_command(
97108
dict(name=str(uuid.uuid4()), description="My command")
98109
)
99110

100111
yield response["command"]
101112

102-
await client.delete_command(response["command"]["name"])
113+
try:
114+
await client.delete_command(response["command"]["name"])
115+
except Exception:
116+
pass
103117

104118

105119
@pytest.fixture(scope="function")
@@ -121,6 +135,10 @@ async def fellowship_of_the_ring(client: StreamChatAsync):
121135
},
122136
{"id": "peregrin-took", "name": "Peregrin Took", "race": "Hobbit", "age": 28},
123137
]
138+
try:
139+
await client.restore_users([m["id"] for m in members])
140+
except Exception:
141+
pass
124142
await client.upsert_users(members)
125143
channel = client.channel(
126144
"team", "fellowship-of-the-ring", {"members": [m["id"] for m in members]}

stream_chat/tests/async_chat/test_client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import json
23
import os
34
import sys
@@ -173,14 +174,14 @@ async def test_delete_users(self, client: StreamChatAsync, random_user: Dict):
173174
)
174175
assert "task_id" in response
175176

176-
for _ in range(20):
177+
for _ in range(60):
177178
response = await client.get_task(response["task_id"])
178179
if response["status"] == "completed" and response["result"][
179180
random_user["id"]
180181
] == {"status": "ok"}:
181182
return
182183

183-
time.sleep(1)
184+
await asyncio.sleep(1)
184185

185186
pytest.fail("task did not succeed")
186187

@@ -810,14 +811,14 @@ async def test_delete_channels(self, client: StreamChatAsync, channel: Channel):
810811
response = await client.delete_channels([channel.cid])
811812
assert "task_id" in response
812813

813-
for _ in range(20):
814+
for _ in range(60):
814815
response = await client.get_task(response["task_id"])
815816
if response["status"] == "completed" and response["result"][
816817
channel.cid
817818
] == {"status": "ok"}:
818819
return
819820

820-
time.sleep(1)
821+
await asyncio.sleep(1)
821822

822823
pytest.fail("task did not succeed")
823824

stream_chat/tests/conftest.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,27 @@ def channel(client: StreamChat, random_user: Dict):
8484

8585
@pytest.fixture(scope="function")
8686
def command(client: StreamChat):
87+
try:
88+
commands = client.list_commands()
89+
for cmd in commands.get("commands", []):
90+
if cmd.get("name") not in ("giphy", "imgur", "flag", "ban", "unban", "mute", "unmute"):
91+
try:
92+
client.delete_command(cmd["name"])
93+
except Exception:
94+
pass
95+
except Exception:
96+
pass
97+
8798
response = client.create_command(
8899
dict(name=str(uuid.uuid4()), description="My command")
89100
)
90101

91102
yield response["command"]
92103

93-
client.delete_command(response["command"]["name"])
104+
try:
105+
client.delete_command(response["command"]["name"])
106+
except Exception:
107+
pass
94108

95109

96110
@pytest.fixture(scope="module")
@@ -111,6 +125,10 @@ def fellowship_of_the_ring(client: StreamChat):
111125
},
112126
{"id": "peregrin-took", "name": "Peregrin Took", "race": "Hobbit", "age": 28},
113127
]
128+
try:
129+
client.restore_users([m["id"] for m in members])
130+
except Exception:
131+
pass
114132
client.upsert_users(members)
115133
channel = client.channel(
116134
"team", "fellowship-of-the-ring", {"members": [m["id"] for m in members]}

stream_chat/tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def test_delete_users(self, client: StreamChat, random_user: Dict):
229229
)
230230
assert "task_id" in response
231231

232-
for _ in range(20):
232+
for _ in range(60):
233233
response = client.get_task(response["task_id"])
234234
if response["status"] == "completed" and response["result"][
235235
random_user["id"]
@@ -818,7 +818,7 @@ def test_delete_channels(self, client: StreamChat, channel: Channel):
818818
response = client.delete_channels([channel.cid])
819819
assert "task_id" in response
820820

821-
for _ in range(20):
821+
for _ in range(60):
822822
response = client.get_task(response["task_id"])
823823
if response["status"] == "completed" and response["result"][
824824
channel.cid

0 commit comments

Comments
 (0)