diff options
author | Steve Baker <sbaker@redhat.com> | 2020-11-23 16:50:08 +1300 |
---|---|---|
committer | Steve Baker <sbaker@redhat.com> | 2020-11-27 10:52:14 +1300 |
commit | 32ab90b3b9727ddf8920feb56e01551065cb9581 (patch) | |
tree | 2d99230d0a23f64a75ed8021af7a0dc52ca4d0dc | |
parent | a3644ebd6395fb767c5e8bec2aced93ca7f5f8df (diff) | |
download | ironic-32ab90b3b9727ddf8920feb56e01551065cb9581.tar.gz |
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
-rw-r--r-- | ironic/tests/unit/api/controllers/v1/test_node.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/ironic/tests/unit/api/controllers/v1/test_node.py b/ironic/tests/unit/api/controllers/v1/test_node.py index 4f863a3a1..d450d78ee 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(), |