From a6ecc84b9f7f3bddb22aa89b20b0e33c4f9ba5db Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 22 Apr 2019 02:17:51 -0300 Subject: [PATCH] test_admin_api/test_guilds: add test_guild_update - docs/admin_api.md: add note on unavailable guild object being returned --- docs/admin_api.md | 4 ++-- tests/test_admin_api/test_guilds.py | 30 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/docs/admin_api.md b/docs/admin_api.md index 1dd37a4..9c4b87c 100644 --- a/docs/admin_api.md +++ b/docs/admin_api.md @@ -155,9 +155,9 @@ Returns a partial guild object. ### PATCH `/guilds/` Update a single guild. +Dispatches `GUILD_UPDATE` to subscribers of the guild. -Dispatches `GUILD_UPDATE` to subscribers of the guild, returns the guild object -on success. +Returns a guild object or an unavailable guild object on success. | field | type | description | | --: | :-- | :-- | diff --git a/tests/test_admin_api/test_guilds.py b/tests/test_admin_api/test_guilds.py index 86424da..c89e484 100644 --- a/tests/test_admin_api/test_guilds.py +++ b/tests/test_admin_api/test_guilds.py @@ -62,3 +62,33 @@ async def test_guild_fetch(test_cli): assert rjson['id'] == guild_id finally: await delete_guild(int(guild_id), app_=test_cli.app) + + +@pytest.mark.asyncio +async def test_guild_update(test_cli): + """Test the update of a guild via the Admin API.""" + token = await login('admin', test_cli) + rjson = await _create_guild(test_cli, token=token) + guild_id = rjson['id'] + assert not rjson['unavailable'] + + try: + # I believe setting up an entire gateway client registered to the guild + # 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( + f'/api/v6/admin/guilds/{guild_id}', + headers={ + 'Authorization': token + }, json={ + 'unavailable': True + }) + + assert resp.status_code == 200 + rjson = await resp.json + assert isinstance(rjson, dict) + assert rjson['id'] == guild_id + assert rjson['unavailable'] + finally: + await delete_guild(int(guild_id), app_=test_cli.app)