Merge "Allow to remove non-compound properties"
This commit is contained in:
commit
6160ea318c
@ -178,6 +178,35 @@ class TestController(testtools.TestCase):
|
||||
}
|
||||
|
||||
expect_body = [{'path': '/name',
|
||||
'op': 'replace',
|
||||
'value': None}]
|
||||
|
||||
expect = [('PATCH', '/artifacts/sample_artifact/%s' % art_id,
|
||||
exp_headers,
|
||||
expect_body)]
|
||||
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.api.calls = []
|
||||
|
||||
self.controller.update(artifact_id=art_id,
|
||||
remove_props=['metadata/key1'],
|
||||
type_name='sample_artifact')
|
||||
|
||||
expect_body = [{'path': '/metadata/key1',
|
||||
'op': 'remove'}]
|
||||
|
||||
expect = [('PATCH', '/artifacts/sample_artifact/%s' % art_id,
|
||||
exp_headers,
|
||||
expect_body)]
|
||||
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.api.calls = []
|
||||
|
||||
self.controller.update(artifact_id=art_id,
|
||||
remove_props=['releases/1'],
|
||||
type_name='sample_artifact')
|
||||
|
||||
expect_body = [{'path': '/releases/1',
|
||||
'op': 'remove'}]
|
||||
|
||||
expect = [('PATCH', '/artifacts/sample_artifact/%s' % art_id,
|
||||
|
@ -77,8 +77,16 @@ class Controller(object):
|
||||
if remove_props:
|
||||
for prop_name in remove_props:
|
||||
if prop_name not in kwargs:
|
||||
changes.append({'op': 'remove',
|
||||
'path': '/%s' % prop_name})
|
||||
if '/' in prop_name:
|
||||
# we remove all values in dicts and lists explicitly,
|
||||
# i.e. matadata/key or releases/1
|
||||
changes.append({'op': 'remove',
|
||||
'path': '/%s' % prop_name})
|
||||
else:
|
||||
# in other cases we just replace the value with None
|
||||
changes.append({'op': 'replace',
|
||||
'path': '/%s' % prop_name,
|
||||
'value': None})
|
||||
for prop_name in kwargs:
|
||||
changes.append({'op': 'add', 'path': '/%s' % prop_name,
|
||||
'value': kwargs[prop_name]})
|
||||
|
Loading…
x
Reference in New Issue
Block a user