'Test set_roles with policy 7'

def testSetRolesPolicy7(self):

    s3db = current.s3db
    auth = current.auth
    settings = current.deployment_settings
    settings.security.policy = 7
    auth.permission = S3Permission(auth)
    assertEqual = self.assertEqual
    assertTrue = self.assertTrue
    try:
        role = auth.s3_create_role('Example    Role', uid='TESTROLE')
        org1 = self.org1
        org2 = self.org2
        s3db.pr_add_affiliation(org1, org2, role='TestRole')
        user_id = auth.s3_get_user_id('normaluser@example.com')
        auth.s3_assign_role(user_id, role, for_pe=org1)
        auth.s3_impersonate('normaluser@example.com')
        realms = auth.user.realms.keys()
        assertTrue((2 in realms))
        assertTrue((3 in realms))
        assertTrue((role in realms))
        assertEqual(len(realms), 3)
        for r in auth.user.realms:
            if (r == role):
                assertTrue((org1 in auth.user.realms[r]))
                assertTrue((org2 in auth.user.realms[r]))
            else:
                assertEqual(auth.user.realms[r], None)
    finally:
        auth.s3_impersonate(None)
        auth.s3_delete_role('TESTROLE')
        current.db.rollback()
