diff options
author | Riccardo Pittau <elfosardo@gmail.com> | 2020-02-03 10:19:19 +0100 |
---|---|---|
committer | Riccardo Pittau <elfosardo@gmail.com> | 2020-02-03 15:36:37 +0100 |
commit | 1e7447a1764a1ca0de2005097570a8dc6d1125e3 (patch) | |
tree | 10511dba2acd956d684c91c27b7b3ab951c226e0 | |
parent | 90b747ac669ee8985335930945ee6fe20d8157fa (diff) | |
download | ironic-1e7447a1764a1ca0de2005097570a8dc6d1125e3.tar.gz |
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
-rw-r--r-- | ironic/api/controllers/v1/utils.py | 3 | ||||
-rw-r--r-- | ironic/tests/unit/api/controllers/v1/test_deploy_template.py | 7 | ||||
-rw-r--r-- | ironic/tests/unit/api/controllers/v1/test_utils.py | 1 |
3 files changed, 7 insertions, 4 deletions
diff --git a/ironic/api/controllers/v1/utils.py b/ironic/api/controllers/v1/utils.py index 7712fc30f..b14109087 100644 --- a/ironic/api/controllers/v1/utils.py +++ b/ironic/api/controllers/v1/utils.py @@ -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) diff --git a/ironic/tests/unit/api/controllers/v1/test_deploy_template.py b/ironic/tests/unit/api/controllers/v1/test_deploy_template.py index 96fd16ced..f45ec138d 100644 --- a/ironic/tests/unit/api/controllers/v1/test_deploy_template.py +++ b/ironic/tests/unit/api/controllers/v1/test_deploy_template.py @@ -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 = { diff --git a/ironic/tests/unit/api/controllers/v1/test_utils.py b/ironic/tests/unit/api/controllers/v1/test_utils.py index 80f74936d..c43bfacfb 100644 --- a/ironic/tests/unit/api/controllers/v1/test_utils.py +++ b/ironic/tests/unit/api/controllers/v1/test_utils.py @@ -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) |