Exemplo n.º 1
0
    def test_functional(self):
        pool = yield self.getPool()

        handle = yield ormHandle(pool)

        foo = yield handle.insert(self.Foo())
        foo.age = 22

        yield handle.update(foo)

        foos = yield handle.find(self.Foo)
        foo2 = foos[0]
        self.assertEqual(foo2.age, 22)
        foo2.age = 23

        foos = yield handle.query(Query(self.Foo))
        self.assertEqual(len(foos), 1)

        yield handle.update(foo2)
        yield handle.refresh(foo)
        self.assertEqual(foo.age, 23)

        foos = yield handle.find(self.Foo, Eq(self.Foo.age, 20))
        self.assertEqual(len(foos), 0)

        yield handle.delete(foo)

        foos = yield handle.find(self.Foo)
        self.assertEqual(len(foos), 0)
Exemplo n.º 2
0
    def test_interaction(self):
        """
        You can do a bunch of things in a transaction
        """
        pool = yield self.getPool()

        handle = yield ormHandle(pool)

        @defer.inlineCallbacks
        def interaction(handle):
            foo = yield handle.insert(self.Foo())
            foo.age = 22

            yield handle.update(foo)

            foos = yield handle.find(self.Foo)
            foo2 = foos[0]
            self.assertEqual(foo2.age, 22)
            foo2.age = 23

            foos = yield handle.query(Query(self.Foo))
            self.assertEqual(len(foos), 1)

            yield handle.update(foo2)
            yield handle.refresh(foo)
            self.assertEqual(foo.age, 23)

            foos = yield handle.find(self.Foo, Eq(self.Foo.age, 20))
            self.assertEqual(len(foos), 0)

            yield handle.delete(foo)
            foos = yield handle.find(self.Foo)
            self.assertEqual(len(foos), 0)

        yield handle.transact(interaction)
Exemplo n.º 3
0
 def test_pool(self):
     """
     The ormHandle should have a pool attribute that you can use directly.
     """
     pool = yield self.getPool()
     handle = yield ormHandle(pool)
     self.assertEqual(handle.pool, pool)
Exemplo n.º 4
0
    def test_interaction_commitOnSuccess(self):
        """
        The transaction should be committed on success.
        """
        pool = yield self.getPool()

        handle = yield ormHandle(pool)
        foo = yield handle.insert(self.Foo())

        @defer.inlineCallbacks
        def interaction(handle, foo):
            yield handle.delete(foo)

        yield handle.transact(interaction, foo)

        foos = yield handle.find(self.Foo)
        self.assertEqual(len(foos), 0, "Should have deleted the object")
Exemplo n.º 5
0
    def test_interaction_rollbackOnError(self):
        """
        The transaction will be rolled back on error
        """
        pool = yield self.getPool()

        handle = yield ormHandle(pool)
        foo = yield handle.insert(self.Foo())

        @defer.inlineCallbacks
        def interaction(handle, foo):
            yield handle.delete(foo)
            raise Exception('error')

        d = handle.transact(interaction, foo)
        self.assertFailure(d, Exception)

        foos = yield handle.find(self.Foo)
        self.assertEqual(len(foos), 1, "Should not have deleted the object")