From 9bb09d4e9dd9033208cb41bfe219c369ee092857 Mon Sep 17 00:00:00 2001 From: missytake Date: Sun, 19 Mar 2023 14:09:02 +0100 Subject: [PATCH] [tests] Test mastodon_read route --- .../test_api_mastodon_get_bot.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 backend/tests/tests_mastodon/test_api_mastodon_get_bot.py diff --git a/backend/tests/tests_mastodon/test_api_mastodon_get_bot.py b/backend/tests/tests_mastodon/test_api_mastodon_get_bot.py new file mode 100644 index 0000000..f6afa8d --- /dev/null +++ b/backend/tests/tests_mastodon/test_api_mastodon_get_bot.py @@ -0,0 +1,46 @@ +# Copyright (C) 2020 by Cathy Hu +# Copyright (C) 2020 by Martin Rey +# +# 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