Skip to content

Commit

Permalink
Made review changes and added test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahesh committed Dec 13, 2023
1 parent 4c605f0 commit f98a520
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 28 deletions.
27 changes: 27 additions & 0 deletions tests/integration_test/chat_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,33 @@ def test_business_messages_with_exception(mock_business_messages, mock_process_m
)


def test_business_messages_with_invalid_create_time():
response = client.post(
f"/api/bot/business_messages/{bot}/{token}",
headers={"Authorization": "Bearer Test"},
json={"message": {
"name": "conversations/24ab463a-a6bf-4049-b49e-cc05fb1dc384/messages/5979C5-325C-4700-BF5A-0156C39C541",
"text": "Hello!",
"createTime": "2023-12-04T06:30:46.034290Z",
"messageId": "5979C547-325C-4700-BF5A-0156C39C5641"},
"context": {
"placeId": "",
"userInfo": {
"displayName": "Mahesh Sattala",
"userDeviceLocale": "en-IN"
},
"resolvedLocale": "en"
},
"sendTime": "2023-12-04T06:30:46.662594Z",
"conversationId": "24ab463a-a6bf-4056-b49e-aa05fb1dc384",
"requestId": "5979C547-325C-4700-BF5A-0156C45C1541",
"agent": "brands/bd7e3fe0-3c3e-4b3e-4759-6e46ac0412a5/agents/3cf91834-3b5e-4c4b-a632-9575f0cc3444"
}
)
actual = response.json()
assert actual == {"status": "OK"}


@patch("kairon.chat.handlers.channels.business_messages.BusinessMessagesHandler.check_message_create_time")
@patch("kairon.chat.handlers.channels.business_messages.BusinessMessages.process_message")
def test_business_messages_without_message(mock_process_message, mock_check_message_create_time):
Expand Down
56 changes: 28 additions & 28 deletions tests/unit_test/chat/chat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,34 +421,6 @@ def __mock_endpoint(*args):
"test",
"test")

@responses.activate
def test_save_channel_config_business_messages(self):
def __mock_endpoint(*args):
return f"https://[email protected]/api/bot/business_messages/tests/test"

with patch('kairon.shared.data.utils.DataUtility.get_channel_endpoint', __mock_endpoint):
channel_endpoint = ChatDataProcessor.save_channel_config(
{
"connector_type": "business_messages",
"config": {
"type": "service_account",
"private_key_id": "fa006e13b1e17eddf3990eede45ca6111eb74945",
"private_key": "test_private_key",
"client_email": "[email protected]",
"client_id": "102056160806575769486"
}
},
"test",
"test")
assert channel_endpoint == "https://[email protected]/api/bot/business_messages/tests/test"
business_messages_config = ChatDataProcessor.get_channel_config("business_messages",
"test")
assert business_messages_config['config'] == {'type': 'service_account',
'private_key_id': 'fa006e13b1e17eddf3990eede45ca6111eb*****',
'private_key': 'test_privat*****',
'client_email': '[email protected]*****',
'client_id': '1020561608065757*****'}

@mock.patch('kairon.shared.utils.MongoClient', autospec=True)
def test_fetch_session_history_error(self, mock_mongo):
mock_mongo.side_effect = ServerSelectionTimeoutError("Failed to retrieve conversation: Failed to connect")
Expand Down Expand Up @@ -495,6 +467,34 @@ def test_fetch_session_history(self, mock_mongo):
assert len(history[0]["events"]) == 2
assert message is None

@responses.activate
def test_save_channel_config_business_messages(self):
def __mock_endpoint(*args):
return f"https://[email protected]/api/bot/business_messages/tests/test"

with patch('kairon.shared.data.utils.DataUtility.get_channel_endpoint', __mock_endpoint):
channel_endpoint = ChatDataProcessor.save_channel_config(
{
"connector_type": "business_messages",
"config": {
"type": "service_account",
"private_key_id": "fa006e13b1e17eddf3990eede45ca6111eb74945",
"private_key": "test_private_key",
"client_email": "[email protected]",
"client_id": "102056160806575769486"
}
},
"test",
"test")
assert channel_endpoint == "https://[email protected]/api/bot/business_messages/tests/test"
business_messages_config = ChatDataProcessor.get_channel_config("business_messages",
"test")
assert business_messages_config['config'] == {'type': 'service_account',
'private_key_id': 'fa006e13b1e17eddf3990eede45ca6111eb*****',
'private_key': 'test_privat*****',
'client_email': '[email protected]*****',
'client_id': '1020561608065757*****'}

def test_save_channel_config_msteams(self, monkeypatch):
bot = '5e564fbcdcf0d5fad89e3acd'

Expand Down

0 comments on commit f98a520

Please sign in to comment.