Пример #1
0
class TestMySQLDictionaryCursor(unittest.TestCase):
    def setUp(self):
        self.connection = MySQLConnection(host='localhost', user='******', 
                                passwd='y47test', database='y47test').connect

    # connection from __init__
    def testInitConnectionIsNone(self):
        self.cursor = MySQLDictionaryCursor(connection=None)
        self.assertEqual(self.cursor.connection, None)

    def testInitConnectionIsNotNone(self):
        self.cursor = MySQLDictionaryCursor(connection=self.connection)
        self.assertTrue(self.cursor.connection is not None)

    def testInitConnectionIsCorrectType(self):
        self.cursor = MySQLDictionaryCursor(connection=self.connection)
        self.assertTrue('_mysql.connection' in repr(self.cursor.connection))

    def testInitConnectionIsIncorrectType(self):
        self.cursor = MySQLDictionaryCursor(connection=self.connection)
        self.assertTrue('foo' not in repr(self.cursor.connection))


    # execute
    def testExecuteConnectionNotSet(self):
        self.cursor = MySQLDictionaryCursor()
        with self.assertRaises(ValueError):
            self.cursor.execute("SELECT * FROM test")

    def testConnectId(self):
        self.cursor = MySQLDictionaryCursor(connection=self.connection)
        results = self.cursor.execute("SELECT * FROM test WHERE name=%s",
                                    ('Glenn',))
        self.assertEqual(results[0]['id'], 1)

    def testConnectName(self):
        self.cursor = MySQLDictionaryCursor(connection=self.connection)
        results = self.cursor.execute("SELECT * FROM test WHERE name=%s",
                                    ('Glenn',))
        self.assertEqual(results[0]['name'], 'Glenn')


    def tearDown(self):
        self.connection = None
        del self.connection
Пример #2
0
 def testConnectName(self):
     self.cursor = MySQLDictionaryCursor(connection=self.connection)
     results = self.cursor.execute("SELECT * FROM test WHERE name=%s",
                                 ('Glenn',))
     self.assertEqual(results[0]['name'], 'Glenn')
Пример #3
0
 def testExecuteConnectionNotSet(self):
     self.cursor = MySQLDictionaryCursor()
     with self.assertRaises(ValueError):
         self.cursor.execute("SELECT * FROM test")
Пример #4
0
 def testInitConnectionIsIncorrectType(self):
     self.cursor = MySQLDictionaryCursor(connection=self.connection)
     self.assertTrue('foo' not in repr(self.cursor.connection))
Пример #5
0
 def testInitConnectionIsCorrectType(self):
     self.cursor = MySQLDictionaryCursor(connection=self.connection)
     self.assertTrue('_mysql.connection' in repr(self.cursor.connection))
Пример #6
0
 def testInitConnectionIsNotNone(self):
     self.cursor = MySQLDictionaryCursor(connection=self.connection)
     self.assertTrue(self.cursor.connection is not None)
Пример #7
0
 def testInitConnectionIsNone(self):
     self.cursor = MySQLDictionaryCursor(connection=None)
     self.assertEqual(self.cursor.connection, None)