-
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.
Test chat history config la flag (#1280)
* changed conversation fetching for chat history and chat client to use flattened data properly * added live_agent_enabled flag to chat client config * added additional tests --------- Co-authored-by: spandan.mondal <[email protected]>
- Loading branch information
Showing
2 changed files
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 |
---|---|---|
|
@@ -75,6 +75,7 @@ | |
from kairon.shared.data.training_data_generation_processor import TrainingDataGenerationProcessor | ||
from kairon.shared.data.utils import DataUtility | ||
from kairon.shared.importer.processor import DataImporterLogProcessor | ||
from kairon.shared.live_agent.live_agent import LiveAgentHandler | ||
from kairon.shared.llm.gpt3 import GPT3FAQEmbedding | ||
from kairon.shared.metering.constants import MetricType | ||
from kairon.shared.metering.data_object import Metering | ||
|
@@ -6509,6 +6510,22 @@ def _mock_bot_info(*args, **kwargs): | |
'/api/bot/.+/metric/user/logs/user_metrics' | ||
], 'access-limit': ['/api/auth/.+/token/refresh']} | ||
|
||
def test_get_chat_client_config_live_agent_enabled_false(self, monkeypatch): | ||
def _mock_bot_info(*args, **kwargs): | ||
return { | ||
"_id": "9876543210", 'name': 'test_bot', 'account': 2, 'user': '[email protected]', | ||
'status': True, | ||
"metadata": {"source_bot_id": None} | ||
} | ||
def _mock_is_live_agent_service_available(*args, **kwargs): | ||
return False | ||
monkeypatch.setattr(AccountProcessor, 'get_bot', _mock_bot_info) | ||
monkeypatch.setattr(LiveAgentHandler, 'is_live_agent_service_available', _mock_is_live_agent_service_available) | ||
processor = MongoProcessor() | ||
actual_config = processor.get_chat_client_config('test_bot', '[email protected]') | ||
assert actual_config.config['live_agent_enabled'] == False | ||
|
||
|
||
def test_save_chat_client_config_without_whitelisted_domain(self, monkeypatch): | ||
def _mock_bot_info(*args, **kwargs): | ||
return {'name': 'test', 'account': 1, 'user': '[email protected]', 'status': 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 |
---|---|---|
|
@@ -395,6 +395,40 @@ def test_flatten_conversation_range(self, mock_client): | |
assert f_count["conversation_data"] == [] | ||
assert message is None | ||
|
||
@mock.patch('kairon.history.processor.MongoClient', autospec=True) | ||
def test_flatten_conversation_with_data_no_ids(self, mock_client): | ||
with open("./tests/testing_data/history/flattened_conversations.json", "r") as f: | ||
conversations = json.load(f) | ||
timestamp = time.time() - 2000 | ||
for conversation in conversations: | ||
conversation['timestamp'] = timestamp | ||
timestamp += 200 | ||
mock_client.return_value = mongomock.MongoClient(Utility.environment['tracker']['url']) | ||
collection = mock_client().get_database().get_collection("tests_flattened") | ||
collection.insert_many(conversations) | ||
r_dict, message = HistoryProcessor.flatten_conversations("tests_flattened") | ||
|
||
for conversation in r_dict["conversation_data"]: | ||
assert not conversation.get("id") | ||
assert not conversation.get("_id") | ||
assert conversation.get("timestamp") | ||
|
||
assert len(r_dict["conversation_data"]) == 11 | ||
assert message is None | ||
r_dict["conversation_data"][0].pop('timestamp') | ||
assert r_dict["conversation_data"][0] == { | ||
'type': 'flattened', 'sender_id': '[email protected]', | ||
'data': { | ||
'user_input': 'Hi', | ||
'intent': 'nlu_fallback', | ||
'confidence': 0.7, 'action': ['utter_please_rephrase'], | ||
'bot_response_text': 'Sorry, I did not get you!', | ||
'bot_response_data': { | ||
'elements': None, 'quick_replies': None, 'buttons': None, 'attachment': None, | ||
'image': None, 'custom': None} | ||
} | ||
} | ||
|
||
@mock.patch('kairon.history.processor.MongoClient', autospec=True) | ||
def test_total_conversation_range_error(self, mock_client): | ||
mock_client.side_effect = ServerSelectionTimeoutError("Failed to connect") | ||
|