コード例 #1
0
ファイル: test_patcher_mysqldb.py プロジェクト: inercia/evy
 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()
コード例 #2
0
ファイル: test_patcher_mysqldb.py プロジェクト: PlumpMath/evy
 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()
コード例 #3
0
ファイル: test_patcher_mysqldb.py プロジェクト: PlumpMath/evy
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
コード例 #4
0
ファイル: test_patcher_mysqldb.py プロジェクト: inercia/evy
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
コード例 #5
0
ファイル: test_patcher_mysqldb.py プロジェクト: PlumpMath/evy
 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
コード例 #6
0
ファイル: test_patcher_mysqldb.py プロジェクト: PlumpMath/evy
 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()
コード例 #7
0
ファイル: test_patcher_mysqldb.py プロジェクト: inercia/evy
 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
コード例 #8
0
ファイル: test_patcher_mysqldb.py プロジェクト: inercia/evy
 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()
コード例 #9
0
ファイル: test_patcher_mysqldb.py プロジェクト: PlumpMath/evy
    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()
コード例 #10
0
ファイル: test_patcher_mysqldb.py プロジェクト: inercia/evy
    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()
コード例 #11
0
ファイル: test_patcher_mysqldb.py プロジェクト: PlumpMath/evy
 def drop_db(self):
     db = MySQLdb.connect(**self._auth).cursor()
     db.execute("drop database " + self._auth['db'])
     db.close()
     del db
コード例 #12
0
ファイル: test_patcher_mysqldb.py プロジェクト: PlumpMath/evy
 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))
コード例 #13
0
ファイル: test_patcher_mysqldb.py プロジェクト: inercia/evy
 def drop_db (self):
     db = MySQLdb.connect(**self._auth).cursor()
     db.execute("drop database " + self._auth['db'])
     db.close()
     del db