Skip to content

Commit

Permalink
Updated api tests to improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunandhita B authored and Sunandhita B committed Nov 29, 2024
1 parent b8d8627 commit f50e47a
Show file tree
Hide file tree
Showing 3 changed files with 508 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/app/handlers/v2/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async def install(install_content: JBBotCode) -> Flow:
fsm_code=install_content.code,
requirements_txt=install_content.requirements,
index_urls=install_content.index_urls,
version = bot.version
),
),
)
Expand Down
57 changes: 57 additions & 0 deletions api/tests/test_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from unittest.mock import patch
import pytest
from lib.data_models import Flow, BotConfig, BotIntent, FlowIntent, Bot
from lib.models import JBBot
from app.handlers.v2.bot import list_bots, install
from app.jb_schema import JBBotCode

@pytest.mark.asyncio
async def test_list_bots():
mock_bot1 = JBBot(id="test_bot_1", name="Bot1", status="active")
mock_bot2 = JBBot(id="test_bot_2", name="Bot2", status="active")

bot_list = [mock_bot1,mock_bot2]
with patch("app.handlers.v2.bot.get_bot_list", return_value = bot_list) as mock_get_bot_list:
result = await list_bots()

assert result == bot_list
mock_get_bot_list.assert_awaited_once()

@pytest.mark.asyncio
async def test_install():

mock_jbbot_code = JBBotCode(
name = "Bot1",
status = "active",
dsl = "test_dsl",
code = "test_code",
requirements = "codaio",
index_urls = ["index_url_1","index_url_2"],
version = "1.0.0",
)

mock_bot1 = JBBot(id="test_bot_1",
name=mock_jbbot_code.name,
status=mock_jbbot_code.status,
dsl = mock_jbbot_code.dsl,
code = mock_jbbot_code.code,
requirements = mock_jbbot_code.requirements,
index_urls = mock_jbbot_code.index_urls,
version = mock_jbbot_code.version)

with patch("app.handlers.v2.bot.create_bot", return_value = mock_bot1) as mock_create_bot:
result = await install(mock_jbbot_code)

assert isinstance(result,Flow)
assert result.source == "api"
assert result.intent == FlowIntent.BOT
assert isinstance(result.bot_config,BotConfig)
assert result.bot_config.bot_id == mock_bot1.id
assert isinstance(result.bot_config.bot,Bot)
assert result.bot_config.bot.name == mock_jbbot_code.name
assert result.bot_config.bot.fsm_code == mock_jbbot_code.code
assert result.bot_config.bot.requirements_txt == mock_jbbot_code.requirements
assert result.bot_config.bot.index_urls == mock_jbbot_code.index_urls
assert result.bot_config.bot.version == mock_bot1.version

mock_create_bot.assert_awaited_once_with(mock_jbbot_code.model_dump())
Loading

0 comments on commit f50e47a

Please sign in to comment.