Skip to content

Commit fbab38e

Browse files
authored
test: improve tests (#117)
1 parent 50289e7 commit fbab38e

File tree

5 files changed

+61
-14
lines changed

5 files changed

+61
-14
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
if: ${{ matrix.python == '3.7' }}
4040
run: make lint
4141

42-
- name: Install, test and code coverage with ${{ matrix.python }}
42+
- name: Test with ${{ matrix.python }}
4343
env:
4444
STREAM_KEY: ${{ secrets.STREAM_KEY }}
4545
STREAM_SECRET: ${{ secrets.STREAM_SECRET }}

stream_chat/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def send_file(
428428
f"{self.base_url}/{uri}",
429429
params=self.get_default_params(),
430430
data={"user": json.dumps(user)},
431-
files={"file": (name, content, content_type)},
431+
files={"file": (name, content, content_type)}, # type: ignore
432432
headers=headers,
433433
)
434434
return self._parse_response(response)

stream_chat/tests/async_chat/conftest.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ async def random_user(client: StreamChatAsync):
5252
response = await client.update_user(user)
5353
assert "users" in response
5454
assert user["id"] in response["users"]
55-
return user
55+
yield user
56+
await hard_delete_users(client, [user["id"]])
5657

5758

5859
@pytest.fixture(scope="function")
@@ -61,24 +62,31 @@ async def server_user(client: StreamChatAsync):
6162
response = await client.update_user(user)
6263
assert "users" in response
6364
assert user["id"] in response["users"]
64-
return user
65+
yield user
66+
await hard_delete_users(client, [user["id"]])
6567

6668

6769
@pytest.fixture(scope="function")
6870
async def random_users(client: StreamChatAsync):
6971
user1 = {"id": str(uuid.uuid4())}
7072
user2 = {"id": str(uuid.uuid4())}
71-
await client.update_users([user1, user2])
72-
return [user1, user2]
73+
await client.upsert_users([user1, user2])
74+
yield [user1, user2]
75+
await hard_delete_users(client, [user1["id"], user2["id"]])
7376

7477

7578
@pytest.fixture(scope="function")
76-
async def channel(client, random_user: Dict):
79+
async def channel(client: StreamChatAsync, random_user: Dict):
7780
channel = client.channel(
7881
"messaging", str(uuid.uuid4()), {"test": True, "language": "python"}
7982
)
8083
await channel.create(random_user["id"])
81-
return channel
84+
yield channel
85+
86+
try:
87+
await channel.delete()
88+
except Exception:
89+
pass
8290

8391

8492
@pytest.fixture(scope="function")
@@ -110,8 +118,23 @@ async def fellowship_of_the_ring(client: StreamChatAsync):
110118
},
111119
{"id": "peregrin-took", "name": "Peregrin Took", "race": "Hobbit", "age": 28},
112120
]
113-
await client.update_users(members)
121+
await client.upsert_users(members)
114122
channel = client.channel(
115123
"team", "fellowship-of-the-ring", {"members": [m["id"] for m in members]}
116124
)
117125
await channel.create("gandalf")
126+
yield
127+
try:
128+
await channel.delete()
129+
except Exception:
130+
pass
131+
await hard_delete_users(client, [m["id"] for m in members])
132+
133+
134+
async def hard_delete_users(client: StreamChatAsync, user_ids: List[str]):
135+
try:
136+
await client.delete_users(
137+
user_ids, "hard", conversations="hard", messages="hard"
138+
)
139+
except Exception:
140+
pass

stream_chat/tests/async_chat/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ async def test_update_user(self, client: StreamChatAsync):
126126

127127
async def test_update_users(self, client: StreamChatAsync):
128128
user = {"id": str(uuid.uuid4())}
129-
response = await client.update_users([user])
129+
response = await client.upsert_users([user])
130130
assert "users" in response
131131
assert user["id"] in response["users"]
132132

stream_chat/tests/conftest.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def random_user(client: StreamChat):
4343
response = client.update_user(user)
4444
assert "users" in response
4545
assert user["id"] in response["users"]
46-
return user
46+
yield user
47+
hard_delete_users(client, [user["id"]])
4748

4849

4950
@pytest.fixture(scope="function")
@@ -52,15 +53,17 @@ def server_user(client: StreamChat):
5253
response = client.update_user(user)
5354
assert "users" in response
5455
assert user["id"] in response["users"]
55-
return user
56+
yield user
57+
hard_delete_users(client, [user["id"]])
5658

5759

5860
@pytest.fixture(scope="function")
5961
def random_users(client: StreamChat):
6062
user1 = {"id": str(uuid.uuid4())}
6163
user2 = {"id": str(uuid.uuid4())}
6264
client.update_users([user1, user2])
63-
return [user1, user2]
65+
yield [user1, user2]
66+
hard_delete_users(client, [user1["id"], user2["id"]])
6467

6568

6669
@pytest.fixture(scope="function")
@@ -69,7 +72,13 @@ def channel(client: StreamChat, random_user: Dict):
6972
"messaging", str(uuid.uuid4()), {"test": True, "language": "python"}
7073
)
7174
channel.create(random_user["id"])
72-
return channel
75+
76+
yield channel
77+
78+
try:
79+
channel.delete()
80+
except Exception:
81+
pass
7382

7483

7584
@pytest.fixture(scope="function")
@@ -106,3 +115,18 @@ def fellowship_of_the_ring(client: StreamChat):
106115
"team", "fellowship-of-the-ring", {"members": [m["id"] for m in members]}
107116
)
108117
channel.create("gandalf")
118+
119+
yield
120+
121+
try:
122+
channel.delete()
123+
except Exception:
124+
pass
125+
hard_delete_users(client, [m["id"] for m in members])
126+
127+
128+
def hard_delete_users(client: StreamChat, user_ids: List[str]):
129+
try:
130+
client.delete_users(user_ids, "hard", conversations="hard", messages="hard")
131+
except Exception:
132+
pass

0 commit comments

Comments
 (0)