'Test for cache middleware raise webob.exc.HTTPForbidden directly
when request context has not \'download_image\' role.'

def test_process_response_without_download_image_policy(self):

    def fake_fetch_request_info(*args, **kwargs):
        return ('test1', 'GET', 'v1')
    def fake_get_v1_image_metadata(*args, **kwargs):
        return {'properties': {}}
    cache_filter = ProcessRequestTestCacheFilter()
    cache_filter._fetch_request_info = fake_fetch_request_info
    cache_filter._get_v1_image_metadata = fake_get_v1_image_metadata
    rules = {'download_image': '!'}
    self.set_policy_rules(rules)
    cache_filter.policy = glance.api.policy.Enforcer()
    image_id = 'test1'
    request = webob.Request.blank(('/v1/images/%s' % image_id))
    request.context = context.RequestContext()
    resp = webob.Response(request=request)
    self.assertRaises(webob.exc.HTTPForbidden, cache_filter.process_response, resp)
    self.assertEqual([''], resp.app_iter)
