Example #1
0
    def test_conversation_operations_no_conversation(self):
        config = BotConversationsConfiguration()
        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)

        del mgr._conversations[client_context.userid]

        mgr.save_conversation(client_context)
    def test_get_conversation_multi_client(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)
        mgr.configuration._multi_client = True

        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)

        conversation = mgr.get_conversation(client_context)
        self.assertEqual(len(mgr.conversations), 1)

        if os.path.exists("./storage/conversations"):
            shutil.rmtree("./storage/conversations")
    def test_remove_conversation_invalid_userid(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")
        self.assertEqual(len(mgr.conversations), 0)
        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)
        self.assertTrue(
            os.path.exists("./storage/conversations/testclient_user1.conv"))

        client_context._userid = "user2"
        mgr.remove_conversation(client_context)
        self.assertTrue(
            os.path.exists("./storage/conversations/testclient_user1.conv"))
        self.assertFalse(
            os.path.exists("./storage/conversations/testclient_user2.conv"))

        if os.path.exists("./storage/conversations"):
            shutil.rmtree("./storage/conversations")
Example #4
0
    def test_initialise(self):
        config = BotConversationsConfiguration()
        mgr = ConversationManager(config)

        client = TestClient()
        client.add_conversation_store("./storage/conversations")

        mgr.initialise(client.storage_factory)
        self.assertIsNotNone(mgr.storage)
Example #5
0
    def test_conversation_operations_multi_client(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), 3)
    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")
    def test_save_conversation_no_userid_data(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")
        mgr.get_conversation(client_context)
        self.assertEqual(len(mgr.conversations), 1)

        mgr.save_conversation(client_context)
        self.assertFalse(
            os.path.exists("./storage/conversations/testclient_user1.conv"))