[tests] Test mastodon_delete route
This commit is contained in:
parent
b49c4767a0
commit
16c325a9cb
30
backend/tests/tests_mastodon/conftest.py
Normal file
30
backend/tests/tests_mastodon/conftest.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
# Copyright (C) 2020 by Cathy Hu <cathy.hu@fau.de>
|
||||
# Copyright (C) 2020 by Martin Rey <martin.rey@mailbox.org>
|
||||
#
|
||||
# SPDX-License-Identifier: 0BSD
|
||||
|
||||
from pytest import fixture
|
||||
|
||||
from kibicara.model import Hood
|
||||
from kibicara.platforms.mastodon.model import MastodonAccount, MastodonInstance
|
||||
|
||||
|
||||
@fixture(scope='function')
|
||||
def mastodon(event_loop, hood_id):
|
||||
hood = event_loop.run_until_complete(Hood.objects.get(id=hood_id))
|
||||
instance = event_loop.run_until_complete(
|
||||
MastodonInstance.objects.create(
|
||||
name="inst4nce",
|
||||
client_id="cl13nt_id",
|
||||
client_secret="cl13nt_s3cr3t",
|
||||
)
|
||||
)
|
||||
return event_loop.run_until_complete(
|
||||
MastodonAccount.objects.create(
|
||||
hood=hood,
|
||||
instance=instance,
|
||||
access_token="t0k3n",
|
||||
enabled=True,
|
||||
username="us3r",
|
||||
)
|
||||
)
|
42
backend/tests/tests_mastodon/test_api_mastodon_delete_bot.py
Normal file
42
backend/tests/tests_mastodon/test_api_mastodon_delete_bot.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
# Copyright (C) 2020 by Cathy Hu <cathy.hu@fau.de>
|
||||
# Copyright (C) 2020 by Martin Rey <martin.rey@mailbox.org>
|
||||
#
|
||||
# SPDX-License-Identifier: 0BSD
|
||||
|
||||
from fastapi import status
|
||||
from ormantic.exceptions import NoMatch
|
||||
from pytest import raises
|
||||
|
||||
from kibicara.platforms.mastodon.model import MastodonAccount
|
||||
|
||||
|
||||
def test_mastodon_delete_bot(client, event_loop, mastodon, auth_header):
|
||||
response = client.delete(
|
||||
'/api/hoods/{0}/mastodon/{1}'.format(mastodon.hood.id, mastodon.id),
|
||||
headers=auth_header,
|
||||
)
|
||||
assert response.status_code == status.HTTP_204_NO_CONTENT
|
||||
with raises(NoMatch):
|
||||
event_loop.run_until_complete(MastodonAccount.objects.get(id=mastodon.id))
|
||||
|
||||
|
||||
def test_mastodon_delete_bot_invalid_id(client, auth_header, hood_id):
|
||||
response = client.delete('/api/hoods/1337/mastodon/123', headers=auth_header)
|
||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||
response = client.delete('/api/hoods/wrong/mastodon/123', headers=auth_header)
|
||||
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
||||
response = client.delete(
|
||||
'/api/hoods/{0}/mastodon/7331'.format(hood_id), headers=auth_header
|
||||
)
|
||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||
response = client.delete(
|
||||
'/api/hoods/{0}/mastodon/wrong'.format(hood_id), headers=auth_header
|
||||
)
|
||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||
|
||||
|
||||
def test_mastodon_delete_bot_unauthorized(client, mastodon):
|
||||
response = client.delete(
|
||||
'/api/hoods/{0}/mastodon/{1}'.format(mastodon.hood.id, mastodon.id)
|
||||
)
|
||||
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
Loading…
Reference in a new issue