예제 #1
0
    def test_after_delete(self):

        from cocktail.persistence import datastore
        from woost.models import DeleteTrigger, Item

        # Declare the trigger
        trigger, response_log = self.make_trigger(DeleteTrigger,
                                                  execution_point="after",
                                                  batch_execution=False)

        # Create and insert an item
        item = Item()
        item.insert()
        datastore.commit()

        # Delete the item, but abort the transaction. This shouldn't trigger
        # the response.
        item.delete()
        datastore.abort()
        assert not response_log

        # Delete the inserted item and commit the transaction. This should
        # trigger the response.
        item.delete()
        datastore.commit()

        assert len(response_log) == 1
        response = response_log[0]
        assert response["trigger"] is trigger
        assert response["items"] == [item]
        assert response["user"] is self.user
        assert not response["batch"]
예제 #2
0
    def test_before_delete(self):

        from woost.models import DeleteTrigger, Item

        # Declare the trigger
        trigger, response_log = self.make_trigger(DeleteTrigger,
                                                  execution_point="before",
                                                  batch_execution=False)

        # Create and insert two items
        item1 = Item()
        item1.insert()

        item2 = Item()
        item2.insert()

        # Delete the items. This should trigger the response twice.
        item1.delete()
        assert len(response_log) == 1

        item2.delete()
        assert len(response_log) == 2

        response = response_log[0]
        assert response["trigger"] is trigger
        assert response["items"] == [item1]
        assert response["user"] is self.user
        assert not response["batch"]

        response = response_log[1]
        assert response["trigger"] is trigger
        assert response["items"] == [item2]
        assert response["user"] is self.user
        assert not response["batch"]
예제 #3
0
    def test_delete(self):

        from datetime import datetime
        from woost.models import (Item, User, ChangeSet, changeset_context)

        author = User()
        author.insert()

        item = Item()
        item.insert()

        with changeset_context(author) as changeset:
            item.delete()

        assert list(ChangeSet.select()) == [changeset]
        assert changeset.author is author
        assert isinstance(changeset.date, datetime)

        assert changeset.changes.keys() == [item.id]
        change = changeset.changes[item.id]
        assert change.target is item
        assert change.action == "delete"
        assert change.changeset is changeset
        assert item.changes == [change]

        assert not item.id in Item.index
예제 #4
0
    def test_after_insert_modify_delete(self):

        from cocktail.persistence import datastore
        from woost.models import (Item, User, InsertTrigger, ModifyTrigger,
                                  DeleteTrigger)

        response_log = []

        insert_trigger = self.make_trigger(InsertTrigger,
                                           response_log,
                                           execution_point="after",
                                           batch_execution=False)

        modify_trigger = self.make_trigger(ModifyTrigger,
                                           response_log,
                                           execution_point="after",
                                           batch_execution=False)

        delete_trigger = self.make_trigger(DeleteTrigger,
                                           response_log,
                                           execution_point="after",
                                           batch_execution=False)

        # Create and insert an item
        item = Item()
        item.qname = "foo"
        item.insert()

        # Modify it
        item.qname = "bar"
        item.global_id = "foobar"

        # Delete it
        item.delete()

        # Commit the transaction; this should execute all the scheduled
        # responses
        datastore.commit()
        assert len(response_log) == 4

        response = response_log.pop(0)
        assert response["trigger"] is insert_trigger
        assert response["items"] == [item]
        assert response["user"] is self.user
        assert not response["batch"]

        for member in (Item.qname, Item.global_id):
            response = response_log.pop(0)
            assert response["trigger"] is modify_trigger
            assert response["items"] == [item]
            assert response["context"]["member"] is member
            assert response["user"] is self.user
            assert not response["batch"]

        response = response_log[0]
        assert response["trigger"] is delete_trigger
        assert response["items"] == [item]
        assert response["user"] is self.user
        assert not response["batch"]
예제 #5
0
    def test_before_create_insert_modify_delete(self):

        from woost.models import (Item, CreateTrigger, InsertTrigger,
                                  ModifyTrigger, DeleteTrigger)

        response_log = []

        create_trigger = self.make_trigger(CreateTrigger,
                                           response_log,
                                           execution_point="before",
                                           batch_execution=False)

        insert_trigger = self.make_trigger(InsertTrigger,
                                           response_log,
                                           execution_point="before",
                                           batch_execution=False)

        modify_trigger = self.make_trigger(ModifyTrigger,
                                           response_log,
                                           execution_point="before",
                                           batch_execution=False)

        delete_trigger = self.make_trigger(DeleteTrigger,
                                           response_log,
                                           execution_point="before",
                                           batch_execution=False)

        # Create and insert an item
        item = Item(qname="foo")
        item.insert()

        assert len(response_log) == 2
        response = response_log.pop()
        assert response["trigger"] is insert_trigger
        assert response["items"] == [item]
        assert response["user"] is self.user
        assert not response["batch"]

        response = response_log.pop()
        assert response["trigger"] is create_trigger
        assert response["items"] == [item]
        assert response["user"] is self.user
        assert response["context"]["values"]["qname"] == "foo"
        assert not response["batch"]

        # Modify the item
        item.qname = "bar"

        assert len(response_log) == 1
        response = response_log.pop()
        assert response["trigger"] is modify_trigger
        assert response["items"] == [item]
        assert response["context"]["member"] is Item.qname
        assert response["user"] is self.user
        assert not response["batch"]

        # Delete the item
        item.delete()

        assert len(response_log) == 1
        response = response_log.pop()
        assert response["trigger"] is delete_trigger
        assert response["items"] == [item]
        assert response["user"] is self.user
        assert not response["batch"]