From 32ab90b3b9727ddf8920feb56e01551065cb9581 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Mon, 23 Nov 2020 16:50:08 +1300 Subject: [PATCH] Test patching booleans with string values The baremetal client encodes boolean patch values as strings ("True", "False") but there is no unit test coverage which confirms that this actually works. This change adds that test coverage. Change-Id: I9e428ad973e88d3e1ef1e04e49a7b00a4e2d43fd --- .../unit/api/controllers/v1/test_node.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/ironic/tests/unit/api/controllers/v1/test_node.py b/ironic/tests/unit/api/controllers/v1/test_node.py index 4f863a3a10..d450d78ee7 100644 --- a/ironic/tests/unit/api/controllers/v1/test_node.py +++ b/ironic/tests/unit/api/controllers/v1/test_node.py @@ -3384,6 +3384,38 @@ class TestPatch(test_api_base.BaseApiTest): self.assertEqual('application/json', response.content_type) self.assertEqual(http_client.OK, response.status_code) + def test_update_protected_string(self): + node = obj_utils.create_test_node(self.context, + uuid=uuidutils.generate_uuid(), + provision_state='active') + self.mock_update_node.return_value = node + headers = {api_base.Version.string: '1.48'} + # Patch with valid boolean string + response = self.patch_json('/nodes/%s' % node.uuid, + [{'path': '/protected', + 'value': "True", + 'op': 'replace'}], + headers=headers) + self.assertEqual('application/json', response.content_type) + self.assertEqual(http_client.OK, response.status_code) + + def test_update_protected_string_invalid(self): + node = obj_utils.create_test_node(self.context, + uuid=uuidutils.generate_uuid(), + provision_state='active') + self.mock_update_node.return_value = node + headers = {api_base.Version.string: '1.48'} + # Patch with invalid boolean string + response = self.patch_json('/nodes/%s' % node.uuid, + [{'path': '/protected', + 'value': "YeahNahGood", + 'op': 'replace'}], + headers=headers, + expect_errors=True) + self.assertEqual(http_client.BAD_REQUEST, response.status_code) + self.assertIn("Invalid protected: Unrecognized value 'YeahNahGood'", + response.json['error_message']) + def test_update_protected_remove(self): node = obj_utils.create_test_node(self.context, uuid=uuidutils.generate_uuid(),