'Test accessible query with policy 3'

def testPolicy3(self):

    auth = current.auth
    current.deployment_settings.security.policy = 3
    auth.permission = S3Permission(auth)
    accessible_query = auth.s3_accessible_query
    c = 'org'
    f = 'permission_test'
    table = current.s3db.org_permission_test
    assertEqual = self.assertEqual
    ALL = (table.id > 0)
    NONE = (table.id == 0)
    auth.s3_impersonate(None)
    query = accessible_query('read', table, c=c, f=f)
    assertEqual(query, NONE)
    auth.s3_impersonate('normaluser@example.com')
    query = accessible_query('read', table, c=c, f=f)
    assertEqual(query, NONE)
    auth.s3_assign_role(auth.user.id, self.reader)
    query = accessible_query('read', 'org_permission_test', c=c, f=f)
    assertEqual(query, ALL)
    query = accessible_query('update', table, c=c, f=f)
    assertEqual(query, NONE)
    query = accessible_query('delete', table, c=c, f=f)
    assertEqual(query, NONE)
    auth.s3_withdraw_role(auth.user.id, self.reader)
    auth.s3_assign_role(auth.user.id, self.editor)
    query = accessible_query('read', table, c=c, f=f)
    assertEqual(query, ALL)
    query = accessible_query('update', table, c=c, f=f)
    assertEqual(query, ALL)
    query = accessible_query('delete', table, c=c, f=f)
    assertEqual(query, NONE)
    auth.s3_withdraw_role(auth.user.id, self.editor)
