Merge "Change status code from 500 to 400 for image update request"
This commit is contained in:
commit
1221691e5a
|
@ -339,6 +339,8 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer):
|
||||||
|
|
||||||
_default_sort_dir = 'desc'
|
_default_sort_dir = 'desc'
|
||||||
|
|
||||||
|
_supported_operations = ('add', 'remove', 'replace')
|
||||||
|
|
||||||
def __init__(self, schema=None):
|
def __init__(self, schema=None):
|
||||||
super(RequestDeserializer, self).__init__()
|
super(RequestDeserializer, self).__init__()
|
||||||
self.schema = schema or get_schema()
|
self.schema = schema or get_schema()
|
||||||
|
@ -382,15 +384,23 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer):
|
||||||
return dict(image=image, extra_properties=properties, tags=tags)
|
return dict(image=image, extra_properties=properties, tags=tags)
|
||||||
|
|
||||||
def _get_change_operation_d10(self, raw_change):
|
def _get_change_operation_d10(self, raw_change):
|
||||||
try:
|
op = raw_change.get('op')
|
||||||
return raw_change['op']
|
if op is None:
|
||||||
except KeyError:
|
msg = _('Unable to find `op` in JSON Schema change. '
|
||||||
msg = _("Unable to find '%s' in JSON Schema change") % 'op'
|
'It must be one of the following: %(available)s.') % \
|
||||||
|
{'available': ', '.join(self._supported_operations)}
|
||||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||||
|
if op not in self._supported_operations:
|
||||||
|
msg = _('Invalid operation: `%(op)s`. '
|
||||||
|
'It must be one of the following: %(available)s.') % \
|
||||||
|
{'op': op,
|
||||||
|
'available': ', '.join(self._supported_operations)}
|
||||||
|
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||||
|
return op
|
||||||
|
|
||||||
def _get_change_operation_d4(self, raw_change):
|
def _get_change_operation_d4(self, raw_change):
|
||||||
op = None
|
op = None
|
||||||
for key in ['replace', 'add', 'remove']:
|
for key in self._supported_operations:
|
||||||
if key in raw_change:
|
if key in raw_change:
|
||||||
if op is not None:
|
if op is not None:
|
||||||
msg = _('Operation objects must contain only one member'
|
msg = _('Operation objects must contain only one member'
|
||||||
|
|
|
@ -2271,6 +2271,7 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
|
||||||
True,
|
True,
|
||||||
False,
|
False,
|
||||||
None,
|
None,
|
||||||
|
{'op': 'invalid', 'path': '/name', 'value': 'fedora'}
|
||||||
]
|
]
|
||||||
for change in changes:
|
for change in changes:
|
||||||
request = self._get_fake_patch_request()
|
request = self._get_fake_patch_request()
|
||||||
|
|
Loading…
Reference in New Issue