Пример #1
0
    def test_note_transitive(self):

        Thing = namedtuple("Thing", ["name"])
        with self.db as con:
            rv = SchemaBase.populate(
                con, [
                    SchemaBaseTests.Ownership,
                    Thing("cat"),
                    Thing("hat")
                ]
            )

            rv = SchemaBase.note(
                con,
                Thing("cat"),
                SchemaBaseTests.Ownership.acquired,
                Thing("hat"),
                text="A cat in a hat!"
            )

            cur = con.cursor()
            cur.execute("select count(*) from touch")
            rv = tuple(cur.fetchone())[0]
            self.assertEqual(1, rv)

            cur.execute(
                "select s.name, state.name, o.name, note.text "
                "from state join touch on state.id = touch.state "
                "join entity as s on touch.sbjct = s.id "
                "left outer join entity as o on touch.objct = o.id "
                "left outer join note on note.touch = touch.id"
            )
            self.assertEqual(("cat", "acquired", "hat", "A cat in a hat!"), tuple(cur.fetchone()))
Пример #2
0
    def handle_memory(self, obj):
        """Handle a memory event.

        This function accesses the internal database. It writes a record
        containing state information and an optional note.

        :param obj: A :py:class:`~turberfield.dialogue.model.Model.Memory`
            object.
        :return: The supplied object.

        """
        if obj.subject is not None:
            with self.con as db:
                SchemaBase.note(
                    db,
                    obj.subject,
                    obj.state,
                    obj.object,
                    text=obj.text,
                    html=obj.html,
                )
        return obj