Exemplo n.º 1
0
    def test_create_drop_bound(self):

        for meta in (MetaData, ThreadLocalMetaData):
            for bind in (testing.db, testing.db.connect()):
                metadata = meta()
                table = Table("test_table", metadata, Column("foo", Integer))
                metadata.bind = bind
                assert metadata.bind is table.bind is bind
                metadata.create_all()
                assert table.exists()
                metadata.drop_all()
                table.create()
                table.drop()
                assert not table.exists()

                metadata = meta()
                table = Table("test_table", metadata, Column("foo", Integer))

                metadata.bind = bind

                assert metadata.bind is table.bind is bind
                metadata.create_all()
                assert table.exists()
                metadata.drop_all()
                table.create()
                table.drop()
                assert not table.exists()
                if isinstance(bind, engine.Connection):
                    bind.close()
 def test_checkfirst_table(self, connection):
     m = MetaData()
     s = Sequence("my_sequence")
     t = Table("t", m, Column("c", Integer, s, primary_key=True))
     t.create(connection, checkfirst=False)
     assert self._has_sequence(connection, "my_sequence")
     t.create(connection, checkfirst=True)
     t.drop(connection, checkfirst=False)
     assert not self._has_sequence(connection, "my_sequence")
     t.drop(connection, checkfirst=True)
Exemplo n.º 3
0
 def test_create_drop_explicit(self):
     metadata = MetaData()
     table = Table("test_table", metadata, Column("foo", Integer))
     for bind in (testing.db, testing.db.connect()):
         for args in [([], {"bind": bind}), ([bind], {})]:
             metadata.create_all(*args[0], **args[1])
             assert table.exists(*args[0], **args[1])
             metadata.drop_all(*args[0], **args[1])
             table.create(*args[0], **args[1])
             table.drop(*args[0], **args[1])
             assert not table.exists(*args[0], **args[1])
Exemplo n.º 4
0
 def test_create_drop_constructor_bound(self):
     for bind in (testing.db, testing.db.connect()):
         try:
             for args in (([bind], {}), ([], {"bind": bind})):
                 metadata = MetaData(*args[0], **args[1])
                 table = Table(
                     "test_table", metadata, Column("foo", Integer)
                 )
                 assert metadata.bind is table.bind is bind
                 metadata.create_all()
                 assert table.exists()
                 metadata.drop_all()
                 table.create()
                 table.drop()
                 assert not table.exists()
         finally:
             if isinstance(bind, engine.Connection):
                 bind.close()
    def test_rollback_deadlock(self):
        """test that returning connections to the pool clears any object
        locks."""

        conn1 = testing.db.connect()
        conn2 = testing.db.connect()
        users = Table(
            "deadlock_users",
            metadata,
            Column("user_id", INT, primary_key=True),
            Column("user_name", VARCHAR(20)),
            test_needs_acid=True,
        )
        users.create(conn1)
        conn1.execute("select * from deadlock_users")
        conn1.close()

        # without auto-rollback in the connection pool's return() logic,
        # this deadlocks in PostgreSQL, because conn1 is returned to the
        # pool but still has a lock on "deadlock_users". comment out the
        # rollback in pool/ConnectionFairy._close() to see !

        users.drop(conn2)
        conn2.close()