def destroy_system_tables(db):
    from dsaw.db import systemTables
    system_tables = systemTables()
    for table in system_tables.itertables():
        db.dropTable(table)
        continue
    return
Esempio n. 2
0
    def test2(self):
        'dsaw.db.Psycopg2: normal table'
        db = self.dbManager()

        # init system tables
        db.createSystemTables()

        from dsaw.db.WithID import WithID
        class Table1(WithID):
            name = 'table1'
            import dsaw.db
            greeting = dsaw.db.varchar(name='greeting', length=100)
            
        db.createTable(Table1)

        # insert record
        row = Table1()
        row.greeting = 'hello'
        row.id = 'first'
        db.insertRow(row)

        # fetch it
        rows = db.fetchall(Table1, where="id='%s'" % row.id)
        self.assertEqual(len(rows), 1)
        row1 = rows[0]
        self.assertEqual(row1.greeting, row.greeting)
        
        db.dropTable(Table1)

        # remove system tables
        db.destroySystemTables()
        return
    def test3b(self):
        'dsaw.db.Psycopg2: table with reference. catch dangling reference'

        db = self.dbManager()

        # declare tables
        from dsaw.db.WithID import WithID

        class User(WithID):
            name = 'users'
            import dsaw.db
            username = dsaw.db.varchar(name='username', length=100)

        class Greeting(WithID):
            name = 'greetings'
            import dsaw.db
            greeting = dsaw.db.varchar(name='greeting', length=100)
            who = dsaw.db.reference(name='who', table=User)

        tables = [User, Greeting]

        # init system tables
        db.createSystemTables()

        #
        for table in tables:
            db.createTable(table)

        # create a user
        user = User()
        user.id = user.username = '******'
        db.insertRow(user)

        # create a greeting
        greeting = Greeting()
        greeting.who = user
        greeting.greeting = 'hello'
        greeting.id = 'greeting1'
        db.insertRow(greeting)

        # delete user would leave a dangling reference
        self.assertRaises(db.RecordStillReferred, db.deleteRecord, user)

        #
        tables.reverse()
        for table in tables:
            db.dropTable(table)

        #
        db.destroySystemTables()
        return
Esempio n. 4
0
    def test3(self):
        'dsaw.db.Psycopg2: table with reference'
        db = self.dbManager()

        from dsaw.db.WithID import WithID
        class User(WithID):
            name = 'users'
            import dsaw.db
            username = dsaw.db.varchar(name='username', length=100)

        class Greeting(WithID):
            name = 'greetings'
            import dsaw.db
            greeting = dsaw.db.varchar(name='greeting', length=100)
            who = dsaw.db.reference(name='who', table=User)
            
        tables = [User, Greeting]

        # init system tables
        db.createSystemTables()

        #
        for table in tables: db.createTable(table)

        # create a user
        user = User()
        user.username = '******'
        user.id = 'bob1'
        db.insertRow(user)
        
        # create a greeting
        greeting = Greeting()
        greeting.who = user
        greeting.greeting = 'hello'
        greeting.id = 'greeting1'
        db.insertRow(greeting)

        #
        tables.reverse()
        for table in tables: db.dropTable(table)

        #
        db.destroySystemTables()
        return
    def test3a(self):
        'dsaw.db.Psycopg2: table with reference. catch non-existing reference'

        db = self.dbManager()

        # declare tables
        from dsaw.db.WithID import WithID

        class User(WithID):
            name = 'users'
            import dsaw.db
            username = dsaw.db.varchar(name='username', length=100)

        class Greeting(WithID):
            name = 'greetings'
            import dsaw.db
            greeting = dsaw.db.varchar(name='greeting', length=100)
            who = dsaw.db.reference(name='who', table=User)

        tables = [User, Greeting]

        # init system tables
        db.createSystemTables()

        #
        for table in tables:
            db.createTable(table)

        # create a greeting
        greeting = Greeting()
        greeting.id = 'greeting1'
        greeting.who = 'a'
        greeting.greeting = 'hello'
        self.assertRaises(db.IntegrityError, db.insertRow, greeting)

        #
        tables.reverse()
        for table in tables:
            db.dropTable(table)

        #
        db.destroySystemTables()
        return