ticketfrei3/backend/tests/tests_mastodon/test_api_mastodon_delete_bot.py

54 lines
1.8 KiB
Python

# 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
import pytest
from kibicara.platforms.mastodon.model import MastodonAccount
@pytest.mark.anyio
async def test_mastodon_delete_bot(asyncclient, mastodon_account, auth_header):
response = await asyncclient.delete(
"/api/hoods/{0}/mastodon/{1}".format(
mastodon_account.hood.id, mastodon_account.id
),
headers=auth_header,
)
assert response.status_code == status.HTTP_204_NO_CONTENT
with pytest.raises(NoMatch):
await MastodonAccount.objects.get(id=mastodon_account.id)
@pytest.mark.anyio
async def test_mastodon_delete_bot_invalid_id(asyncclient, auth_header, hood_id):
response = await asyncclient.delete(
"/api/hoods/1337/mastodon/123", headers=auth_header
)
assert response.status_code == status.HTTP_404_NOT_FOUND
response = await asyncclient.delete(
"/api/hoods/wrong/mastodon/123", headers=auth_header
)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
response = await asyncclient.delete(
"/api/hoods/{0}/mastodon/7331".format(hood_id), headers=auth_header
)
assert response.status_code == status.HTTP_404_NOT_FOUND
response = await asyncclient.delete(
"/api/hoods/{0}/mastodon/wrong".format(hood_id), headers=auth_header
)
assert response.status_code == status.HTTP_404_NOT_FOUND
@pytest.mark.anyio
async def test_mastodon_delete_bot_unauthorized(asyncclient, mastodon_account):
response = await asyncclient.delete(
"/api/hoods/{0}/mastodon/{1}".format(
mastodon_account.hood.id, mastodon_account.id
)
)
assert response.status_code == status.HTTP_401_UNAUTHORIZED