Merge "Allow to remove non-compound properties"
This commit is contained in:
		| @@ -178,6 +178,35 @@ class TestController(testtools.TestCase): | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         expect_body = [{'path': '/name', |         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'}] |                         'op': 'remove'}] | ||||||
|  |  | ||||||
|         expect = [('PATCH', '/artifacts/sample_artifact/%s' % art_id, |         expect = [('PATCH', '/artifacts/sample_artifact/%s' % art_id, | ||||||
|   | |||||||
| @@ -77,8 +77,16 @@ class Controller(object): | |||||||
|         if remove_props: |         if remove_props: | ||||||
|             for prop_name in remove_props: |             for prop_name in remove_props: | ||||||
|                 if prop_name not in kwargs: |                 if prop_name not in kwargs: | ||||||
|                     changes.append({'op': 'remove', |                     if '/' in prop_name: | ||||||
|                                     'path': '/%s' % 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: |         for prop_name in kwargs: | ||||||
|             changes.append({'op': 'add', 'path': '/%s' % prop_name, |             changes.append({'op': 'add', 'path': '/%s' % prop_name, | ||||||
|                             'value': kwargs[prop_name]}) |                             'value': kwargs[prop_name]}) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jenkins
					Jenkins