Example #1
0
    def test_dropTable(self):
        #Setup
        from errors import SyntaxError
        import slap
        t = slap.DB()

        #Create a table => True
        self.assertTrue(
            t.createTable(
                'test',
                '(name TEXT, color TEXT, age INTEGER, ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT)'
            ))
        #Drop an existing table => True
        self.assertTrue(t.dropTable('test'))
        #Drop an non-existing table => True
        self.assertTrue(t.dropTable('fooey'))
        #Create a table => True
        self.assertTrue(
            t.createTable(
                'test',
                '(name TEXT, color TEXT, age INTEGER, ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT)'
            ))
        #Drop an existing table with syntax error => SyntaxError
        self.failUnlessRaises(SyntaxError, t.dropTable, 't#st')

        #Clean up
        #Close an open DB => True
        self.assertTrue(t.closeDB())
Example #2
0
    def test_deleteRow(self):
        #Setup
        from errors import ColumnDNE_Error, SyntaxError, TableDNE_Error
        import slap
        t = slap.DB()

        #Create a table => True
        self.assertTrue(
            t.createTable(
                'test',
                '(name TEXT, color TEXT, age INTEGER, ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT)'
            ))
        #Insert full rows in an existing table => True
        self.assertTrue(
            t.insertRow('test', {
                'name': 'Plain',
                'color': 'WH',
                'age': 10
            }))
        self.assertTrue(
            t.insertRow('test', {
                'name': 'Mountain',
                'color': 'RD',
                'age': 10
            }))
        self.assertTrue(
            t.insertRow('test', {
                'name': 'Swamp',
                'color': 'BK',
                'age': 10
            }))
        #Delete a row that exists => True
        self.assertTrue(t.deleteRow('test', {'ID': ('==', 1)}))
        #Delete a row that exists using multiple conditions => True
        self.assertTrue(
            t.deleteRow('test', {
                "ID": ('==', 2),
                'name': ('==', 'Swamp')
            }))
        #Delete a row with a column that does not exist => ColumnDNE_Error
        self.failUnlessRaises(ColumnDNE_Error, t.deleteRow, 'test',
                              {'junk': ('==', 'bar')})
        #Delete a row in a non-existant table => TableDNE_Error
        self.failUnlessRaises(TableDNE_Error, t.deleteRow, 'fooey',
                              {'name': ('==', 'Swamp')})
        #Delete a row with syntax errors => SyntaxError
        self.failUnlessRaises(SyntaxError, t.deleteRow, 'test',
                              {'col(or': ('==', 'RD')})

        #Clean up
        #Close an open DB => True
        self.assertTrue(t.closeDB())