'Test whether default approver is set if current user has
permission to approve records in a table'

def testSetDefaultApprover(self):

    auth = current.auth
    acl = auth.permission
    AUTHENTICATED = auth.get_system_roles().AUTHENTICATED
    otable = current.s3db.org_organisation
    otable.approved_by.default = None
    assertEqual = self.assertEqual
    acl.set_default_approver(otable, force=True)
    assertEqual(otable.approved_by.default, 0)
    auth.s3_impersonate('normaluser@example.com')
    acl.set_default_approver(otable, force=True)
    assertEqual(otable.approved_by.default, auth.user.id)
    current.deployment_settings.auth.record_approval = True
    acl.set_default_approver(otable, force=True)
    assertEqual(otable.approved_by.default, None)
    acl.update_acl(AUTHENTICATED, c='org', uacl=((acl.READ | acl.REVIEW) | acl.APPROVE), oacl=(((acl.READ | acl.UPDATE) | acl.REVIEW) | acl.APPROVE))
    acl.update_acl(AUTHENTICATED, t='org_organisation', uacl=(((acl.READ | acl.CREATE) | acl.REVIEW) | acl.APPROVE), oacl=(((acl.READ | acl.UPDATE) | acl.REVIEW) | acl.APPROVE))
    auth.s3_impersonate('normaluser@example.com')
    acl.set_default_approver(otable, force=True)
    assertEqual(otable.approved_by.default, auth.user.id)
    auth.s3_impersonate('admin@example.com')
    acl.set_default_approver(otable, force=True)
    assertEqual(otable.approved_by.default, auth.user.id)
    auth.s3_impersonate(None)
    acl.set_default_approver(otable, force=True)
    assertEqual(otable.approved_by.default, None)
