diff --git a/tests/common.py b/tests/common.py index 66d67c6..284b302 100644 --- a/tests/common.py +++ b/tests/common.py @@ -56,6 +56,7 @@ class TestClient: user and adds authorization headers to test requests.""" def __init__(self, test_cli, test_user): self.cli = test_cli + self.app = test_cli.app self.user = test_user def __getitem__(self, key): @@ -78,6 +79,11 @@ class TestClient: kwargs['headers'] = self._inject_auth(kwargs) return await self.cli.post(*args, **kwargs) + async def put(self, *args, **kwargs): + """Send a POST request.""" + kwargs['headers'] = self._inject_auth(kwargs) + return await self.cli.put(*args, **kwargs) + async def patch(self, *args, **kwargs): """Send a PATCH request.""" kwargs['headers'] = self._inject_auth(kwargs) diff --git a/tests/test_admin_api/test_guilds.py b/tests/test_admin_api/test_guilds.py index e87309e..d1156e0 100644 --- a/tests/test_admin_api/test_guilds.py +++ b/tests/test_admin_api/test_guilds.py @@ -63,13 +63,13 @@ async def test_guild_fetch(test_cli_staff): try: await _fetch_guild(test_cli_staff, guild_id) finally: - await delete_guild(int(guild_id), app_=test_cli_staff.test_cli.app) + await delete_guild(int(guild_id), app_=test_cli_staff.app) @pytest.mark.asyncio async def test_guild_update(test_cli_staff): """Test the update of a guild via the Admin API.""" - rjson = await _create_guild(test_cli_staff, token=token) + rjson = await _create_guild(test_cli_staff) guild_id = rjson['id'] assert not rjson['unavailable'] @@ -78,11 +78,9 @@ async def test_guild_update(test_cli_staff): # would be overkill to test the side-effects, so... I'm not # testing them. Yes, I know its a bad idea, but if someone has an easier # way to write that, do send an MR. - resp = await test_cli.patch( + resp = await test_cli_staff.patch( f'/api/v6/admin/guilds/{guild_id}', - headers={ - 'Authorization': token - }, json={ + json={ 'unavailable': True }) @@ -95,7 +93,7 @@ async def test_guild_update(test_cli_staff): rjson = await _fetch_guild(test_cli_staff, guild_id) assert rjson['unavailable'] finally: - await delete_guild(int(guild_id), app_=test_cli_staff.test_cli.app) + await delete_guild(int(guild_id), app_=test_cli_staff.app) @pytest.mark.asyncio @@ -118,4 +116,4 @@ async def test_guild_delete(test_cli_staff): assert rjson['error'] assert rjson['code'] == GuildNotFound.error_code finally: - await delete_guild(int(guild_id), app_=test_cli.app) + await delete_guild(int(guild_id), app_=test_cli_staff.app) diff --git a/tests/test_admin_api/test_users.py b/tests/test_admin_api/test_users.py index 841711a..a78acf7 100644 --- a/tests/test_admin_api/test_users.py +++ b/tests/test_admin_api/test_users.py @@ -21,7 +21,6 @@ import secrets import pytest -from tests.credentials import CREDS from litecord.enums import UserFlags @@ -98,7 +97,7 @@ async def test_create_delete(test_cli_staff): assert isinstance(rjson, list) assert rjson[0]['id'] == genned_uid finally: - await _del_user(test_cli_staff, genned_uid, token=token) + await _del_user(test_cli_staff, genned_uid) @pytest.mark.asyncio @@ -126,4 +125,4 @@ async def test_user_update(test_cli_staff): # TODO: maybe we can check for side effects by fetching the # user manually too... finally: - await _del_user(test_cli, user_id, token=token) + await _del_user(test_cli_staff, user_id) diff --git a/tests/test_websocket.py b/tests/test_websocket.py index 86dba0f..dc31235 100644 --- a/tests/test_websocket.py +++ b/tests/test_websocket.py @@ -87,7 +87,7 @@ async def test_gw(test_cli): @pytest.mark.asyncio async def test_ready(test_cli_user): - conn = await gw_start(test_cli_user.test_cli) + conn = await gw_start(test_cli_user.cli) # get the hello frame but ignore it await _json(conn) @@ -111,7 +111,7 @@ async def test_ready(test_cli_user): @pytest.mark.asyncio async def test_ready_fields(test_cli_user): - conn = await gw_start(test_cli_user.test_cli) + conn = await gw_start(test_cli_user.cli) # get the hello frame but ignore it await _json(conn) @@ -151,7 +151,7 @@ async def test_ready_fields(test_cli_user): @pytest.mark.asyncio async def test_heartbeat(test_cli_user): - conn = await gw_start(test_cli_user.test_cli) + conn = await gw_start(test_cli_user.cli) # get the hello frame but ignore it await _json(conn)