ticketfrei3/backend/tests/tests_mastodon/test_api_mastodon_delete_bot.py

54 lines
1.8 KiB
Python
Raw Normal View History

2023-03-19 12:47:20 +00:00
# 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
2023-04-01 13:13:50 +00:00
import pytest
2023-03-19 12:47:20 +00:00
from kibicara.platforms.mastodon.model import MastodonAccount
2023-04-01 13:13:50 +00:00
@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
),
2023-03-19 12:47:20 +00:00
headers=auth_header,
)
assert response.status_code == status.HTTP_204_NO_CONTENT
2023-04-01 13:13:50 +00:00
with pytest.raises(NoMatch):
await MastodonAccount.objects.get(id=mastodon_account.id)
2023-03-19 12:47:20 +00:00
2023-04-01 13:13:50 +00:00
@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
)
2023-03-19 12:47:20 +00:00
assert response.status_code == status.HTTP_404_NOT_FOUND
2023-04-01 13:13:50 +00:00
response = await asyncclient.delete(
"/api/hoods/wrong/mastodon/123", headers=auth_header
)
2023-03-19 12:47:20 +00:00
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
2023-04-01 13:13:50 +00:00
response = await asyncclient.delete(
"/api/hoods/{0}/mastodon/7331".format(hood_id), headers=auth_header
2023-03-19 12:47:20 +00:00
)
assert response.status_code == status.HTTP_404_NOT_FOUND
2023-04-01 13:13:50 +00:00
response = await asyncclient.delete(
"/api/hoods/{0}/mastodon/wrong".format(hood_id), headers=auth_header
2023-03-19 12:47:20 +00:00
)
assert response.status_code == status.HTTP_404_NOT_FOUND
2023-04-01 13:13:50 +00:00
@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
)
2023-03-19 12:47:20 +00:00
)
assert response.status_code == status.HTTP_401_UNAUTHORIZED