From 8e95cdf8ec5f80cc8551fe124128461d68d3ac54 Mon Sep 17 00:00:00 2001 From: Ruby Loo Date: Thu, 16 Jun 2016 20:15:17 -0400 Subject: [PATCH] Replace dict.get(key) in api & conductor tests This replaces dict.get(key) with dict[key] in tests/unit/api & tests/unit/conductor, since we should be explicit about whether we expect the key to exist or not. In particular, we shouldn't be doing self.assertIsNone(dict.get(key)) since it will pass if 1. the value is None or 2. if the key isn't in the dict. For the case of 2, .assertIsNone() is replaced with .assertNotIn(). Change-Id: Ia305a221389e39d759b0881620c200c625fc98e1 Closes-Bug: #1590808 --- ironic/tests/unit/api/v1/test_nodes.py | 16 ++++++---------- ironic/tests/unit/conductor/test_manager.py | 6 +++--- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/ironic/tests/unit/api/v1/test_nodes.py b/ironic/tests/unit/api/v1/test_nodes.py index 9a100a8ce9..7e21f21fe4 100644 --- a/ironic/tests/unit/api/v1/test_nodes.py +++ b/ironic/tests/unit/api/v1/test_nodes.py @@ -536,8 +536,7 @@ class TestListNodes(test_api_base.BaseApiTest): def test_associated_nodes_insensitive(self): associated_nodes = (self - ._create_association_test_nodes() - .get('associated')) + ._create_association_test_nodes()['associated']) data = self.get_json('/nodes?associated=true') data1 = self.get_json('/nodes?associated=True') @@ -555,9 +554,8 @@ class TestListNodes(test_api_base.BaseApiTest): self.assertTrue(response.json['error_message']) def test_unassociated_nodes_insensitive(self): - unassociated_nodes = (self - ._create_association_test_nodes() - .get('unassociated')) + unassociated_nodes = ( + self._create_association_test_nodes()['unassociated']) data = self.get_json('/nodes?associated=false') data1 = self.get_json('/nodes?associated=FALSE') @@ -568,9 +566,8 @@ class TestListNodes(test_api_base.BaseApiTest): self.assertEqual(sorted(unassociated_nodes), sorted(uuids)) def test_unassociated_nodes_with_limit(self): - unassociated_nodes = (self - ._create_association_test_nodes() - .get('unassociated')) + unassociated_nodes = ( + self._create_association_test_nodes()['unassociated']) data = self.get_json('/nodes?associated=False&limit=2') @@ -585,8 +582,7 @@ class TestListNodes(test_api_base.BaseApiTest): def test_detail_with_association_filter(self): associated_nodes = (self - ._create_association_test_nodes() - .get('associated')) + ._create_association_test_nodes()['associated']) data = self.get_json('/nodes/detail?associated=true') self.assertIn('driver', data['nodes'][0]) self.assertEqual(len(associated_nodes), len(data['nodes'])) diff --git a/ironic/tests/unit/conductor/test_manager.py b/ironic/tests/unit/conductor/test_manager.py index bcd4ff5283..ac287fe392 100644 --- a/ironic/tests/unit/conductor/test_manager.py +++ b/ironic/tests/unit/conductor/test_manager.py @@ -1491,7 +1491,7 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, # Node will be moved to CLEANING self.assertEqual(states.CLEANING, node.provision_state) self.assertEqual(states.MANAGEABLE, node.target_provision_state) - self.assertIsNone(node.driver_internal_info.get('clean_steps')) + self.assertNotIn('clean_steps', node.driver_internal_info) self.assertIsNone(node.last_error) @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') @@ -1719,8 +1719,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, self.assertEqual(states.AVAILABLE, node.provision_state) self.assertEqual(states.NOSTATE, node.target_provision_state) self.assertEqual({}, node.clean_step) - self.assertIsNone(node.driver_internal_info.get('clean_steps')) - self.assertIsNone(node.driver_internal_info.get('clean_step_index')) + self.assertNotIn('clean_steps', node.driver_internal_info) + self.assertNotIn('clean_step_index', node.driver_internal_info) @mock.patch('ironic.drivers.modules.fake.FakeDeploy.prepare_cleaning') def __do_node_clean_prepare_clean_fail(self, mock_prep, clean_steps=None):