Apply expected patch format when updating tags in v2.images

Currently, glanceclient.v2.update builds a patch request that does not
match glance API.

This patch overrides the default behaviour to customize the patch
request with the right format for the API.

Co-Authored-By: Steve Lewis <steve.lewis@rackspace.com>
Fixes bug 1306774
Change-Id: If0739ac285da1e741bfa40b6c719331a5ce49319
This commit is contained in:
Steve Lewis
2015-03-10 13:10:37 -07:00
parent 2858645cef
commit f6f573316c
3 changed files with 57 additions and 6 deletions
+19 -2
View File
@@ -58,7 +58,7 @@ data_fixtures = {
},
'color': {'type': 'string', 'is_base': False},
},
'additionalProperties': {'type': 'string'}
'additionalProperties': {'type': 'string'},
},
),
},
@@ -418,8 +418,9 @@ schema_fixtures = {
}
},
'color': {'type': 'string', 'is_base': False},
'tags': {'type': 'array'},
},
'additionalProperties': {'type': 'string'}
'additionalProperties': {'type': 'string'},
}
)
}
@@ -889,6 +890,22 @@ class TestController(testtools.TestCase):
self._empty_get(image_id)
])
def test_update_tags(self):
image_id = 'a2b83adc-888e-11e3-8872-78acc0b951d8'
tag_map = {'tags': ['tag01', 'tag02', 'tag03']}
image = self.controller.update(image_id, **tag_map)
expected_body = [{'path': '/tags', 'op': 'replace',
'value': tag_map['tags']}]
expected = [
self._empty_get(image_id),
self._patch_req(image_id, expected_body),
self._empty_get(image_id)
]
self.assertEqual(expected, self.api.calls)
self.assertEqual(image_id, image.id)
def test_update_missing_location(self):
image_id = 'a2b83adc-888e-11e3-8872-78acc0b951d8'
new_loc = {'url': 'http://spam.com/', 'metadata': {'spam': 'ham'}}
+18 -2
View File
@@ -37,8 +37,11 @@ fixtures = {
{
'name': 'image',
'properties': {
'name': {'type': 'string', 'description': 'Name of image'},
'name': {'type': 'string',
'description': 'Name of image'},
'tags': {'type': 'array'}
},
},
),
},
@@ -51,6 +54,7 @@ _SCHEMA = schemas.Schema({
'name': {'type': 'string'},
'color': {'type': 'string'},
'shape': {'type': 'string', 'is_base': False},
'tags': {'type': 'array'}
},
})
@@ -99,7 +103,8 @@ class TestController(testtools.TestCase):
def test_get_schema(self):
schema = self.controller.get('image')
self.assertEqual('image', schema.name)
self.assertEqual(['name'], [p.name for p in schema.properties])
self.assertEqual(['name', 'tags'],
[p.name for p in schema.properties])
class TestSchemaBasedModel(testtools.TestCase):
@@ -195,3 +200,14 @@ class TestSchemaBasedModel(testtools.TestCase):
patch = original.patch
expected = '[{"path": "/shape", "value": "square", "op": "replace"}]'
self.assertTrue(compare_json_patches(patch, expected))
def test_patch_should_replace_tags(self):
obj = {'name': 'fred', }
original = self.model(obj)
original['tags'] = ['tag1', 'tag2']
patch = original.patch
expected = '[{"path": "/tags", "value": ["tag1", "tag2"], ' \
'"op": "replace"}]'
self.assertTrue(compare_json_patches(patch, expected))