From 9fa4bc2ea8cb0755d071e74431e6d2167d4fe70b Mon Sep 17 00:00:00 2001 From: Darja Shakhray Date: Mon, 24 Aug 2015 14:43:17 +0300 Subject: [PATCH] Fix return 200 status code when we operate with nonexistent property Glance returned 200 status code when we add/remove/replace element to nonexistent "artifacts" property. Now glance return 400 status code with description error. Change-Id: Ifa9f92de0999052c4db4bcd44fba894f503c7378 Depends-On: I49a385f124236b22360ee07f5adcba27b3c92603 Closes-bug: #1485478 --- glance/artifacts/updater.py | 1 + .../functional/artifacts/test_artifacts.py | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/glance/artifacts/updater.py b/glance/artifacts/updater.py index 61a9a9f02e..9e3fccc557 100644 --- a/glance/artifacts/updater.py +++ b/glance/artifacts/updater.py @@ -37,6 +37,7 @@ class ArtifactProxy(proxy.Artifact): path = kwargs.get("path") value = kwargs.get("value") prop_name, delimiter, path_left = path.lstrip('/').partition('/') + super(ArtifactProxy, self).get_type_specific_property(prop_name) if not path_left: return setattr(self, prop_name, value) try: diff --git a/glance/tests/functional/artifacts/test_artifacts.py b/glance/tests/functional/artifacts/test_artifacts.py index 7415224d48..9183c8884d 100644 --- a/glance/tests/functional/artifacts/test_artifacts.py +++ b/glance/tests/functional/artifacts/test_artifacts.py @@ -491,6 +491,81 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory data='ZZZZZ', status=200) self._check_artifact_delete('/withblob/v1/%s' % art['id']) + def test_update_nonexistent_property_by_replace_op(self): + art = self._create_artifact('withprops', data={'name': 'some art', + 'version': '4.2'}) + data = [{'op': 'replace', 'value': 'some value', + 'path': '/nonexistent_property'}] + result = self._check_artifact_patch('/withprops/v1/%s' % + art['id'], + data=data, + status=400) + actual = u'''\ + + + 400 Bad Request + + +

400 Bad Request

+ Artifact has no property nonexistent_property

+ + + + +''' + + self.assertEqual(actual, result) + + def test_update_nonexistent_property_by_remove_op(self): + art = self._create_artifact('withprops', data={'name': 'some art', + 'version': '4.2'}) + data = [{'op': 'replace', 'value': 'some value', + 'path': '/nonexistent_property'}] + result = self._check_artifact_patch('/withprops/v1/%s' % + art['id'], + data=data, + status=400) + actual = u'''\ + + + 400 Bad Request + + +

400 Bad Request

+ Artifact has no property nonexistent_property

+ + + + +''' + + self.assertEqual(actual, result) + + def test_update_nonexistent_property_by_add_op(self): + art = self._create_artifact('withprops', data={'name': 'some art', + 'version': '4.2'}) + data = [{'op': 'replace', 'value': 'some value', + 'path': '/nonexistent_property'}] + result = self._check_artifact_patch('/withprops/v1/%s' % + art['id'], + data=data, + status=400) + actual = u'''\ + + + 400 Bad Request + + +

400 Bad Request

+ Artifact has no property nonexistent_property

+ + + + +''' + + self.assertEqual(actual, result) + def test_update_array_property_by_replace_op(self): art = self._create_artifact('withprops', data={'name': 'some art', 'version': '4.2'})