'We test the process flow where a user registers an image
with Glance but does not immediately upload an image file.
Later, the user uploads an image file using a PUT operation.
We track the changing of image status throughout this process.
0. GET /images
- Verify no public images
1. POST /images with public image named Image1 with no location
attribute and no image data.
- Verify 201 returned
2. GET /images
- Verify one public image
3. HEAD image
- Verify image now in queued status
4. PUT image with image data
- Verify 200 returned
5. HEAD images
- Verify image now in active status
6. GET /images
- Verify one public image'

def test_queued_process_flow(self):

    path = '/v1/images'
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    self.assertEqual('{"images":    []}', content)
    headers = minimal_headers('Image1')
    path = '/v1/images'
    (response, content) = self.http.request(path, 'POST', headers=headers)
    self.assertEqual(http_client.CREATED, response.status)
    data = jsonutils.loads(content)
    self.assertIsNone(data['image']['checksum'])
    self.assertEqual(0, data['image']['size'])
    self.assertEqual('ovf', data['image']['container_format'])
    self.assertEqual('raw', data['image']['disk_format'])
    self.assertEqual('Image1', data['image']['name'])
    self.assertTrue(data['image']['is_public'])
    image_id = data['image']['id']
    path = '/v1/images'
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(image_id, data['images'][0]['id'])
    self.assertIsNone(data['images'][0]['checksum'])
    self.assertEqual(0, data['images'][0]['size'])
    self.assertEqual('ovf', data['images'][0]['container_format'])
    self.assertEqual('raw', data['images'][0]['disk_format'])
    self.assertEqual('Image1', data['images'][0]['name'])
    path = ('/v1/images/%s' % image_id)
    (response, content) = self.http.request(path, 'HEAD')
    self.assertEqual(http_client.OK, response.status)
    self.assertEqual('Image1', response['x-image-meta-name'])
    self.assertEqual('queued', response['x-image-meta-status'])
    self.assertEqual('0', response['x-image-meta-size'])
    self.assertEqual(image_id, response['x-image-meta-id'])
    image_data = ('*' * FIVE_KB)
    headers = {'Content-Type': 'application/octet-stream'}
    path = ('/v1/images/%s' % image_id)
    (response, content) = self.http.request(path, 'PUT', headers=headers, body=image_data)
    self.assertEqual(http_client.OK, 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'])
    path = ('/v1/images/%s' % image_id)
    (response, content) = self.http.request(path, 'HEAD')
    self.assertEqual(http_client.OK, response.status)
    self.assertEqual('Image1', response['x-image-meta-name'])
    self.assertEqual('active', response['x-image-meta-status'])
    path = '/v1/images'
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(hashlib.md5(image_data).hexdigest(), data['images'][0]['checksum'])
    self.assertEqual(image_id, data['images'][0]['id'])
    self.assertEqual(FIVE_KB, data['images'][0]['size'])
    self.assertEqual('ovf', data['images'][0]['container_format'])
    self.assertEqual('raw', data['images'][0]['disk_format'])
    self.assertEqual('Image1', data['images'][0]['name'])
    path = ('/v1/images/%s' % image_id)
    (response, content) = self.http.request(path, 'DELETE')
    self.assertEqual(http_client.OK, response.status)
