'Test the special x-glance-registry-purge-props header controls
the purge property behaviour of the registry.
:see LP Bug#901534'

def test_disable_purge_props(self):

    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-property-key1': 'value1'}
    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 = 'chunk00000remainder'
    res = req.get_response(self.api)
    self.assertEqual(http_client.CREATED, res.status_int)
    res_body = jsonutils.loads(res.body)['image']
    self.assertIn('id', res_body)
    image_id = res_body['id']
    self.assertIn(('/images/%s' % image_id), res.headers['location'])
    self.assertIn('status', res_body)
    self.assertEqual('active', res_body['status'])
    self.assertIn('properties', res_body)
    self.assertIn('key1', res_body['properties'])
    self.assertEqual('value1', res_body['properties']['key1'])
    req = webob.Request.blank(('/images/%s' % image_id))
    req.method = 'PUT'
    req.headers['x-image-meta-property-key2'] = 'value2'
    res = req.get_response(self.api)
    self.assertEqual(http_client.OK, res.status_int)
    req = webob.Request.blank(('/images/%s' % image_id))
    req.method = 'HEAD'
    res = req.get_response(self.api)
    self.assertEqual(http_client.OK, res.status_int)
    self.assertIn('x-image-meta-property-key2', res.headers, ('Did    not    find    required    property    in    headers.    Got    headers:    %r' % res.headers))
    self.assertNotIn('x-image-meta-property-key1', res.headers, ('Found    property    in    headers    that    was    not    expected.    Got    headers:    %r' % res.headers))
    req = webob.Request.blank(('/images/%s' % image_id))
    req.method = 'PUT'
    req.headers['x-image-meta-property-key3'] = 'value3'
    req.headers['x-glance-registry-purge-props'] = 'false'
    res = req.get_response(self.api)
    self.assertEqual(http_client.OK, res.status_int)
    req = webob.Request.blank(('/images/%s' % image_id))
    req.method = 'HEAD'
    res = req.get_response(self.api)
    self.assertEqual(http_client.OK, res.status_int)
    self.assertIn('x-image-meta-property-key2', res.headers, ('Did    not    find    required    property    in    headers.    Got    headers:    %r' % res.headers))
    self.assertIn('x-image-meta-property-key3', res.headers, ('Did    not    find    required    property    in    headers.    Got    headers:    %r' % res.headers))
