def test__emit_conductor_node_notification(self, mock_secrets):
        mock_notify_method = mock.Mock()
        # Required for exception handling
        mock_notify_method.__name__ = 'MockNotificationConstructor'
        mock_payload_method = mock.Mock()
        mock_payload_method.__name__ = 'MockPayloadConstructor'
        mock_kwargs = {'mock0': mock.Mock(),
                       'mock1': mock.Mock()}

        notif_utils._emit_conductor_node_notification(
            self.task,
            mock_notify_method,
            mock_payload_method,
            'fake_action',
            fields.NotificationLevel.INFO,
            fields.NotificationStatus.SUCCESS,
            **mock_kwargs
        )

        mock_payload_method.assert_called_once_with(
            self.task.node, **mock_kwargs)
        mock_secrets.assert_called_once_with(mock_payload_method.return_value)
        mock_notify_method.assert_called_once_with(
            publisher=mock.ANY,
            event_type=mock.ANY,
            level=fields.NotificationLevel.INFO,
            payload=mock_payload_method.return_value
        )
        mock_notify_method.return_value.emit.assert_called_once_with(
            self.task.context)
    def test__emit_conductor_node_notification(self, mock_secrets):
        mock_notify_method = mock.Mock()
        # Required for exception handling
        mock_notify_method.__name__ = 'MockNotificationConstructor'
        mock_payload_method = mock.Mock()
        mock_payload_method.__name__ = 'MockPayloadConstructor'
        mock_kwargs = {'mock0': mock.Mock(),
                       'mock1': mock.Mock()}

        notif_utils._emit_conductor_node_notification(
            self.task,
            mock_notify_method,
            mock_payload_method,
            'fake_action',
            fields.NotificationLevel.INFO,
            fields.NotificationStatus.SUCCESS,
            **mock_kwargs
        )

        mock_payload_method.assert_called_once_with(
            self.task.node, **mock_kwargs)
        mock_secrets.assert_called_once_with(mock_payload_method.return_value)
        mock_notify_method.assert_called_once_with(
            publisher=mock.ANY,
            event_type=mock.ANY,
            level=fields.NotificationLevel.INFO,
            payload=mock_payload_method.return_value
        )
        mock_notify_method.return_value.emit.assert_called_once_with(
            self.task.context)
    def test__emit_conductor_node_notification_known_payload_exc(self):
        """Test exception caught for a known payload exception."""
        mock_notify_method = mock.Mock()
        # Required for exception handling
        mock_notify_method.__name__ = 'MockNotificationConstructor'
        mock_payload_method = mock.Mock()
        mock_payload_method.__name__ = 'MockPayloadConstructor'
        mock_kwargs = {'mock0': mock.Mock(), 'mock1': mock.Mock()}
        mock_payload_method.side_effect = exception.NotificationSchemaKeyError

        notif_utils._emit_conductor_node_notification(
            self.task, mock_notify_method, mock_payload_method, 'fake_action',
            fields.NotificationLevel.INFO, fields.NotificationStatus.SUCCESS,
            **mock_kwargs)

        self.assertFalse(mock_notify_method.called)
    def test__emit_conductor_node_notification_known_notify_exc(
            self, mock_secrets):
        """Test exception caught for a known notification exception."""
        mock_notify_method = mock.Mock()
        # Required for exception handling
        mock_notify_method.__name__ = 'MockNotificationConstructor'
        mock_payload_method = mock.Mock()
        mock_payload_method.__name__ = 'MockPayloadConstructor'
        mock_kwargs = {'mock0': mock.Mock(), 'mock1': mock.Mock()}
        mock_notify_method.side_effect = VersionedObjectsException

        notif_utils._emit_conductor_node_notification(
            self.task, mock_notify_method, mock_payload_method, 'fake_action',
            fields.NotificationLevel.INFO, fields.NotificationStatus.SUCCESS,
            **mock_kwargs)

        self.assertFalse(mock_notify_method.return_value.emit.called)
    def test__emit_conductor_node_notification_known_payload_exc(self):
        """Test exception caught for a known payload exception."""
        mock_notify_method = mock.Mock()
        # Required for exception handling
        mock_notify_method.__name__ = 'MockNotificationConstructor'
        mock_payload_method = mock.Mock()
        mock_payload_method.__name__ = 'MockPayloadConstructor'
        mock_kwargs = {'mock0': mock.Mock(),
                       'mock1': mock.Mock()}
        mock_payload_method.side_effect = exception.NotificationSchemaKeyError

        notif_utils._emit_conductor_node_notification(
            self.task,
            mock_notify_method,
            mock_payload_method,
            'fake_action',
            fields.NotificationLevel.INFO,
            fields.NotificationStatus.SUCCESS,
            **mock_kwargs
        )

        self.assertFalse(mock_notify_method.called)
    def test__emit_conductor_node_notification_known_notify_exc(self,
                                                                mock_secrets):
        """Test exception caught for a known notification exception."""
        mock_notify_method = mock.Mock()
        # Required for exception handling
        mock_notify_method.__name__ = 'MockNotificationConstructor'
        mock_payload_method = mock.Mock()
        mock_payload_method.__name__ = 'MockPayloadConstructor'
        mock_kwargs = {'mock0': mock.Mock(),
                       'mock1': mock.Mock()}
        mock_notify_method.side_effect = VersionedObjectsException

        notif_utils._emit_conductor_node_notification(
            self.task,
            mock_notify_method,
            mock_payload_method,
            'fake_action',
            fields.NotificationLevel.INFO,
            fields.NotificationStatus.SUCCESS,
            **mock_kwargs
        )

        self.assertFalse(mock_notify_method.return_value.emit.called)