-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* mail read schedule stop mechanism, filters and their related tests * mail read schedule stop mechanism, filters and their related tests * mail read schedule stop mechanism, filters and their related tests * mail read schedule stop mechanism, filters and their related tests --------- Co-authored-by: spandan_mondal <[email protected]>
- Loading branch information
Showing
10 changed files
with
261 additions
and
20 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
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
from unittest.mock import patch, MagicMock | ||
|
||
import pytest | ||
from imap_tools import MailMessage | ||
from imap_tools import MailMessage, AND | ||
|
||
from mongoengine import connect, disconnect | ||
from uuid6 import uuid7 | ||
|
@@ -276,6 +276,53 @@ def test_process_mail(self, mock_get_channel_config): | |
assert result == "Hello John Doe, How can I help you today?" | ||
|
||
|
||
|
||
@patch("kairon.shared.chat.processor.ChatDataProcessor.get_channel_config") | ||
@pytest.mark.asyncio | ||
async def test_generate_criteria(self, mock_get_channel_config): | ||
bot_id = pytest.mail_test_bot | ||
mock_get_channel_config.return_value = { | ||
'config': { | ||
'email_account': "[email protected]", | ||
'email_password': "password", | ||
'imap_server': "imap.testuser.com", | ||
} | ||
} | ||
|
||
mp = MailProcessor(bot=bot_id) | ||
mp.state.last_email_uid = 123 | ||
#seen | ||
criteria = mp.generate_criteria(read_status="seen") | ||
print(criteria) | ||
assert criteria == '((SEEN) (UID 124:*))' | ||
|
||
#unseen | ||
criteria = mp.generate_criteria(read_status="unseen") | ||
assert criteria == '((UNSEEN) (UID 124:*))' | ||
|
||
#default | ||
criteria = mp.generate_criteria() | ||
assert criteria == '((UID 124:*))' | ||
|
||
#subjects | ||
criteria = mp.generate_criteria(subjects=["Test Subject", "another test subject"]) | ||
assert criteria == '((OR SUBJECT "Test Subject" SUBJECT "another test subject") (UID 124:*))' | ||
|
||
#from | ||
criteria = mp.generate_criteria(from_addresses=["info", "[email protected]", "[email protected]"]) | ||
assert criteria == '((OR OR FROM "[email protected]" FROM "[email protected]" FROM "info") (UID 124:*))' | ||
|
||
#mix | ||
criteria = mp.generate_criteria(read_status="unseen", | ||
subjects=["Test Subject", "another test subject", "happy"], | ||
ignore_subjects=['cat'], | ||
ignore_from=["info", "nomreply"], | ||
from_addresses=["@digite.com", "@nimblework.com"]) | ||
|
||
assert criteria == '((UNSEEN) (OR OR SUBJECT "Test Subject" SUBJECT "another test subject" SUBJECT "happy") NOT ((SUBJECT "cat")) (OR FROM "@digite.com" FROM "@nimblework.com") NOT ((FROM "info")) NOT ((FROM "nomreply")) (UID 124:*))' | ||
|
||
|
||
|
||
@patch("kairon.shared.channels.mail.processor.MailProcessor.logout_imap") | ||
@patch("kairon.shared.channels.mail.processor.MailProcessor.process_message_task") | ||
@patch("kairon.shared.channels.mail.processor.MailBox") | ||
|
@@ -538,4 +585,7 @@ def test_get_log_exception(self): | |
BotSettings.objects(user="mail_channel_test_user_acc").delete() | ||
Bot.objects(user="mail_channel_test_user_acc").delete() | ||
Account.objects(user="mail_channel_test_user_acc").delete() | ||
Channels.objects(connector_type=ChannelTypes.MAIL.value).delete() | ||
Channels.objects(connector_type=ChannelTypes.MAIL.value).delete() | ||
|
||
|
||
|
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
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