-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mail channel availability verification (#1727)
* Mail channel availability verification * Mail channel availability verification * added doc strings --------- Co-authored-by: spandan_mondal <[email protected]>
- Loading branch information
Showing
6 changed files
with
196 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -589,3 +589,43 @@ def test_get_log_exception(self): | |
|
||
|
||
|
||
@pytest.fixture | ||
def config_dict(self): | ||
return { | ||
'email_account': '[email protected]', | ||
'subjects': 'subject1,subject2' | ||
} | ||
|
||
@patch('kairon.shared.chat.processor.ChatDataProcessor.get_all_channel_configs') | ||
def test_check_email_config_exists_no_existing_config(self,mock_get_all_channel_configs, config_dict): | ||
mock_get_all_channel_configs.return_value = [] | ||
result = MailProcessor.check_email_config_exists(config_dict) | ||
assert result == False | ||
|
||
@patch('kairon.shared.chat.processor.ChatDataProcessor.get_all_channel_configs') | ||
def test_check_email_config_exists_same_config_exists(self, mock_get_all_channel_configs, config_dict): | ||
mock_get_all_channel_configs.return_value = [{ | ||
'config': config_dict | ||
}] | ||
result = MailProcessor.check_email_config_exists(config_dict) | ||
assert result == True | ||
|
||
@patch('kairon.shared.chat.processor.ChatDataProcessor.get_all_channel_configs') | ||
def test_check_email_config_exists_different_config_exists(self,mock_get_all_channel_configs, config_dict): | ||
existing_config = config_dict.copy() | ||
existing_config['subjects'] = 'subject3' | ||
mock_get_all_channel_configs.return_value = [{ | ||
'config': existing_config | ||
}] | ||
result = MailProcessor.check_email_config_exists(config_dict) | ||
assert result == False | ||
|
||
@patch('kairon.shared.chat.processor.ChatDataProcessor.get_all_channel_configs') | ||
def test_check_email_config_exists_partial_subject_match(self, mock_get_all_channel_configs, config_dict): | ||
existing_config = config_dict.copy() | ||
existing_config['subjects'] = 'subject1,subject3' | ||
mock_get_all_channel_configs.return_value = [{ | ||
'config': existing_config | ||
}] | ||
result = MailProcessor.check_email_config_exists(config_dict) | ||
assert result == True |
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 |
---|---|---|
|
@@ -937,6 +937,105 @@ async def test_mongotracker_save(self): | |
assert data[0]['type'] == 'flattened' | ||
|
||
|
||
def test_get_all_channel_configs(self): | ||
configs = list(ChatDataProcessor.get_all_channel_configs('telegram')) | ||
assert len(configs) == 1 | ||
assert configs[0].get("connector_type") == "telegram" | ||
assert str(configs[0]["config"].get("access_token")).__contains__("***") | ||
|
||
configs = list(ChatDataProcessor.get_all_channel_configs('telegram', mask_characters=False)) | ||
assert len(configs) == 1 | ||
assert configs[0].get("connector_type") == "telegram" | ||
assert not str(configs[0]["config"].get("access_token")).__contains__("***") | ||
|
||
@patch('kairon.shared.channels.mail.scheduler.MailScheduler.request_epoch') | ||
@patch('kairon.shared.chat.processor.ChatDataProcessor.get_all_channel_configs') | ||
def test_mail_channel_save_duplicate_error(self, mock_get_all_channels, mock_request_epock, monkeypatch): | ||
def __get_bot(*args, **kwargs): | ||
return {"account": 1000} | ||
|
||
monkeypatch.setattr(AccountProcessor, "get_bot", __get_bot) | ||
|
||
mock_get_all_channels.return_value = [{ | ||
'connector_type': 'mail', | ||
'config': { | ||
'email_account': '[email protected]', | ||
'subjects': 'subject1,subject2' | ||
} | ||
}] | ||
|
||
#error case | ||
#same email and subject | ||
with pytest.raises(AppException, match='Email configuration already exists for same email address and subject'): | ||
ChatDataProcessor.save_channel_config({ | ||
'connector_type': 'mail', | ||
'config': { | ||
'email_account': '[email protected]', | ||
'subjects': 'subject1,subject2', | ||
'email_password': 'test', | ||
'imap_server': 'imap.gmail.com', | ||
'smtp_server': 'smtp.gmail.com', | ||
'smtp_port': '587' | ||
} | ||
}, 'test', 'test') | ||
|
||
#same email partical subject overlap | ||
with pytest.raises(AppException, match='Email configuration already exists for same email address and subject'): | ||
ChatDataProcessor.save_channel_config({ | ||
'connector_type': 'mail', | ||
'config': { | ||
'email_account': '[email protected]', | ||
'subjects': 'subject1', | ||
'email_password': 'test', | ||
'imap_server': 'imap.gmail.com', | ||
'smtp_server': 'smtp.gmail.com', | ||
'smtp_port': '587' | ||
} | ||
}, 'test', 'test') | ||
|
||
|
||
#non error case | ||
#different email and subject | ||
ChatDataProcessor.save_channel_config({ | ||
'connector_type': 'mail', | ||
'config': { | ||
'email_account': '[email protected]', | ||
'subjects': '', | ||
'email_password': 'test', | ||
'imap_server': 'imap.gmail.com', | ||
'smtp_server': 'smtp.gmail.com', | ||
'smtp_port': '587' | ||
} | ||
}, 'test', 'test') | ||
|
||
#different email same subject | ||
ChatDataProcessor.save_channel_config({ | ||
'connector_type': 'mail', | ||
'config': { | ||
'email_account': '[email protected]', | ||
'subjects': '', | ||
'email_password': 'subject1,subject2', | ||
'imap_server': 'imap.gmail.com', | ||
'smtp_server': 'smtp.gmail.com', | ||
'smtp_port': '587' | ||
} | ||
}, 'test', 'test') | ||
|
||
#same email different subject | ||
ChatDataProcessor.save_channel_config({ | ||
'connector_type': 'mail', | ||
'config': { | ||
'email_account': '[email protected]', | ||
'subjects': 'apple', | ||
'email_password': 'test', | ||
'imap_server': 'imap.gmail.com', | ||
'smtp_server': 'smtp.gmail.com', | ||
'smtp_port': '587' | ||
} | ||
}, 'test', 'test') | ||
assert mock_request_epock.call_count == 3 | ||
|
||
Channels.objects(connector_type='mail').delete() | ||
|
||
|
||
@pytest.mark.asyncio | ||
|