'Test ownership required for controller'

def testOwnershipRequiredController(self):

    auth = current.auth
    permission = auth.permission
    deployment_settings = current.deployment_settings
    policies = {1: False, 2: False, 3: True, 4: True, 5: True, 6: True, 7: True, 8: True, 0: True}
    current_policy = deployment_settings.get_security_policy()
    assertTrue = self.assertTrue
    assertFalse = self.assertFalse
    auth.permission.update_acl(self.role_id, c='pr', f='person', uacl=auth.permission.NONE, oacl=auth.permission.ALL)
    auth.s3_impersonate('normaluser@example.com')
    auth.s3_assign_role(auth.user.id, self.role_id)
    try:
        for policy in policies:
            deployment_settings.security.policy = policy
            permission = S3Permission(auth)
            ownership_required = permission.ownership_required
            o = ownership_required('update', 'ownership_test_table', c='pr', f='person')
            required = policies[policy]
            msg = ('ownership_required    failed    in    policy    %s    (%s    instead    of    %s)' % (policy, (not required), required))
            if policies[policy]:
                assertTrue(o, msg=msg)
            else:
                assertFalse(o, msg=msg)
    finally:
        deployment_settings.security.policy = current_policy
        auth.permission.delete_acl(self.role_id, c='pr', f='person')
