|
| 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) |
0 commit comments