def test_get_stack_not_found_fails(self, mock_heat_client_init): mock_heat_client = mock_heat_client_init.return_value mock_heat_client.stacks.get.side_effect = heatexc.HTTPNotFound('Not found') mock_session = MagicMock() heat_driver = HeatDriver(mock_session) with self.assertRaises(StackNotFoundError) as context: heat_driver.get_stack('12345') self.assertEqual(str(context.exception), 'ERROR: Not found')
def test_get_stack(self, mock_heat_client_init): mock_heat_client = mock_heat_client_init.return_value expected_stack = {'id': 'mock_id'} mock_stack = MagicMock() mock_stack.to_dict.return_value = expected_stack mock_heat_client.stacks.get.return_value = mock_stack mock_session = MagicMock() heat_driver = HeatDriver(mock_session) stack = heat_driver.get_stack('12345') mock_heat_client.stacks.get.assert_called_once_with('12345') self.assertEqual(stack, expected_stack)
def test_get_stack_without_id_fails(self, mock_heat_client_init): mock_session = MagicMock() heat_driver = HeatDriver(mock_session) with self.assertRaises(ValueError) as context: heat_driver.get_stack(None) self.assertEqual(str(context.exception), 'stack_id must be provided')