add testing database and chatgpt factories (#28)

* add testing database and chatgpt factories

* include lint job to develop stage

* reformat audioconverter save files to tmp directory

* add api tests

* update README.md
This commit is contained in:
Dmitry Afanasyev
2023-10-08 04:43:24 +03:00
committed by GitHub
parent 23031b0777
commit beb32fb0b9
25 changed files with 434 additions and 255 deletions

View File

@@ -2,9 +2,12 @@ import httpx
import pytest
from faker import Faker
from httpx import AsyncClient, Response
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import Session
from api.exceptions import BaseAPIException
from settings.config import AppSettings
from tests.integration.factories.bot import ChatGptModelFactory
from tests.integration.utils import mocked_ask_question_api
pytestmark = [
@@ -22,9 +25,11 @@ async def test_bot_updates(rest_client: AsyncClient) -> None:
async def test_bot_healthcheck_is_ok(
dbsession: Session,
rest_client: AsyncClient,
test_settings: AppSettings,
) -> None:
ChatGptModelFactory.create_batch(size=3)
with mocked_ask_question_api(
host=test_settings.GPT_BASE_HOST,
return_value=Response(status_code=httpx.codes.OK, text="Привет! Как я могу помочь вам сегодня?"),
@@ -35,8 +40,9 @@ async def test_bot_healthcheck_is_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
dbsession: AsyncSession, rest_client: AsyncClient, test_settings: AppSettings, text: str
) -> None:
ChatGptModelFactory.create_batch(size=3)
with mocked_ask_question_api(
host=test_settings.GPT_BASE_HOST,
return_value=Response(status_code=httpx.codes.OK, text=text),
@@ -46,9 +52,11 @@ async def test_bot_healthcheck_invalid_request_model(
async def test_bot_healthcheck_not_ok(
dbsession: Session,
rest_client: AsyncClient,
test_settings: AppSettings,
) -> None:
ChatGptModelFactory.create_batch(size=3)
with mocked_ask_question_api(
host=test_settings.GPT_BASE_HOST,
side_effect=BaseAPIException(),