class TestMySQLCursor(unittest.TestCase): def setUp(self): self.connection = MySQLConnection(host='localhost', user='******', passwd='y47test', database='y47test').connect # connection from __init__ def testInitConnectionIsNone(self): self.cursor = MySQLCursor(connection=None) self.assertEqual(self.cursor.connection, None) def testInitConnectionIsNotNone(self): self.cursor = MySQLCursor(connection=self.connection) self.assertTrue(self.cursor.connection is not None) def testInitConnectionIsCorrectType(self): self.cursor = MySQLCursor(connection=self.connection) self.assertTrue('_mysql.connection' in repr(self.cursor.connection)) def testInitConnectionIsIncorrectType(self): self.cursor = MySQLCursor(connection=self.connection) self.assertTrue('foo' not in repr(self.cursor.connection)) # row_type from __init__ def testRowTypeDefault(self): self.cursor = MySQLCursor(connection=self.connection) self.assertTrue(self.cursor._getRowType() in ALLOWED_TYPES) def testRowTypeInAllowedTypes(self): self.cursor = MySQLCursor(connection=self.connection, row_type=types.DictionaryType) self.assertTrue(self.cursor._getRowType() in ALLOWED_TYPES) def testRowTypeNotInAllowedTypes(self): self.cursor = MySQLCursor(connection=self.connection, row_type=types.ListType) self.assertTrue(self.cursor._getRowType() not in ALLOWED_TYPES) # execute def testExecuteConnectionNotSet(self): self.cursor = MySQLCursor() with self.assertRaises(ValueError): self.cursor.execute("SELECT * FROM test") def testConnectId(self): self.cursor = MySQLCursor(connection=self.connection) results = self.cursor.execute("SELECT * FROM test") self.assertEqual(results[0][0], 1) def testConnectName(self): self.cursor = MySQLCursor(connection=self.connection) results = self.cursor.execute("SELECT * FROM test") self.assertEqual(results[0][1], 'Glenn') def tearDown(self): self.connection = None del self.connection
def testConnectName(self): self.cursor = MySQLCursor(connection=self.connection) results = self.cursor.execute("SELECT * FROM test") self.assertEqual(results[0][1], 'Glenn')
def testExecuteConnectionNotSet(self): self.cursor = MySQLCursor() with self.assertRaises(ValueError): self.cursor.execute("SELECT * FROM test")
def testRowTypeNotInAllowedTypes(self): self.cursor = MySQLCursor(connection=self.connection, row_type=types.ListType) self.assertTrue(self.cursor._getRowType() not in ALLOWED_TYPES)
def testRowTypeInAllowedTypes(self): self.cursor = MySQLCursor(connection=self.connection, row_type=types.DictionaryType) self.assertTrue(self.cursor._getRowType() in ALLOWED_TYPES)
def testRowTypeDefault(self): self.cursor = MySQLCursor(connection=self.connection) self.assertTrue(self.cursor._getRowType() in ALLOWED_TYPES)
def testInitConnectionIsIncorrectType(self): self.cursor = MySQLCursor(connection=self.connection) self.assertTrue('foo' not in repr(self.cursor.connection))
def testInitConnectionIsCorrectType(self): self.cursor = MySQLCursor(connection=self.connection) self.assertTrue('_mysql.connection' in repr(self.cursor.connection))
def testInitConnectionIsNotNone(self): self.cursor = MySQLCursor(connection=self.connection) self.assertTrue(self.cursor.connection is not None)
def testInitConnectionIsNone(self): self.cursor = MySQLCursor(connection=None) self.assertEqual(self.cursor.connection, None)