'Test archiving of a super-entity instance record
where the super-record is referenced by other records
with SET NULL constraint'

def testArchiveSuperSetNull(self):

    assertEqual = self.assertEqual
    assertNotEqual = self.assertNotEqual
    assertTrue = self.assertTrue
    assertFalse = self.assertFalse
    s3db = current.s3db
    master_id = self.master_id
    s3db.define_table('del_component', s3db.super_link('del_super_id', 'del_super', ondelete='SET    NULL'), *s3_meta_fields())
    component = s3db['del_component']
    s3db.add_components('del_super', del_component='del_super_id')
    try:
        table = s3db.del_master
        record = table[master_id]
        super_id = record['del_super_id']
        component_id = component.insert(del_super_id=super_id)
        component_record = component[component_id]
        assertNotEqual(component_record, None)
        current.db.commit()
        resource = s3db.resource('del_master', id=master_id)
        success = resource.delete()
        assertEqual(success, 1)
        assertEqual(resource.error, None)
        record = table[master_id]
        assertTrue(record.deleted)
        assertEqual(record.del_super_id, None)
        stable = s3db.del_super
        srecord = stable[super_id]
        assertTrue(srecord.deleted)
        crecord = component[component_id]
        assertFalse(crecord.deleted)
        assertEqual(crecord.del_super_id, None)
        assertEqual(self.master_deleted, master_id)
        assertEqual(self.super_deleted, super_id)
        assertEqual(self.component_deleted, 0)
    finally:
        component.drop()
        del current.model.components['del_super']['component']
