2020-07-19 12:37:04 +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:37:04 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: 0BSD
|
|
|
|
|
|
|
|
from fastapi import status
|
2023-04-01 13:23:33 +00:00
|
|
|
import pytest
|
2020-10-13 08:35:20 +00:00
|
|
|
|
2020-07-19 12:37:04 +00:00
|
|
|
from kibicara.model import Hood
|
|
|
|
from kibicara.platforms.telegram.model import Telegram
|
|
|
|
|
|
|
|
|
2023-04-01 13:23:33 +00:00
|
|
|
@pytest.mark.anyio
|
2023-04-01 13:32:10 +00:00
|
|
|
async def test_telegram_get_bots(client, auth_header, hood_id):
|
2023-04-01 13:23:33 +00:00
|
|
|
hood = await Hood.objects.get(id=hood_id)
|
|
|
|
telegram0 = await Telegram.objects.create(
|
|
|
|
hood=hood,
|
|
|
|
api_token="api_token123",
|
|
|
|
welcome_message="welcome_message123",
|
2020-07-19 12:37:04 +00:00
|
|
|
)
|
2023-04-01 13:23:33 +00:00
|
|
|
telegram1 = await Telegram.objects.create(
|
|
|
|
hood=hood,
|
|
|
|
api_token="api_token456",
|
|
|
|
welcome_message="welcome_message123",
|
2020-07-19 12:37:04 +00:00
|
|
|
)
|
2023-04-01 13:32:10 +00:00
|
|
|
response = await client.get(
|
2023-04-01 13:23:33 +00:00
|
|
|
"/api/hoods/{0}/telegram/".format(telegram0.hood.id), headers=auth_header
|
2020-07-19 12:37:04 +00:00
|
|
|
)
|
|
|
|
assert response.status_code == status.HTTP_200_OK
|
2023-03-18 17:47:02 +00:00
|
|
|
assert response.json()[0]["id"] == telegram0.id
|
|
|
|
assert response.json()[0]["api_token"] == telegram0.api_token
|
|
|
|
assert response.json()[1]["id"] == telegram1.id
|
|
|
|
assert response.json()[1]["api_token"] == telegram1.api_token
|
2020-07-19 12:37:04 +00:00
|
|
|
|
|
|
|
|
2023-04-01 13:23:33 +00:00
|
|
|
@pytest.mark.anyio
|
2023-04-01 13:32:10 +00:00
|
|
|
async def test_telegram_get_bots_invalid_id(client, auth_header, hood_id):
|
|
|
|
response = await client.get("/api/hoods/1337/telegram/", headers=auth_header)
|
2020-07-19 12:37:04 +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/telegram/", headers=auth_header)
|
2020-07-19 12:37:04 +00:00
|
|
|
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
|
|
|
|
|
|
|
|
2023-04-01 13:23:33 +00:00
|
|
|
@pytest.mark.anyio
|
2023-04-01 13:32:10 +00:00
|
|
|
async def test_telegram_get_bots_unauthorized(client, hood_id):
|
|
|
|
response = await client.get("/api/hoods/{0}/telegram/".format(hood_id))
|
2020-07-19 12:37:04 +00:00
|
|
|
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|