From a8f60b8786da909b3bfa0a9d03bd1fa4d418c82e Mon Sep 17 00:00:00 2001 From: Cathy Hu Date: Sun, 19 Jul 2020 00:29:43 +0200 Subject: [PATCH] [tests] Add tests for getting infos about a twitter bot --- tests/test_api_twitter_get_bot.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/test_api_twitter_get_bot.py diff --git a/tests/test_api_twitter_get_bot.py b/tests/test_api_twitter_get_bot.py new file mode 100644 index 0000000..72778a2 --- /dev/null +++ b/tests/test_api_twitter_get_bot.py @@ -0,0 +1,31 @@ +# Copyright (C) 2020 by Cathy Hu +# +# SPDX-License-Identifier: 0BSD + +from fastapi import status + + +def test_twitter_get_bot(client, auth_header, event_loop, twitter): + response = client.get( + f'/api/hoods/{twitter.hood.id}/twitter/{twitter.id}', headers=auth_header + ) + assert response.status_code == status.HTTP_200_OK + assert response.json()['id'] == twitter.id + assert response.json()['access_token'] == twitter.access_token + assert response.json()['access_token_secret'] == twitter.access_token_secret + + +def test_twitter_get_bot_invalid_id(client, auth_header, hood_id): + response = client.get('/api/hoods/1337/twitter/123', headers=auth_header) + assert response.status_code == status.HTTP_404_NOT_FOUND + response = client.get('/api/hoods/wrong/twitter/123', headers=auth_header) + assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY + response = client.get(f'/api/hoods/{hood_id}/twitter/7331', headers=auth_header) + assert response.status_code == status.HTTP_404_NOT_FOUND + response = client.get(f'/api/hoods/{hood_id}/twitter/wrong', headers=auth_header) + assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY + + +def test_twitter_get_bot_unauthorized(client, twitter): + response = client.get(f'/api/hoods/{twitter.hood.id}/twitter/{twitter.id}') + assert response.status_code == status.HTTP_401_UNAUTHORIZED