From 3f94f5d224e6d6f8d7bd6e8c4e1ac2fe3f1d489e Mon Sep 17 00:00:00 2001 From: Ruby Loo Date: Mon, 25 Jun 2018 16:05:06 +0000 Subject: [PATCH] Add helper method for testing node fields This adds a helper method '_test_node_fields_hidden_in_lower_version()) to provide consistency and reduce the amount of copy/paste being used for several of the unit tests. Change-Id: I3d319cd1711fe10e9c92ab2076b9b415b7f3810c --- .../unit/api/controllers/v1/test_node.py | 49 +++++++------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/ironic/tests/unit/api/controllers/v1/test_node.py b/ironic/tests/unit/api/controllers/v1/test_node.py index 50f8b03410..8e014fd62e 100644 --- a/ironic/tests/unit/api/controllers/v1/test_node.py +++ b/ironic/tests/unit/api/controllers/v1/test_node.py @@ -198,13 +198,20 @@ class TestListNodes(test_api_base.BaseApiTest): headers={api_base.Version.string: str(api_v1.max_version())}) self.assertEqual(node.uuid, data['uuid']) - def test_node_states_field_hidden_in_lower_version(self): - node = obj_utils.create_test_node(self.context, - chassis_id=self.chassis.id) + def _test_node_field_hidden_in_lower_version(self, field, + old_version, new_version): + node = obj_utils.create_test_node(self.context) data = self.get_json( '/nodes/%s' % node.uuid, - headers={api_base.Version.string: '1.8'}) - self.assertNotIn('states', data) + headers={api_base.Version.string: old_version}) + self.assertNotIn(field, data) + data = self.get_json( + '/nodes/%s' % node.uuid, + headers={api_base.Version.string: new_version}) + self.assertIn(field, data) + + def test_node_states_field_hidden_in_lower_version(self): + self._test_node_field_hidden_in_lower_version('states', '1.8', '1.14') def test_node_interface_fields_hidden_in_lower_version(self): node = obj_utils.create_test_node(self.context) @@ -215,26 +222,15 @@ class TestListNodes(test_api_base.BaseApiTest): self.assertNotIn(field, data) def test_node_storage_interface_hidden_in_lower_version(self): - node = obj_utils.create_test_node(self.context, - storage_interface='cinder') - data = self.get_json( - '/nodes/%s' % node.uuid, - headers={api_base.Version.string: '1.32'}) - self.assertNotIn('storage_interface', data) + self._test_node_field_hidden_in_lower_version('storage_interface', + '1.32', '1.33') def test_node_traits_hidden_in_lower_version(self): - node = obj_utils.create_test_node(self.context) - data = self.get_json( - '/nodes/%s' % node.uuid, - headers={api_base.Version.string: '1.36'}) - self.assertNotIn('traits', data) + self._test_node_field_hidden_in_lower_version('traits', '1.36', '1.37') def test_node_bios_hidden_in_lower_version(self): - node = obj_utils.create_test_node(self.context) - data = self.get_json( - '/nodes/%s' % node.uuid, - headers={api_base.Version.string: '1.39'}) - self.assertNotIn('bios_interface', data) + self._test_node_field_hidden_in_lower_version('bios_interface', + '1.39', '1.40') def test_node_inspect_wait_state_between_api_versions(self): node = obj_utils.create_test_node(self.context, @@ -251,15 +247,8 @@ class TestListNodes(test_api_base.BaseApiTest): higher_version_data['provision_state']) def test_node_fault_hidden_in_lower_version(self): - node = obj_utils.create_test_node(self.context) - data = self.get_json( - '/nodes/%s' % node.uuid, - headers={api_base.Version.string: '1.41'}) - self.assertNotIn('fault', data) - data = self.get_json( - '/nodes/%s' % node.uuid, - headers={api_base.Version.string: '1.42'}) - self.assertIn('fault', data) + self._test_node_field_hidden_in_lower_version('fault', + '1.41', '1.42') def test_get_one_custom_fields(self): node = obj_utils.create_test_node(self.context,