# 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 kibicara.platforms.mastodon.model import MastodonInstance def test_mastodon_get_bot(client, auth_header, event_loop, mastodon): response = client.get( "/api/hoods/{0}/mastodon/{1}".format(mastodon.hood.id, mastodon.id), headers=auth_header, ) assert response.status_code == status.HTTP_200_OK assert response.json()["id"] == mastodon.id assert response.json()["username"] == mastodon.username assert response.json()["access_token"] == mastodon.access_token mastodon_instance = event_loop.run_until_complete( MastodonInstance.objects.get(id=mastodon.instance) ) assert response.json()["instance"]["name"] == mastodon_instance.name assert not response.json()["instance"].get("client_id") assert not response.json()["instance"].get("client_secret") def test_mastodon_get_bot_invalid_id(client, auth_header, hood_id): response = client.get("/api/hoods/1337/mastodon/123", headers=auth_header) assert response.status_code == status.HTTP_404_NOT_FOUND response = client.get("/api/hoods/wrong/mastodon/123", headers=auth_header) assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY response = client.get( "/api/hoods/{0}/mastodon/7331".format(hood_id), headers=auth_header ) assert response.status_code == status.HTTP_404_NOT_FOUND response = client.get( "/api/hoods/{0}/mastodon/wrong".format(hood_id), headers=auth_header ) assert response.status_code == status.HTTP_404_NOT_FOUND def test_mastodon_get_bot_unauthorized(client, mastodon): response = client.get( "/api/hoods/{0}/mastodon/{1}".format(mastodon.hood.id, mastodon.id) ) assert response.status_code == status.HTTP_401_UNAUTHORIZED