diff options
author | Dmitry Tantsur <dtantsur@protonmail.com> | 2020-07-07 17:43:12 +0200 |
---|---|---|
committer | Dmitry Tantsur <dtantsur@protonmail.com> | 2020-07-07 17:43:12 +0200 |
commit | addbdf7c2b325288d9a024e699fd5d626b6885aa (patch) | |
tree | 5325af2f4dde1e54131f2065b443487237b0c09f | |
parent | 3c47122f363756911f066f8cf8ecb0b1cac1335b (diff) | |
download | ironic-addbdf7c2b325288d9a024e699fd5d626b6885aa.tar.gz |
Do not verify error messages from jsonpatch in unit tests
They are not guaranteed to be stable and actually change in the next
version of jsonpatch.
Change-Id: If6fc0b99c4cb8654ba0b50400d51a184518a32cb
-rw-r--r-- | ironic/tests/unit/api/controllers/v1/test_deploy_template.py | 28 | ||||
-rw-r--r-- | ironic/tests/unit/api/controllers/v1/test_utils.py | 11 |
2 files changed, 14 insertions, 25 deletions
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 6f5b6e64c..b194dafdd 100644 --- a/ironic/tests/unit/api/controllers/v1/test_deploy_template.py +++ b/ironic/tests/unit/api/controllers/v1/test_deploy_template.py @@ -353,14 +353,15 @@ class TestPatch(BaseDeployTemplatesAPITest): mock_save.assert_called_once_with(mock.ANY) return response - def _test_update_bad_request(self, mock_save, patch, error_msg): + def _test_update_bad_request(self, mock_save, patch, error_msg=None): response = self.patch_json('/deploy_templates/%s' % self.template.uuid, patch, expect_errors=True, headers=self.headers) self.assertEqual('application/json', response.content_type) self.assertEqual(http_client.BAD_REQUEST, response.status_code) self.assertTrue(response.json['error_message']) - self.assertRegex(response.json['error_message'], error_msg) + if error_msg: + self.assertRegex(response.json['error_message'], error_msg) self.assertFalse(mock_save.called) return response @@ -537,16 +538,14 @@ class TestPatch(BaseDeployTemplatesAPITest): 'priority': 42 } patch = [{'path': '/steps/1', 'op': 'replace', 'value': step}] - self._test_update_bad_request( - mock_save, patch, "list assignment index out of range|" - "can't replace outside of list") + self._test_update_bad_request(mock_save, patch) def test_replace_empty_step_list_fail(self, mock_save): patch = [{'path': '/steps', 'op': 'replace', 'value': []}] self._test_update_bad_request( mock_save, patch, 'No deploy steps specified') - def _test_remove_not_allowed(self, mock_save, field, error_msg): + def _test_remove_not_allowed(self, mock_save, field, error_msg=None): patch = [{'path': '/%s' % field, 'op': 'remove'}] self._test_update_bad_request(mock_save, patch, error_msg) @@ -566,8 +565,7 @@ class TestPatch(BaseDeployTemplatesAPITest): "'/steps' is a mandatory attribute and can not be removed") def test_remove_foo(self, mock_save): - self._test_remove_not_allowed( - mock_save, 'foo', "can't remove non-existent object 'foo'") + self._test_remove_not_allowed(mock_save, 'foo') def test_replace_step_invalid_interface(self, mock_save): patch = [{'path': '/steps/0/interface', 'op': 'replace', @@ -632,14 +630,11 @@ class TestPatch(BaseDeployTemplatesAPITest): def test_remove_non_existent_property_fail(self, mock_save): patch = [{'path': '/non-existent', 'op': 'remove'}] - self._test_update_bad_request( - mock_save, patch, - "can't remove non-existent object 'non-existent'") + self._test_update_bad_request(mock_save, patch) def test_remove_non_existent_step_fail(self, mock_save): patch = [{'path': '/steps/1', 'op': 'remove'}] - self._test_update_bad_request( - mock_save, patch, "can't remove non-existent object '1'") + self._test_update_bad_request(mock_save, patch) def test_remove_only_step_fail(self, mock_save): patch = [{'path': '/steps/0', 'op': 'remove'}] @@ -648,9 +643,7 @@ class TestPatch(BaseDeployTemplatesAPITest): def test_remove_non_existent_step_property_fail(self, mock_save): patch = [{'path': '/steps/0/non-existent', 'op': 'remove'}] - self._test_update_bad_request( - mock_save, patch, - "can't remove non-existent object 'non-existent'") + self._test_update_bad_request(mock_save, patch) def test_add_root_non_existent(self, mock_save): patch = [{'path': '/foo', 'value': 'bar', 'op': 'add'}] @@ -665,8 +658,7 @@ class TestPatch(BaseDeployTemplatesAPITest): 'priority': 42 } patch = [{'path': '/steps/2', 'op': 'add', 'value': step}] - self._test_update_bad_request( - mock_save, patch, "can't insert outside of list") + self._test_update_bad_request(mock_save, patch) def test_add_multi(self, mock_save): steps = [ diff --git a/ironic/tests/unit/api/controllers/v1/test_utils.py b/ironic/tests/unit/api/controllers/v1/test_utils.py index d4c888222..201bd0217 100644 --- a/ironic/tests/unit/api/controllers/v1/test_utils.py +++ b/ironic/tests/unit/api/controllers/v1/test_utils.py @@ -105,18 +105,15 @@ class TestApiUtils(base.TestCase): # Raises a KeyError. doc = {} patch = [{"op": "remove", "path": "/foo"}] - self.assertRaisesRegex(exception.PatchError, - "can't remove non-existent object 'foo'", - utils.apply_jsonpatch, doc, patch) + self.assertRaises(exception.PatchError, + utils.apply_jsonpatch, doc, patch) def test_apply_jsonpatch_replace_non_existent_list_item(self): # Raises an IndexError. 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) + self.assertRaises(exception.PatchError, + utils.apply_jsonpatch, doc, patch) def test_get_patch_values_no_path(self): patch = [{'path': '/name', 'op': 'update', 'value': 'node-0'}] |