2023-03-19 13:25:21 +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 13:25:21 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: 0BSD
|
|
|
|
|
|
|
|
from fastapi import status
|
2023-04-01 13:13:50 +00:00
|
|
|
import pytest
|
2023-03-19 13:25:21 +00:00
|
|
|
|
2023-03-19 16:25:37 +00:00
|
|
|
from kibicara.platforms.mastodon.model import MastodonAccount
|
2023-03-19 13:25:21 +00:00
|
|
|
|
|
|
|
|
2023-04-01 13:13:50 +00:00
|
|
|
@pytest.mark.anyio
|
|
|
|
async def test_mastodon_get_bots(
|
2023-04-01 13:32:10 +00:00
|
|
|
client, auth_header, hood_id, mastodon_account, mastodon_instance
|
2023-03-19 16:25:37 +00:00
|
|
|
):
|
2023-03-19 18:03:25 +00:00
|
|
|
mastodon2 = await MastodonAccount.create(
|
2023-04-01 13:13:50 +00:00
|
|
|
hood=mastodon_account.hood,
|
|
|
|
instance=mastodon_instance,
|
|
|
|
access_token="4cc3ss",
|
|
|
|
enabled=True,
|
|
|
|
username="us4r",
|
2023-03-19 13:25:21 +00:00
|
|
|
)
|
2023-04-01 13:32:10 +00:00
|
|
|
response = await client.get(
|
2023-04-01 13:13:50 +00:00
|
|
|
"/api/hoods/{0}/mastodon/".format(mastodon_account.hood.id), headers=auth_header
|
2023-03-19 13:25:21 +00:00
|
|
|
)
|
2023-04-01 13:13:50 +00:00
|
|
|
print(response.headers)
|
2023-03-19 13:25:21 +00:00
|
|
|
assert response.status_code == status.HTTP_200_OK
|
2023-03-19 16:25:37 +00:00
|
|
|
assert response.json()[0]["id"] == mastodon_account.id
|
|
|
|
assert response.json()[0]["access_token"] == mastodon_account.access_token
|
2023-03-19 13:25:21 +00:00
|
|
|
assert response.json()[1]["id"] == mastodon2.id
|
|
|
|
assert response.json()[1]["access_token"] == mastodon2.access_token
|
|
|
|
|
|
|
|
|
2023-04-01 13:13:50 +00:00
|
|
|
@pytest.mark.anyio
|
2023-04-01 13:32:10 +00:00
|
|
|
async def test_mastodon_get_bots_invalid_id(client, auth_header, hood_id):
|
|
|
|
response = await client.get("/api/hoods/1337/mastodon/", headers=auth_header)
|
2023-03-19 13:25:21 +00:00
|
|
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
2023-04-01 13:32:10 +00:00
|
|
|
response = await client.get("/api/hoods/wrong/mastodon/", headers=auth_header)
|
2023-03-19 13:25:21 +00:00
|
|
|
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
|
|
|
|
|
|
|
|
2023-04-01 13:13:50 +00:00
|
|
|
@pytest.mark.anyio
|
2023-04-01 13:32:10 +00:00
|
|
|
async def test_mastodon_get_bots_unauthorized(client, hood_id):
|
|
|
|
response = await client.get("/api/hoods/{0}/mastodon/".format(hood_id))
|
2023-03-19 13:25:21 +00:00
|
|
|
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
|
|
|
|
|
|
|
|
2023-04-01 13:13:50 +00:00
|
|
|
@pytest.mark.anyio
|
2023-04-01 13:32:10 +00:00
|
|
|
async def test_mastodon_public(client, mastodon_account, mastodon_instance):
|
|
|
|
response = await client.get(
|
2023-03-19 16:25:37 +00:00
|
|
|
"/api/hoods/{0}/mastodon/public".format(mastodon_account.hood.id)
|
2023-03-19 13:25:21 +00:00
|
|
|
)
|
2023-03-19 16:25:37 +00:00
|
|
|
assert response.json()[0]["username"] == mastodon_account.username
|
2023-03-19 13:25:21 +00:00
|
|
|
assert response.json()[0]["instance"] == mastodon_instance.name
|