'Test that the image contents are checksummed properly'

def test_bad_checksum_prevents_image_creation(self):

    image_contents = 'chunk00000remainder'
    bad_checksum = hashlib.md5('invalid').hexdigest()
    fixture_headers = {'x-image-meta-store': 'file', 'x-image-meta-disk-format': 'vhd', 'x-image-meta-container-format': 'ovf', 'x-image-meta-name': 'fake    image    #3', 'x-image-meta-checksum': bad_checksum, 'x-image-meta-is-public': 'true'}
    req = webob.Request.blank('/images')
    req.method = 'POST'
    for (k, v) in six.iteritems(fixture_headers):
        req.headers[k] = v
    req.headers['Content-Type'] = 'application/octet-stream'
    req.body = image_contents
    res = req.get_response(self.api)
    self.assertEqual(http_client.BAD_REQUEST, res.status_int)
    req = webob.Request.blank('/images')
    req.method = 'GET'
    res = req.get_response(self.api)
    self.assertEqual(http_client.OK, res.status_int)
    images = jsonutils.loads(res.body)['images']
    self.assertEqual(1, len(images))
