2020-07-19 12:02:43 +00:00
|
|
|
# Copyright (C) 2020 by Cathy Hu <cathy.hu@fau.de>
|
2020-09-28 22:39:32 +00:00
|
|
|
# Copyright (C) 2020 by Martin Rey <martin.rey@mailbox.org>
|
2020-07-19 12:02:43 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: 0BSD
|
|
|
|
|
|
|
|
from fastapi import status
|
|
|
|
from pytest import mark
|
|
|
|
|
|
|
|
|
2023-03-18 17:47:02 +00:00
|
|
|
@mark.parametrize("bot", [{"api_token": "apitoken123", "welcome_message": "msg"}])
|
2020-07-19 12:02:43 +00:00
|
|
|
def test_telegram_get_bot(client, auth_header, event_loop, bot, telegram):
|
|
|
|
response = client.get(
|
2023-03-18 17:47:02 +00:00
|
|
|
"/api/hoods/{0}/telegram/{1}".format(telegram.hood.id, telegram.id),
|
2020-10-12 20:47:06 +00:00
|
|
|
headers=auth_header,
|
2020-07-19 12:02:43 +00:00
|
|
|
)
|
|
|
|
assert response.status_code == status.HTTP_200_OK
|
2023-03-18 17:47:02 +00:00
|
|
|
assert response.json()["id"] == telegram.id
|
|
|
|
assert response.json()["api_token"] == telegram.api_token
|
|
|
|
assert response.json()["welcome_message"] == telegram.welcome_message
|
2020-07-19 12:02:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_telegram_get_bot_invalid_id(client, auth_header, hood_id):
|
2023-03-18 17:47:02 +00:00
|
|
|
response = client.get("/api/hoods/1337/telegram/123", headers=auth_header)
|
2020-07-19 12:02:43 +00:00
|
|
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
2023-03-18 17:47:02 +00:00
|
|
|
response = client.get("/api/hoods/wrong/telegram/123", headers=auth_header)
|
2020-07-19 12:02:43 +00:00
|
|
|
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
2020-10-12 20:47:06 +00:00
|
|
|
response = client.get(
|
2023-03-18 17:47:02 +00:00
|
|
|
"/api/hoods/{0}/telegram/7331".format(hood_id), headers=auth_header
|
2020-10-12 20:47:06 +00:00
|
|
|
)
|
2020-07-19 12:02:43 +00:00
|
|
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
2020-10-12 20:47:06 +00:00
|
|
|
response = client.get(
|
2023-03-18 17:47:02 +00:00
|
|
|
"/api/hoods/{0}/telegram/wrong".format(hood_id), headers=auth_header
|
2020-10-12 20:47:06 +00:00
|
|
|
)
|
2020-07-19 12:02:43 +00:00
|
|
|
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
|
|
|
|
|
|
|
|
2023-03-18 17:47:02 +00:00
|
|
|
@mark.parametrize("bot", [{"api_token": "apitoken456", "welcome_message": "msg"}])
|
2020-07-19 12:02:43 +00:00
|
|
|
def test_telegram_get_bot_unauthorized(client, bot, telegram):
|
2020-10-12 20:47:06 +00:00
|
|
|
response = client.get(
|
2023-03-18 17:47:02 +00:00
|
|
|
"/api/hoods/{0}/telegram/{1}".format(telegram.hood.id, telegram.id)
|
2020-10-12 20:47:06 +00:00
|
|
|
)
|
2020-07-19 12:02:43 +00:00
|
|
|
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|