class TestSQLiteDictionaryCursor(unittest.TestCase): def setUp(self): self.connection = SQLiteConnection(database=FILENAME).connect # connection from __init__ def testInitConnectionIsNone(self): self.cursor = SQLiteDictionaryCursor(connection=None) self.assertEqual(self.cursor.connection, None) def testInitConnectionIsNotNone(self): self.cursor = SQLiteDictionaryCursor(connection=self.connection) self.assertTrue(self.cursor.connection is not None) def testInitConnectionIsCorrectType(self): self.cursor = SQLiteDictionaryCursor(connection=self.connection) self.assertTrue('sqlite3.Connection' in repr(self.cursor.connection)) def testInitConnectionIsIncorrectType(self): self.cursor = SQLiteDictionaryCursor(connection=self.connection) self.assertTrue('foo' not in repr(self.cursor.connection)) # execute def testExecuteConnectionNotSet(self): self.cursor = SQLiteDictionaryCursor() with self.assertRaises(ValueError): self.cursor.execute("SELECT * FROM test") def testConnectId(self): self.cursor = SQLiteDictionaryCursor(connection=self.connection) results = self.cursor.execute("SELECT * FROM test WHERE name=?", ('Glenn',)) self.assertEqual(results[0]['id'], 1) def testConnectName(self): self.cursor = SQLiteDictionaryCursor(connection=self.connection) results = self.cursor.execute("SELECT * FROM test WHERE name=?", ('Glenn',)) self.assertEqual(results[0]['name'], 'Glenn') def tearDown(self): self.connection = None del self.connection
def testConnectName(self): self.cursor = SQLiteDictionaryCursor(connection=self.connection) results = self.cursor.execute("SELECT * FROM test WHERE name=?", ('Glenn',)) self.assertEqual(results[0]['name'], 'Glenn')
def testExecuteConnectionNotSet(self): self.cursor = SQLiteDictionaryCursor() with self.assertRaises(ValueError): self.cursor.execute("SELECT * FROM test")
def testInitConnectionIsIncorrectType(self): self.cursor = SQLiteDictionaryCursor(connection=self.connection) self.assertTrue('foo' not in repr(self.cursor.connection))
def testInitConnectionIsCorrectType(self): self.cursor = SQLiteDictionaryCursor(connection=self.connection) self.assertTrue('sqlite3.Connection' in repr(self.cursor.connection))
def testInitConnectionIsNotNone(self): self.cursor = SQLiteDictionaryCursor(connection=self.connection) self.assertTrue(self.cursor.connection is not None)
def testInitConnectionIsNone(self): self.cursor = SQLiteDictionaryCursor(connection=None) self.assertEqual(self.cursor.connection, None)