Ejemplo n.º 1
0
    def test_match_context_in_db(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLConversationStore(engine)

        store.empty()

        client = TestClient()
        client_context = client.create_client_context("user1")

        matched_context1 = MatchContext(100,
                                        100,
                                        sentence="Hello",
                                        response="Hi There")
        matched_context1._matched_nodes = []
        matched_context1._template_node = None

        store._write_match_context_to_db(client_context, 1, matched_context1)

        store.commit()

        matched_context2 = MatchContext(100, 100)

        store._read_match_context_from_db(client_context, 1, matched_context2)

        self.assertEqual(100, matched_context2.max_search_timeout)
        self.assertEqual(100, matched_context2.max_search_depth)
        self.assertEqual("Hello", matched_context2.sentence)
        self.assertEqual("Hi There", matched_context2.response)

        store.empty()
Ejemplo n.º 2
0
    def test_get_set_matched_nodes(self):
        context = MatchContext(max_search_depth=100, max_search_timeout=60)

        context._matched_nodes = [
            Match(Match.WORD, PatternWordNode("Hello"), "Hello"),
            Match(Match.WORD, PatternWordNode("There"), "There")
        ]

        self.assertEqual(2, len(context.matched_nodes))

        matched = context.matched_nodes

        self.assertEqual(2, len(matched))