def test_conversation_operations_multi_client_no_storage(self): config = BotConversationsConfiguration() config._multi_client = True mgr = ConversationManager(config) convo_dir = self.get_temp_dir() + os.sep + "storage" + os.sep + "conversations" if os.path.exists(convo_dir): shutil.rmtree(convo_dir) client = TestClient() #client.add_conversation_store(convo_dir) mgr.initialise(client.storage_factory) client_context = client.create_client_context("user1") conversation = mgr.get_conversation(client_context) question1 = Question.create_from_text(client_context, "Hello There") question1.sentence(0).response = "Hi" conversation.record_dialog(question1) mgr.save_conversation(client_context) question2 = Question.create_from_text(client_context, "Hello There Again") question2.sentence(0).response = "Hi Again" conversation.record_dialog(question2) mgr.save_conversation(client_context) question3 = Question.create_from_text(client_context, "Hello There Again Again") question3.sentence(0).response = "Hi Again Again" conversation.record_dialog(question3) mgr.save_conversation(client_context) conversation2 = mgr.get_conversation(client_context) self.assertIsNotNone(conversation2) self.assertEqual(len(mgr.conversations), 1) mgr.empty() self.assertEqual(len(mgr.conversations), 0) conversation = mgr.get_conversation(client_context) self.assertEqual(len(mgr.conversations), 1) if os.path.exists(convo_dir): shutil.rmtree(convo_dir) self.assertIsNotNone(conversation) self.assertEqual(len(conversation.questions), 0)
def test_conversation_operations(self): config = BotConversationsConfiguration() mgr = ConversationManager(config) if os.path.exists("./storage/conversations"): shutil.rmtree("./storage/conversations") client = TestClient() client.add_conversation_store("./storage/conversations") mgr.initialise(client.storage_factory) client_context = client.create_client_context("user1") conversation = mgr.get_conversation(client_context) question1 = Question.create_from_text(client_context, "Hello There") question1.sentence(0).response = "Hi" conversation.record_dialog(question1) mgr.save_conversation(client_context) question2 = Question.create_from_text(client_context, "Hello There Again") question2.sentence(0).response = "Hi Again" conversation.record_dialog(question2) mgr.save_conversation(client_context) question3 = Question.create_from_text(client_context, "Hello There Again Again") question3.sentence(0).response = "Hi Again Again" conversation.record_dialog(question3) mgr.save_conversation(client_context) self.assertTrue( os.path.exists("./storage/conversations/testclient_user1.conv")) self.assertEqual(len(mgr.conversations), 1) mgr.empty() self.assertEqual(len(mgr.conversations), 0) conversation = mgr.get_conversation(client_context) self.assertEqual(len(mgr.conversations), 1) self.assertIsNotNone(conversation) self.assertEqual(len(conversation.questions), 3) if os.path.exists("./storage/conversations"): shutil.rmtree("./storage/conversations")