Skip to content

Commit 6775daf

Browse files
committed
Add some guild tests
1 parent d09b223 commit 6775daf

File tree

3 files changed

+80
-13
lines changed

3 files changed

+80
-13
lines changed

tests/http/core.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"components",
8181
"avatar",
8282
"applied_tags",
83+
"icon",
8384
)
8485

8586
V = TypeVar("V")
@@ -390,6 +391,14 @@ def avatar(request) -> bytes | None:
390391
return None
391392

392393

394+
@pytest.fixture(params=(None, "random"))
395+
def icon(request) -> bytes | None:
396+
"""A random icon fixture"""
397+
if request.param == "random":
398+
return random_bytes()
399+
return None
400+
401+
393402
@pytest.fixture(params=(None, "random"))
394403
def applied_tags(request) -> list[int] | None:
395404
if request.param == "random":

tests/http/test_guild.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2021-present Pycord Development
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a
7+
copy of this software and associated documentation files (the "Software"),
8+
to deal in the Software without restriction, including without limitation
9+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10+
and/or sell copies of the Software, and to permit persons to whom the
11+
Software is furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22+
DEALINGS IN THE SOFTWARE.
23+
"""
24+
import pytest
25+
26+
from discord import Route
27+
28+
from ..core import client
29+
from .core import after, before, guild_id, icon, limit, name
30+
31+
32+
async def test_get_guilds(client, limit, before, after):
33+
params = {"limit": limit}
34+
if before:
35+
params["before"] = before
36+
if after:
37+
params["after"] = after
38+
with client.makes_request(Route("GET", "/users/@me/guilds"), params=params):
39+
await client.http.get_guilds(limit, before, after)
40+
41+
42+
async def test_leave_guild(client, guild_id):
43+
with client.makes_request(
44+
Route("DELETE", "/users/@me/guilds/{guild_id}", guild_id=guild_id)
45+
):
46+
await client.http.leave_guild(guild_id)
47+
48+
49+
@pytest.mark.parametrize(
50+
"with_counts",
51+
(True, False),
52+
)
53+
async def test_get_guild(client, guild_id, with_counts):
54+
with client.makes_request(
55+
Route("GET", "/guilds/{guild_id}", guild_id=guild_id),
56+
params={"with_counts": int(with_counts)},
57+
):
58+
await client.http.get_guild(guild_id, with_counts=with_counts)
59+
60+
61+
async def test_delete_guild(client, guild_id):
62+
with client.makes_request(Route("DELETE", "/guilds/{guild_id}", guild_id=guild_id)):
63+
await client.http.delete_guild(guild_id)
64+
65+
66+
async def test_create_guild(client, name, icon):
67+
payload = {"name": name}
68+
if icon:
69+
payload["icon"] = icon
70+
with client.makes_request(Route("POST", "/guilds"), json=payload):
71+
await client.http.create_guild(name, icon)

tests/http/test_main.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,6 @@ async def test_pins_from(client, channel_id):
180180
await client.http.pins_from(channel_id)
181181

182182

183-
@pytest.mark.parametrize(
184-
"with_counts",
185-
(True, False),
186-
)
187-
async def test_get_guild(client, with_counts):
188-
get_mock_response("get_guild")
189-
with client.makes_request(
190-
Route("GET", "/guilds/{guild_id}", guild_id=1234),
191-
params={"with_counts": int(with_counts)},
192-
):
193-
await client.http.get_guild(1234, with_counts=with_counts)
194-
195-
196183
# async def test_static_login(client):
197184
# """Test logging in with a static token."""
198185
# await client.http.close() # Test closing the client before it exists

0 commit comments

Comments
 (0)