Exemplo n.º 1
0
    def test_init(self):
        """MySQLCursor object init"""
        try:
            cur = cursor.MySQLCursor(connection=None)
        except (SyntaxError, TypeError) as err:
            self.fail("Failed initializing MySQLCursor; {}".format(err))

        exp = {
            '_connection': None,
            '_stored_results': [],
            '_nextrow': (None, None),
            '_warnings': None,
            '_warning_count': 0,
            '_executed': None,
            '_executed_list': [],
        }

        for key, value in exp.items():
            self.assertEqual(value,
                             getattr(cur, key),
                             msg="Default for '{}' did not match.".format(key))

        self.assertRaises(errors.InterfaceError,
                          cursor.MySQLCursor,
                          connection='foo')
Exemplo n.º 2
0
 def test_statement(self):
     self.c = cursor.MySQLCursor()
     exp = 'SELECT * FROM ham'
     self.c._executed = exp
     self.assertEqual(exp, self.c.statement)
     self.c._executed = '  ' + exp + '    '
     self.assertEqual(exp, self.c.statement)
Exemplo n.º 3
0
 def test_readonly_properties(self):
     cur = cursor.MySQLCursor()
     for attr in ('description', 'rowcount', 'lastrowid'):
         try:
             setattr(cur, attr, 'spam')
         except AttributeError, err:
             # It's readonly, that's OK
             pass
         else:
             self.fail('Need read-only property: %s' % attr)
Exemplo n.º 4
0
    def test_next(self):
        """MySQLCursor object next()-method"""
        self.check_method(self.cur, 'next')

        self.cnx = connection.MySQLConnection(**tests.get_mysql_config())
        self.cur = cursor.MySQLCursor(self.cnx)
        self.assertRaises(StopIteration, self.cur.__next__)
        self.cur.execute("SELECT BINARY 'ham'")
        exp = (b'ham', )
        self.assertEqual(exp, next(self.cur))
        self.cur.close()
Exemplo n.º 5
0
 def test_next(self):
     """MySQLCursor object next()-method"""
     self.checkMethod(self.c,'next')
     
     self.connection = connection.MySQLConnection(**self.getMySQLConfig())
     self.c = cursor.MySQLCursor(self.connection)
     self.assertRaises(StopIteration,self.c.next)
     self.c.execute("SELECT SHA1('myconnpy')")
     exp = (u'c5e24647dbb63447682164d81b34fe493a83610b',)
     self.assertEqual(exp,self.c.next())
     self.c.close()
Exemplo n.º 6
0
 def test_next(self):
     """MySQLCursor object next()-method"""
     self.checkMethod(self.c,'next')
     
     self.db = connection.MySQLConnection(**self.getMySQLConfig())
     self.c = cursor.MySQLCursor(self.db)
     self.assertRaises(StopIteration,self.c.__next__)
     self.c.execute("SELECT BINARY 'ham'")
     exp = (b'ham',)
     self.assertEqual(exp,next(self.c))
     self.c.close()
Exemplo n.º 7
0
    def test_close(self):
        """MySQLCursor object close()-method"""
        self.checkMethod(self.c, 'close')

        self.assertEqual(False, self.c.close(),
                         "close() should return False with no connection")

        db1 = connection.MySQLConnection(**self.getMySQLConfig())
        self.assertEqual([], db1.cursors,
                         "New MySQL-object should have no cursors.")
        c1 = cursor.MySQLCursor(db1)
        self.assertEqual([c1], db1.cursors)
        self.assertEqual(True, c1.close(),
                         "close() should return True when succesful")
        self.assertEqual(
            [], db1.cursors,
            "Closing last cursor MySQL-object should leave list empty.")

        c1 = cursor.MySQLCursor(db1)
        db1.remove_cursor(c1)
        self.assertEqual(False, c1.close())
Exemplo n.º 8
0
    def test__have_unread_result(self):
        """MySQLCursor object _have_unread_result()-method"""
        self.checkMethod(self.c, '_have_unread_result')
        class FakeConnection(object):
            def __init__(self):
                self.unread_result = False

        self.c = cursor.MySQLCursor()
        self.c._connection = FakeConnection()
        
        self.c._connection.unread_result = True
        self.assertTrue(self.c._have_unread_result())
        self.c._connection.unread_result = False
        self.assertFalse(self.c._have_unread_result())
Exemplo n.º 9
0
 def test_with_rows(self):
     self.cur = cursor.MySQLCursor()
     self.assertFalse(self.cur.with_rows)
     self.cur._description = ('ham', 'spam')
     self.assertTrue(self.cur.with_rows)
Exemplo n.º 10
0
 def setUp(self):
     self.cur = cursor.MySQLCursor(connection=None)
     self.cnx = None
Exemplo n.º 11
0
 def test_init(self):
     """MySQLCursor object init"""
     try:
         c = cursor.MySQLCursor(connection=None)
     except (SyntaxError, TypeError), e:
         self.fail("Failed initializing MySQLCursor; %s" % e)
Exemplo n.º 12
0
 def setUp(self):
     self.c = cursor.MySQLCursor(connection=None)
     self.db = None
Exemplo n.º 13
0
 def setUp(self):
     self.c = cursor.MySQLCursor(db=None)
     self.db = None