Exemple #1
0
 def test_visibility_from_other_connections (self):
     conn = MySQLdb.connect(**self._auth)
     conn2 = MySQLdb.connect(**self._auth)
     curs = conn.cursor()
     try:
         curs2 = conn2.cursor()
         curs2.execute("insert into gargleblatz (a) values (%s)" % (314159))
         self.assertEqual(curs2.rowcount, 1)
         conn2.commit()
         selection_query = "select * from gargleblatz"
         curs2.execute(selection_query)
         self.assertEqual(curs2.rowcount, 1)
         del curs2, conn2
         # create a new connection, it should see the addition
         conn3 = MySQLdb.connect(**self._auth)
         curs3 = conn3.cursor()
         curs3.execute(selection_query)
         self.assertEqual(curs3.rowcount, 1)
         # now, does the already-open connection see it?
         curs.execute(selection_query)
         self.assertEqual(curs.rowcount, 1)
         del curs3, conn3
     finally:
         # clean up my litter
         curs.execute("delete from gargleblatz where a=314159")
         conn.commit()
 def test_visibility_from_other_connections(self):
     conn = MySQLdb.connect(**self._auth)
     conn2 = MySQLdb.connect(**self._auth)
     curs = conn.cursor()
     try:
         curs2 = conn2.cursor()
         curs2.execute("insert into gargleblatz (a) values (%s)" % (314159))
         self.assertEqual(curs2.rowcount, 1)
         conn2.commit()
         selection_query = "select * from gargleblatz"
         curs2.execute(selection_query)
         self.assertEqual(curs2.rowcount, 1)
         del curs2, conn2
         # create a new connection, it should see the addition
         conn3 = MySQLdb.connect(**self._auth)
         curs3 = conn3.cursor()
         curs3.execute(selection_query)
         self.assertEqual(curs3.rowcount, 1)
         # now, does the already-open connection see it?
         curs.execute(selection_query)
         self.assertEqual(curs.rowcount, 1)
         del curs3, conn3
     finally:
         # clean up my litter
         curs.execute("delete from gargleblatz where a=314159")
         conn.commit()
def mysql_requirement(_f):
    """We want to skip tests if using pyevent, MySQLdb is not installed, or if
    there is no database running on the localhost that the auth file grants
    us access to.
    
    This errs on the side of skipping tests if everything is not right, but
    it's better than a million tests failing when you don't care about mysql
    support."""
    if MySQLdb is False:
        print "Skipping mysql tests, MySQLdb not importable"
        return False
    try:
        auth = get_database_auth()['MySQLdb'].copy()
        MySQLdb.connect(**auth)
        return True
    except MySQLdb.OperationalError:
        print "Skipping mysql tests, error when connecting:"
        traceback.print_exc()
        return False
Exemple #4
0
def mysql_requirement (_f):
    """We want to skip tests if using pyevent, MySQLdb is not installed, or if
    there is no database running on the localhost that the auth file grants
    us access to.
    
    This errs on the side of skipping tests if everything is not right, but
    it's better than a million tests failing when you don't care about mysql
    support."""
    if MySQLdb is False:
        print "Skipping mysql tests, MySQLdb not importable"
        return False
    try:
        auth = get_database_auth()['MySQLdb'].copy()
        MySQLdb.connect(**auth)
        return True
    except MySQLdb.OperationalError:
        print "Skipping mysql tests, error when connecting:"
        traceback.print_exc()
        return False
 def create_db(self):
     auth = self._auth.copy()
     try:
         self.drop_db()
     except Exception:
         pass
     dbname = 'test_%d_%d' % (os.getpid(), int(time.time() * 1000))
     db = MySQLdb.connect(**auth).cursor()
     db.execute("create database " + dbname)
     db.close()
     self._auth['db'] = dbname
     del db
 def setUp(self):
     self._auth = get_database_auth()['MySQLdb']
     self.create_db()
     self.connection = None
     self.connection = MySQLdb.connect(**self._auth)
     cursor = self.connection.cursor()
     cursor.execute("""CREATE TABLE gargleblatz
     (
     a INTEGER
     );""")
     self.connection.commit()
     cursor.close()
Exemple #7
0
 def create_db (self):
     auth = self._auth.copy()
     try:
         self.drop_db()
     except Exception:
         pass
     dbname = 'test_%d_%d' % (os.getpid(), int(time.time() * 1000))
     db = MySQLdb.connect(**auth).cursor()
     db.execute("create database " + dbname)
     db.close()
     self._auth['db'] = dbname
     del db
Exemple #8
0
 def setUp (self):
     self._auth = get_database_auth()['MySQLdb']
     self.create_db()
     self.connection = None
     self.connection = MySQLdb.connect(**self._auth)
     cursor = self.connection.cursor()
     cursor.execute("""CREATE TABLE gargleblatz
     (
     a INTEGER
     );""")
     self.connection.commit()
     cursor.close()
    def set_up_dummy_table(self, connection=None):
        close_connection = False
        if connection is None:
            close_connection = True
            if self.connection is None:
                connection = MySQLdb.connect(**self._auth)
            else:
                connection = self.connection

        cursor = connection.cursor()
        cursor.execute(self.dummy_table_sql)
        connection.commit()
        cursor.close()
        if close_connection:
            connection.close()
Exemple #10
0
    def set_up_dummy_table (self, connection = None):
        close_connection = False
        if connection is None:
            close_connection = True
            if self.connection is None:
                connection = MySQLdb.connect(**self._auth)
            else:
                connection = self.connection

        cursor = connection.cursor()
        cursor.execute(self.dummy_table_sql)
        connection.commit()
        cursor.close()
        if close_connection:
            connection.close()
Exemple #11
0
 def drop_db(self):
     db = MySQLdb.connect(**self._auth).cursor()
     db.execute("drop database " + self._auth['db'])
     db.close()
     del db
Exemple #12
0
 def test_connecting_annoyingly(self):
     self.assert_connection_works(MySQLdb.Connect(**self._auth))
     self.assert_connection_works(MySQLdb.Connection(**self._auth))
     self.assert_connection_works(
         MySQLdb.connections.Connection(**self._auth))
Exemple #13
0
 def drop_db (self):
     db = MySQLdb.connect(**self._auth).cursor()
     db.execute("drop database " + self._auth['db'])
     db.close()
     del db