mirror of https://gitlab.com/litecord/litecord.git
parent
136f7a7348
commit
8d9ac79dbc
|
|
@ -351,7 +351,8 @@ async def _update_guild(guild_id):
|
|||
|
||||
|
||||
@bp.route('/<int:guild_id>', methods=['DELETE'])
|
||||
@bp.route('/<int:guild_id>/delete', methods=['POST']) # this one is not actually documented, but it's used by Discord client
|
||||
# this endpoint is not documented, but used by the official client.
|
||||
@bp.route('/<int:guild_id>/delete', methods=['POST'])
|
||||
async def delete_guild(guild_id):
|
||||
"""Delete a guild."""
|
||||
user_id = await token_check()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,92 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
import secrets
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.common import login
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_guild_create(test_cli):
|
||||
"""Test the creation of a guild, in three stages:
|
||||
- creating it
|
||||
- checking the list
|
||||
- deleting it
|
||||
"""
|
||||
token = await login('normal', test_cli)
|
||||
g_name = secrets.token_hex(5)
|
||||
|
||||
# stage 1: create
|
||||
resp = await test_cli.post('/api/v6/guilds', headers={
|
||||
'Authorization': token
|
||||
}, json={
|
||||
'name': g_name,
|
||||
'region': None,
|
||||
})
|
||||
|
||||
assert resp.status_code == 200
|
||||
rjson = await resp.json
|
||||
|
||||
# we won't assert a full guild object.
|
||||
assert isinstance(rjson['id'], str)
|
||||
assert isinstance(rjson['owner_id'], str)
|
||||
assert isinstance(rjson['name'], str)
|
||||
assert rjson['name'] == g_name
|
||||
|
||||
created = rjson
|
||||
guild_id = created['id']
|
||||
|
||||
# stage 2: test
|
||||
resp = await test_cli.get('/api/v6/users/@me/guilds', headers={
|
||||
'Authorization': token
|
||||
})
|
||||
|
||||
assert resp.status_code == 200
|
||||
rjson = await resp.json
|
||||
|
||||
assert isinstance(rjson, list)
|
||||
|
||||
# it MUST be 1 as we'll delete the guild later on.
|
||||
# plus the test user never starts with any guild.
|
||||
assert len(rjson) == 1
|
||||
|
||||
for guild in rjson:
|
||||
assert isinstance(guild, dict)
|
||||
assert isinstance(guild['id'], str)
|
||||
assert isinstance(guild['name'], str)
|
||||
assert isinstance(guild['owner'], bool)
|
||||
assert guild['icon'] is None or isinstance(guild['icon'], str)
|
||||
|
||||
try:
|
||||
our_guild = next(filter(
|
||||
lambda guild: guild['id'] == guild_id,
|
||||
rjson
|
||||
))
|
||||
except StopIteration:
|
||||
raise Exception('created guild not found in user guild list')
|
||||
|
||||
assert our_guild['id'] == created['id']
|
||||
assert our_guild['name'] == created['name']
|
||||
|
||||
# stage 3: deletion
|
||||
resp = await test_cli.delete(f'/api/v6/guilds/{guild_id}', headers={
|
||||
'Authorization': token
|
||||
})
|
||||
|
||||
assert resp.status_code == 204
|
||||
Loading…
Reference in New Issue