Fix jsonpatch related tests
Latest release of jsonpatch fixed an issue with array boundaries[1] but broke tests since JsonPatchConflict is now correctly raised when a patch tries to replace an item that doesn't exist. This patch fixes the issue with the tests including JsonPatchConflict in the json exceptions intercepted by the method apply_jsonpatch. [1] https://github.com/stefankoegl/python-json-patch/commit/b3726f3a8bdcdf0f0841e078228014de8477b0ec Change-Id: I6edf6eb7ae1e9f3aa7bc3220cd943a4849f4997c
This commit is contained in:
@@ -41,7 +41,8 @@ from ironic import objects
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
_JSONPATCH_EXCEPTIONS = (jsonpatch.JsonPatchException,
|
||||
_JSONPATCH_EXCEPTIONS = (jsonpatch.JsonPatchConflict,
|
||||
jsonpatch.JsonPatchException,
|
||||
jsonpatch.JsonPointerException,
|
||||
KeyError,
|
||||
IndexError)
|
||||
|
||||
@@ -360,7 +360,7 @@ class TestPatch(BaseDeployTemplatesAPITest):
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
|
||||
self.assertTrue(response.json['error_message'])
|
||||
self.assertIn(error_msg, response.json['error_message'])
|
||||
self.assertRegex(response.json['error_message'], error_msg)
|
||||
self.assertFalse(mock_save.called)
|
||||
return response
|
||||
|
||||
@@ -538,7 +538,8 @@ class TestPatch(BaseDeployTemplatesAPITest):
|
||||
}
|
||||
patch = [{'path': '/steps/1', 'op': 'replace', 'value': step}]
|
||||
self._test_update_bad_request(
|
||||
mock_save, patch, "list assignment index out of range")
|
||||
mock_save, patch, "list assignment index out of range|"
|
||||
"can't replace outside of list")
|
||||
|
||||
def test_replace_empty_step_list_fail(self, mock_save):
|
||||
patch = [{'path': '/steps', 'op': 'replace', 'value': []}]
|
||||
@@ -654,7 +655,7 @@ class TestPatch(BaseDeployTemplatesAPITest):
|
||||
def test_add_root_non_existent(self, mock_save):
|
||||
patch = [{'path': '/foo', 'value': 'bar', 'op': 'add'}]
|
||||
self._test_update_bad_request(
|
||||
mock_save, patch, "Adding a new attribute (/foo)")
|
||||
mock_save, patch, "Adding a new attribute \(/foo\)")
|
||||
|
||||
def test_add_too_high_index_step_fail(self, mock_save):
|
||||
step = {
|
||||
|
||||
@@ -114,6 +114,7 @@ class TestApiUtils(base.TestCase):
|
||||
doc = []
|
||||
patch = [{"op": "replace", "path": "/0", "value": 42}]
|
||||
self.assertRaisesRegex(exception.PatchError,
|
||||
"can't replace outside of list|"
|
||||
"list assignment index out of range",
|
||||
utils.apply_jsonpatch, doc, patch)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user