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
This commit is contained in:
Darja Shakhray 2015-08-24 14:43:17 +03:00 committed by Nikhil Komawar
parent 27ca72587e
commit 9fa4bc2ea8
2 changed files with 76 additions and 0 deletions

View File

@ -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:

View File

@ -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'''\
<html>
<head>
<title>400 Bad Request</title>
</head>
<body>
<h1>400 Bad Request</h1>
Artifact has no property nonexistent_property<br /><br />
</body>
</html>'''
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'''\
<html>
<head>
<title>400 Bad Request</title>
</head>
<body>
<h1>400 Bad Request</h1>
Artifact has no property nonexistent_property<br /><br />
</body>
</html>'''
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'''\
<html>
<head>
<title>400 Bad Request</title>
</head>
<body>
<h1>400 Bad Request</h1>
Artifact has no property nonexistent_property<br /><br />
</body>
</html>'''
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'})