mirror of
https://github.com/Balshgit/gpt_chat_bot.git
synced 2025-12-16 21:20:39 +03:00
refactoring (#26)
This commit is contained in:
57
bot_microservice/tests/integration/system/test_system.py
Normal file
57
bot_microservice/tests/integration/system/test_system.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import httpx
|
||||
import pytest
|
||||
from faker import Faker
|
||||
from httpx import AsyncClient, Response
|
||||
|
||||
from api.exceptions import BaseAPIException
|
||||
from settings.config import AppSettings
|
||||
from tests.integration.utils import mocked_ask_question_api
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.asyncio,
|
||||
pytest.mark.enable_socket,
|
||||
]
|
||||
|
||||
|
||||
faker = Faker()
|
||||
|
||||
|
||||
async def test_bot_updates(rest_client: AsyncClient) -> None:
|
||||
response = await rest_client.get("/api/healthcheck")
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
async def test_bot_healthcheck_is_ok(
|
||||
rest_client: AsyncClient,
|
||||
test_settings: AppSettings,
|
||||
) -> None:
|
||||
with mocked_ask_question_api(
|
||||
host=test_settings.GPT_BASE_HOST,
|
||||
return_value=Response(status_code=httpx.codes.OK, text="Привет! Как я могу помочь вам сегодня?"),
|
||||
):
|
||||
response = await rest_client.get("/api/bot-healthcheck")
|
||||
assert response.status_code == httpx.codes.OK
|
||||
|
||||
|
||||
@pytest.mark.parametrize("text", ["Invalid request model", "return unexpected http status code"])
|
||||
async def test_bot_healthcheck_invalid_request_model(
|
||||
rest_client: AsyncClient, test_settings: AppSettings, text: str
|
||||
) -> None:
|
||||
with mocked_ask_question_api(
|
||||
host=test_settings.GPT_BASE_HOST,
|
||||
return_value=Response(status_code=httpx.codes.OK, text=text),
|
||||
):
|
||||
response = await rest_client.get("/api/bot-healthcheck")
|
||||
assert response.status_code == httpx.codes.INTERNAL_SERVER_ERROR
|
||||
|
||||
|
||||
async def test_bot_healthcheck_not_ok(
|
||||
rest_client: AsyncClient,
|
||||
test_settings: AppSettings,
|
||||
) -> None:
|
||||
with mocked_ask_question_api(
|
||||
host=test_settings.GPT_BASE_HOST,
|
||||
side_effect=BaseAPIException(),
|
||||
):
|
||||
response = await rest_client.get("/api/bot-healthcheck")
|
||||
assert response.status_code == httpx.codes.INTERNAL_SERVER_ERROR
|
||||
Reference in New Issue
Block a user