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
Example #2
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