mirror of https://gitlab.com/litecord/litecord.git
admin_api.guilds: make get guild route raise GuildNotFound
before it was returning 200 but with a `null` inside, I don't think that's reasonable API design. - test_admin_api/test_guilds: add checks for GuildNotFound error code
This commit is contained in:
parent
4142baa84b
commit
daee044a4f
|
|
@ -150,7 +150,7 @@ Returns empty body with 204 status code on success.
|
|||
|
||||
### GET `/guilds/<guild_id>`
|
||||
|
||||
Returns a partial guild object.
|
||||
Returns a partial guild object. Gives a 404 when the guild is not found.
|
||||
|
||||
### PATCH `/guilds/<guild_id>`
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ from litecord.auth import admin_check
|
|||
from litecord.schemas import validate
|
||||
from litecord.admin_schemas import GUILD_UPDATE
|
||||
from litecord.blueprints.guilds import delete_guild
|
||||
from litecord.errors import GuildNotFound
|
||||
|
||||
bp = Blueprint('guilds_admin', __name__)
|
||||
|
||||
|
|
@ -31,9 +32,12 @@ async def get_guild(guild_id: int):
|
|||
"""Get a basic guild payload."""
|
||||
await admin_check()
|
||||
|
||||
return jsonify(
|
||||
await app.storage.get_guild(guild_id)
|
||||
)
|
||||
guild = await app.storage.get_guild(guild_id)
|
||||
|
||||
if not guild:
|
||||
raise GuildNotFound()
|
||||
|
||||
return jsonify(guild)
|
||||
|
||||
|
||||
@bp.route('/<int:guild_id>', methods=['PATCH'])
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import pytest
|
|||
|
||||
from tests.common import login
|
||||
from litecord.blueprints.guilds import delete_guild
|
||||
from litecord.errors import GuildNotFound
|
||||
|
||||
async def _create_guild(test_cli, *, token=None):
|
||||
token = token or await login('admin', test_cli)
|
||||
|
|
@ -125,5 +126,9 @@ async def test_guild_delete(test_cli):
|
|||
ret_early=True)
|
||||
|
||||
assert resp.status_code == 404
|
||||
rjson = await resp.json
|
||||
assert isinstance(rjson, dict)
|
||||
assert rjson['error']
|
||||
assert rjson['code'] == GuildNotFound.error_code
|
||||
finally:
|
||||
await delete_guild(int(guild_id), app_=test_cli.app)
|
||||
|
|
|
|||
Loading…
Reference in New Issue