-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
spandan_mondal
committed
Dec 2, 2024
1 parent
e1d3738
commit 9176d03
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -656,6 +656,57 @@ async def test_classify_messages_invalid_llm_response(self, mock_get_channel_con | |
assert not ans | ||
|
||
|
||
@patch("kairon.shared.channels.mail.processor.MailProcessor.classify_messages") | ||
@patch("kairon.shared.channels.mail.processor.MailProcessor.login_smtp") | ||
@patch("kairon.shared.channels.mail.processor.MailProcessor.logout_smtp") | ||
@patch("kairon.shared.channels.mail.processor.MailProcessor.send_mail") | ||
@patch("kairon.chat.utils.ChatUtils.process_messages_via_bot") | ||
@patch("kairon.shared.channels.mail.processor.LLMProcessor") | ||
@pytest.mark.asyncio | ||
async def test_process_messages(self, mock_llm_processor, mock_process_messages_via_bot, mock_send_mail, mock_logout_smtp, mock_login_smtp, | ||
mock_classify_messages): | ||
|
||
|
||
# Arrange | ||
bot = pytest.mail_test_bot | ||
batch = [{"mail_id": "[email protected]", "subject": "Test Subject", "date": "2023-10-10", "body": "Test Body"}] | ||
mock_classify_messages.return_value = [{ | ||
"intent": "test_intent", | ||
"entities": {"entity_name": "value"}, | ||
"mail_id": "[email protected]", | ||
"subject": "Test Subject", | ||
"name": "spandan" | ||
}] | ||
mock_process_messages_via_bot.return_value = [{ | ||
"slots": ["name: spandan"], | ||
"response": [{"text": "Test Response"}] | ||
}] | ||
|
||
mock_llm_processor_instance = MagicMock() | ||
mock_llm_processor.return_value = mock_llm_processor_instance | ||
|
||
# Act | ||
await MailProcessor.process_messages(bot, batch) | ||
|
||
# Assert | ||
mock_classify_messages.assert_called_once_with(batch) | ||
mock_process_messages_via_bot.assert_called_once() | ||
mock_login_smtp.assert_called_once() | ||
mock_send_mail.assert_called_once() | ||
mock_logout_smtp.assert_called_once() | ||
|
||
@patch("kairon.shared.channels.mail.processor.MailProcessor.classify_messages") | ||
@pytest.mark.asyncio | ||
async def test_process_messages_exception(self, mock_classify_messages): | ||
# Arrange | ||
bot = "test_bot" | ||
batch = [{"mail_id": "[email protected]", "subject": "Test Subject", "date": "2023-10-10", "body": "Test Body"}] | ||
mock_classify_messages.side_effect = Exception("Test Exception") | ||
|
||
# Act & Assert | ||
with pytest.raises(AppException): | ||
await MailProcessor.process_messages(bot, batch) | ||
|
||
|
||
|
||
|
||
|