Ejemplo n.º 1
0
class TestSQLiteCursor(unittest.TestCase):
    def setUp(self):
        self.connection = SQLiteConnection(database=FILENAME).connect

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

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

    def testInitConnectionIsCorrectType(self):
        self.cursor = SQLiteCursor(connection=self.connection)
        self.assertTrue('sqlite3.Connection' in repr(self.cursor.connection))

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


    # row_type from __init__
    def testRowTypeDefault(self):
        self.cursor = SQLiteCursor(connection=self.connection)
        self.assertTrue(self.cursor._getRowType() in ALLOWED_TYPES)

    def testRowTypeInAllowedTypes(self):
        self.cursor = SQLiteCursor(connection=self.connection,
                                    row_type=types.DictionaryType)
        self.assertTrue(self.cursor._getRowType() in ALLOWED_TYPES)

    def testRowTypeNotInAllowedTypes(self):
        self.cursor = SQLiteCursor(connection=self.connection,
                                    row_type=types.ListType)
        self.assertTrue(self.cursor._getRowType() not in ALLOWED_TYPES)


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

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

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


    def tearDown(self):
        self.connection = None
        del self.connection
Ejemplo n.º 2
0
 def testExecuteConnectionNotSet(self):
     self.cursor = SQLiteCursor()
     with self.assertRaises(ValueError):
         self.cursor.execute("SELECT * FROM test")
Ejemplo n.º 3
0
 def testRowTypeNotInAllowedTypes(self):
     self.cursor = SQLiteCursor(connection=self.connection,
                                 row_type=types.ListType)
     self.assertTrue(self.cursor._getRowType() not in ALLOWED_TYPES)
Ejemplo n.º 4
0
 def testRowTypeInAllowedTypes(self):
     self.cursor = SQLiteCursor(connection=self.connection,
                                 row_type=types.DictionaryType)
     self.assertTrue(self.cursor._getRowType() in ALLOWED_TYPES)
Ejemplo n.º 5
0
 def testRowTypeDefault(self):
     self.cursor = SQLiteCursor(connection=self.connection)
     self.assertTrue(self.cursor._getRowType() in ALLOWED_TYPES)
Ejemplo n.º 6
0
 def testInitConnectionIsIncorrectType(self):
     self.cursor = SQLiteCursor(connection=self.connection)
     self.assertTrue('foo' not in repr(self.cursor.connection))
Ejemplo n.º 7
0
 def testInitConnectionIsCorrectType(self):
     self.cursor = SQLiteCursor(connection=self.connection)
     self.assertTrue('sqlite3.Connection' in repr(self.cursor.connection))
Ejemplo n.º 8
0
 def testInitConnectionIsNotNone(self):
     self.cursor = SQLiteCursor(connection=self.connection)
     self.assertTrue(self.cursor.connection is not None)
Ejemplo n.º 9
0
 def testInitConnectionIsNone(self):
     self.cursor = SQLiteCursor(connection=None)
     self.assertEqual(self.cursor.connection, None)
Ejemplo n.º 10
0
 def testConnectName(self):
     self.cursor = SQLiteCursor(connection=self.connection)
     results = self.cursor.execute("SELECT * FROM test WHERE name=?",
                                 ('Glenn',))
     self.assertEqual(results[0][1], 'Glenn')