Skip to content

Commit

Permalink
Modified api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunandhita B authored and Sunandhita B committed Dec 9, 2024
1 parent 8093a34 commit 0723b8a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions api/tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def test_add_credentials_success():

with patch("app.handlers.v2.bot.get_bot_by_id", return_value = mock_bot) as mock_get_bot_by_id, \
patch("app.handlers.v2.bot.update_bot", return_value = bot_id) as mock_update_bot, \
patch("app.handlers.v2.bot.EncryptionHandler.encrypt_dict", return_value = "encrypted_test_key"):
patch("app.handlers.v2.bot.EncryptionHandler.encrypt_dict", return_value = "encrypted_test_key") as mock_encrypt_dict:

result = await add_credentials(bot_id,credentials)

Expand All @@ -75,6 +75,7 @@ async def test_add_credentials_success():

mock_get_bot_by_id.assert_awaited_once_with(bot_id)
mock_update_bot.assert_awaited_once()
mock_encrypt_dict.assert_called_once_with(credentials)

@pytest.mark.asyncio
async def test_add_credentials_failure():
Expand Down Expand Up @@ -185,14 +186,15 @@ async def test_add_channel_when_channel_creation_is_success():
status = "active",
name = "test_channel",
type = "test_type",
key = "test_key",
key = "encrypted_test_key",
app_id = "12345678",
url = "test_url"
)

with patch("app.handlers.v2.bot.get_bot_by_id", return_value = mock_bot) as mock_get_bot_by_id, \
patch("app.handlers.v2.bot.get_active_channel_by_identifier", return_value = None) as mock_get_active_channel_by_identifier, \
patch("app.handlers.v2.bot.create_channel",return_value = mock_channel) as mock_create_channel:
patch("app.handlers.v2.bot.create_channel",return_value = mock_channel) as mock_create_channel, \
patch("app.handlers.v2.bot.EncryptionHandler.encrypt_text", return_value = "encrypted_test_key") as mock_encrypt_text:

result = await add_channel(bot_id,channel_content)

Expand All @@ -204,6 +206,7 @@ async def test_add_channel_when_channel_creation_is_success():
mock_get_active_channel_by_identifier.assert_awaited_once_with(identifier = channel_content.app_id,
channel_type = channel_content.type)
mock_create_channel.assert_awaited_once_with(bot_id, channel_content.model_dump())
mock_encrypt_text.assert_called_once()

@pytest.mark.asyncio
async def test_delete_success():
Expand Down
4 changes: 3 additions & 1 deletion api/tests/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ async def test_update_success():
)

with patch("app.handlers.v2.channel.get_channel_by_id", return_value = mock_channel_object) as mock_get_channel_by_id, \
patch("app.handlers.v2.channel.update_channel", return_value = channel_id) as mock_update_channel:
patch("app.handlers.v2.channel.update_channel", return_value = channel_id) as mock_update_channel, \
patch("app.handlers.v2.bot.EncryptionHandler.encrypt_text", return_value = "encrypted_test_key") as mock_encrypt_text:

result = await update(channel_id, channel_data)

Expand All @@ -85,6 +86,7 @@ async def test_update_success():

mock_get_channel_by_id.assert_awaited_once_with(channel_id)
mock_update_channel.assert_awaited_once()
mock_encrypt_text.assert_called_once()

@pytest.mark.asyncio
async def test_activate_failure_when_channel_not_found():
Expand Down

0 comments on commit 0723b8a

Please sign in to comment.