Merge "Revert "Don't update tags every time""

This commit is contained in:
Jenkins 2016-08-20 19:16:37 +00:00 committed by Gerrit Code Review
commit d4196325eb
2 changed files with 6 additions and 34 deletions

View File

@ -381,20 +381,6 @@ data_fixtures = {
'',
)
},
'/v2/images/a2b83adc-888e-11e3-8872-78acc0b951d9': {
'GET': (
{},
{
'id': 'a2b83adc-888e-11e3-8872-78acc0b951d9',
'name': 'image-1',
'tags': ['tag1', 'tag2'],
},
),
'PATCH': (
{},
'',
)
},
'/v2/images?limit=%d&os_distro=NixOS' % images.DEFAULT_PAGE_SIZE: {
'GET': (
{},
@ -996,23 +982,6 @@ class TestController(testtools.TestCase):
# will not actually change - yet in real life it will...
self.assertEqual('image-3', image.name)
def test_update_add_prop_with_tags(self):
image_id = 'a2b83adc-888e-11e3-8872-78acc0b951d9'
params = {'finn': 'human'}
image = self.controller.update(image_id, **params)
expect_hdrs = {
'Content-Type': 'application/openstack-images-v2.1-json-patch',
}
expect_body = [[('op', 'add'), ('path', '/finn'), ('value', 'human')]]
expect = [
('GET', '/v2/images/%s' % image_id, {}, None),
('PATCH', '/v2/images/%s' % image_id, expect_hdrs, expect_body),
('GET', '/v2/images/%s' % image_id, {}, None),
]
self.assertEqual(expect, self.api.calls)
self.assertEqual(image_id, image.id)
self.assertEqual('image-1', image.name)
def test_update_bad_additionalProperty_type(self):
image_id = 'e7e59ff6-fa2e-4075-87d3-1a1398a07dc3'
params = {'name': 'pong', 'bad_prop': False}

View File

@ -31,12 +31,12 @@ class SchemaBasedModel(warlock.Model):
"""
def _make_custom_patch(self, new, original):
if 'tags' in new and 'tags' not in original:
if not self.get('tags'):
tags_patch = []
else:
tags_patch = [{"path": "/tags",
"value": self.get('tags'),
"op": "replace"}]
else:
tags_patch = []
patch_string = jsonpatch.make_patch(original, new).to_string()
patch = json.loads(patch_string)
@ -55,6 +55,9 @@ class SchemaBasedModel(warlock.Model):
if (name not in original and name in new and
prop.get('is_base', True)):
original[name] = None
original['tags'] = None
new['tags'] = None
return self._make_custom_patch(new, original)