From a59934f580bcd4fe0eb9156b424b0ea40f5f0e2a Mon Sep 17 00:00:00 2001 From: Sinval Vieira Date: Wed, 9 Dec 2015 20:31:58 -0300 Subject: [PATCH] Simplifies exception message assurance for oneview.common tests This change was suggested on another patch, the idea is to make exception message assurance with RaisesRegexp. Change-Id: Idd7c34428398f1c746ee4ffa6b83d28f87ad5bc7 --- .../drivers/modules/oneview/test_common.py | 80 +++++-------------- 1 file changed, 20 insertions(+), 60 deletions(-) diff --git a/ironic/tests/unit/drivers/modules/oneview/test_common.py b/ironic/tests/unit/drivers/modules/oneview/test_common.py index 79b5a44ba2..71d18fecb1 100644 --- a/ironic/tests/unit/drivers/modules/oneview/test_common.py +++ b/ironic/tests/unit/drivers/modules/oneview/test_common.py @@ -56,28 +56,16 @@ class OneViewCommonTestCase(db_base.DbTestCase): "capabilities": ("enclosure_group_uri:fake_eg_uri," "server_profile_template_uri:fake_spt_uri") } - - exc = self.assertRaises( - exception.MissingParameterValue, - common.verify_node_info, - self.node - ) - self.assertEqual("Missing the keys for the following OneView data in " - "node's properties/capabilities: " - "server_hardware_type_uri.", - str(exc)) + with self.assertRaisesRegexp(exception.MissingParameterValue, + "server_hardware_type_uri"): + common.verify_node_info(self.node) def test_verify_node_info_missing_node_driver_info(self): self.node.driver_info = {} - exc = self.assertRaises( - exception.MissingParameterValue, - common.verify_node_info, - self.node - ) - self.assertEqual("Missing the keys for the following OneView data in " - "node's driver_info: server_hardware_uri.", - str(exc)) + with self.assertRaisesRegexp(exception.MissingParameterValue, + "server_hardware_uri"): + common.verify_node_info(self.node) def test_verify_node_info_missing_spt(self): properties = db_utils.get_test_oneview_properties() @@ -85,17 +73,9 @@ class OneViewCommonTestCase(db_base.DbTestCase): "enclosure_group_uri:fake_eg_uri") self.node.properties = properties - - exc = self.assertRaises( - exception.MissingParameterValue, - common.verify_node_info, - self.node - ) - # TODO(gabriel-bezerra): Simplify this after Mitaka - self.assertEqual( - ("Missing 'server_profile_template_uri' parameter value in " - "properties/capabilities"), - str(exc)) + with self.assertRaisesRegexp(exception.MissingParameterValue, + "server_profile_template_uri"): + common.verify_node_info(self.node) def test_verify_node_info_missing_sh(self): driver_info = db_utils.get_test_oneview_driver_info() @@ -110,16 +90,9 @@ class OneViewCommonTestCase(db_base.DbTestCase): self.node.properties = properties self.node.driver_info = driver_info - exc = self.assertRaises( - exception.MissingParameterValue, - common.verify_node_info, - self.node - ) - # TODO(gabriel-bezerra): Simplify this after Mitaka - self.assertEqual( - ("Missing the keys for the following OneView data in node's " - "driver_info: server_hardware_uri."), - str(exc)) + with self.assertRaisesRegexp(exception.MissingParameterValue, + "server_hardware_uri"): + common.verify_node_info(self.node) def test_verify_node_info_missing_sht(self): driver_info = db_utils.get_test_oneview_driver_info() @@ -131,16 +104,9 @@ class OneViewCommonTestCase(db_base.DbTestCase): self.node.properties = properties self.node.driver_info = driver_info - exc = self.assertRaises( - exception.MissingParameterValue, - common.verify_node_info, - self.node - ) - # TODO(gabriel-bezerra): Simplify this after Mitaka - self.assertEqual( - ("Missing the keys for the following OneView data in node's " - "properties/capabilities: server_hardware_type_uri."), - str(exc)) + with self.assertRaisesRegexp(exception.MissingParameterValue, + "server_hardware_type_uri"): + common.verify_node_info(self.node) def test_get_oneview_info(self): complete_node = self.node @@ -289,17 +255,11 @@ class OneViewCommonTestCase(db_base.DbTestCase): ) def test__verify_node_info_missing_values_empty_string(self): - exc_expected_msg = ("Missing parameter value for: 'properties:a'" - ", 'properties:b'") - - self.assertRaisesRegexp( - exception.MissingParameterValue, - exc_expected_msg, - common._verify_node_info, - "properties", - {"a": '', "b": None, "c": "something"}, - ["a", "b", "c"] - ) + with self.assertRaisesRegexp(exception.MissingParameterValue, + "'properties:a', 'properties:b'"): + common._verify_node_info("properties", + {"a": '', "b": None, "c": "something"}, + ["a", "b", "c"]) def _test_translate_oneview_states(self, power_state_to_translate, expected_translated_power_state):