From 0723b8a1a5cd463e5e0f3dbcef6e7301d103e576 Mon Sep 17 00:00:00 2001 From: Sunandhita B Date: Mon, 9 Dec 2024 13:21:34 +0530 Subject: [PATCH] Modified api tests --- api/tests/test_bot.py | 9 ++++++--- api/tests/test_channel.py | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/api/tests/test_bot.py b/api/tests/test_bot.py index 1bca7e5..78cd45d 100644 --- a/api/tests/test_bot.py +++ b/api/tests/test_bot.py @@ -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) @@ -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(): @@ -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) @@ -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(): diff --git a/api/tests/test_channel.py b/api/tests/test_channel.py index c9e2eab..3b5889f 100644 --- a/api/tests/test_channel.py +++ b/api/tests/test_channel.py @@ -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) @@ -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():