'We test that putting the cache middleware into the
application pipeline gives us transparent image caching'

@skip_if_disabled
def test_cache_middleware_transparent_v1(self):

    self.cleanup()
    self.start_servers(**self.__dict__.copy())
    image_data = ('*' * FIVE_KB)
    headers = minimal_headers('Image1')
    path = ('http://%s:%d/v1/images' % ('127.0.0.1', self.api_port))
    http = httplib2.Http()
    (response, content) = http.request(path, 'POST', headers=headers, body=image_data)
    self.assertEqual(http_client.CREATED, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(hashlib.md5(image_data).hexdigest(), data['image']['checksum'])
    self.assertEqual(FIVE_KB, data['image']['size'])
    self.assertEqual('Image1', data['image']['name'])
    self.assertTrue(data['image']['is_public'])
    image_id = data['image']['id']
    image_cached_path = os.path.join(self.api_server.image_cache_dir, image_id)
    self.assertFalse(os.path.exists(image_cached_path))
    path = ('http://%s:%d/v1/images/%s' % ('127.0.0.1', self.api_port, image_id))
    http = httplib2.Http()
    (response, content) = http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    image_cached_path = os.path.join(self.api_server.image_cache_dir, image_id)
    i = 0
    while ((not os.path.exists(image_cached_path)) and (i < 30)):
        time.sleep(0.05)
        i = (i + 1)
    self.assertTrue(os.path.exists(image_cached_path))
    path = ('http://%s:%d/v1/images/%s' % ('127.0.0.1', self.api_port, image_id))
    http = httplib2.Http()
    (response, content) = http.request(path, 'DELETE')
    self.assertEqual(http_client.OK, response.status)
    self.assertFalse(os.path.exists(image_cached_path))
    self.stop_servers()
