diff --git a/tests/unit_test/data_processor/data_processor_test.py b/tests/unit_test/data_processor/data_processor_test.py index e9dce9d83..e3f313c8a 100644 --- a/tests/unit_test/data_processor/data_processor_test.py +++ b/tests/unit_test/data_processor/data_processor_test.py @@ -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': 'user@integration.com', + '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', 'user@integration.com') + 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': 'user@integration.com', 'status': True} diff --git a/tests/unit_test/data_processor/history_test.py b/tests/unit_test/data_processor/history_test.py index 3048b9cc3..3428736b9 100644 --- a/tests/unit_test/data_processor/history_test.py +++ b/tests/unit_test/data_processor/history_test.py @@ -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': 'mathew.anil@digite.com', + '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")