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>
|
2023-03-19 18:03:25 +00:00
|
|
|
# Copyright (C) 2023 by Thomas Lindner <tom@dl6tom.de>
|
2023-03-19 12:47:20 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: 0BSD
|
|
|
|
|
|
|
|
from fastapi import status
|
2023-04-01 13:13:50 +00:00
|
|
|
import pytest
|
2023-03-19 18:03:25 +00:00
|
|
|
from tortoise.exceptions import DoesNotExist
|
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
|
2023-04-01 13:32:10 +00:00
|
|
|
async def test_mastodon_delete_bot(client, mastodon_account, auth_header):
|
|
|
|
response = await client.delete(
|
2023-03-19 16:25:37 +00:00
|
|
|
"/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-03-19 18:03:25 +00:00
|
|
|
with pytest.raises(DoesNotExist):
|
|
|
|
await MastodonAccount.get(id=mastodon_account.id)
|
2023-03-19 12:47:20 +00:00
|
|
|
|
|
|
|
|
2023-04-01 13:13:50 +00:00
|
|
|
@pytest.mark.anyio
|
2023-04-01 13:32:10 +00:00
|
|
|
async def test_mastodon_delete_bot_invalid_id(client, auth_header, hood_id):
|
|
|
|
response = await client.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:32:10 +00:00
|
|
|
response = await client.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:32:10 +00:00
|
|
|
response = await client.delete(
|
2023-03-19 13:04:45 +00:00
|
|
|
"/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:32:10 +00:00
|
|
|
response = await client.delete(
|
2023-03-19 13:04:45 +00:00
|
|
|
"/api/hoods/{0}/mastodon/wrong".format(hood_id), headers=auth_header
|
2023-03-19 12:47:20 +00:00
|
|
|
)
|
2023-03-19 18:03:25 +00:00
|
|
|
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
2023-03-19 12:47:20 +00:00
|
|
|
|
|
|
|
|
2023-04-01 13:13:50 +00:00
|
|
|
@pytest.mark.anyio
|
2023-04-01 13:32:10 +00:00
|
|
|
async def test_mastodon_delete_bot_unauthorized(client, mastodon_account):
|
|
|
|
response = await client.delete(
|
2023-03-19 16:25:37 +00:00
|
|
|
"/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
|