"Fossies" - the Fresh Open Source Software Archive

Member "masakari-9.0.0/masakari/tests/unit/engine/test_utils.py" (13 May 2020, 3341 Bytes) of package /linux/misc/openstack/masakari-9.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test_utils.py": 8.0.0_vs_9.0.0.

    1 # Copyright (c) 2018 NTT DATA
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License");
    4 # you may not use this file except in compliance with the License.
    5 # You may obtain a copy of the License at
    6 #
    7 #    http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 # Unless required by applicable law or agreed to in writing, software
   10 # distributed under the License is distributed on an "AS IS" BASIS,
   11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
   12 # implied.
   13 # See the License for the specific language governing permissions and
   14 # limitations under the License.
   15 
   16 import socket
   17 import testtools
   18 from unittest import mock
   19 
   20 from masakari.engine import utils as engine_utils
   21 from masakari.notifications.objects import base as notification_base
   22 from masakari.notifications.objects import exception as notification_exception
   23 from masakari.notifications.objects import notification as event_notification
   24 from masakari.objects import fields
   25 from masakari.objects import notification as notification_obj
   26 
   27 
   28 class TestApiUtils(testtools.TestCase):
   29     def setUp(self):
   30         super(TestApiUtils, self).setUp()
   31 
   32     @mock.patch.object(notification_base, 'EventType')
   33     @mock.patch.object(notification_base, 'NotificationPublisher')
   34     @mock.patch.object(event_notification, 'NotificationApiNotification')
   35     @mock.patch.object(event_notification, 'NotificationApiPayload')
   36     @mock.patch.object(notification_exception.ExceptionPayload,
   37                        'from_exc_and_traceback')
   38     def test_notify_about_notification_update(
   39         self, mock_from_exception, mock_NotificationApiPayload,
   40         mock_NotificationApiNotification, mock_NotificationPublisher,
   41         mock_EventType):
   42         mock_fault = mock.Mock()
   43         mock_from_exception.return_value = mock_fault
   44         mock_payload = mock.Mock()
   45         mock_NotificationApiPayload.return_value = mock_payload
   46         mock_engine_notification = mock.Mock()
   47         mock_NotificationApiNotification.return_value = (
   48             mock_engine_notification)
   49         mock_engine_notification.emit.return_value = None
   50         mock_publisher = mock.Mock()
   51         mock_NotificationPublisher.return_value = mock_publisher
   52         mock_event_type = mock.Mock()
   53         mock_EventType.return_value = mock_event_type
   54 
   55         mock_context = mock.Mock()
   56         notification = notification_obj.Notification()
   57         action = fields.EventNotificationAction.NOTIFICATION_PROCESS
   58         phase = fields.EventNotificationPhase.ERROR
   59         e = Exception()
   60 
   61         engine_utils.notify_about_notification_update(mock_context,
   62             notification, action=action, phase=phase, exception=e)
   63 
   64         mock_from_exception.assert_called_once_with(e, None)
   65         mock_NotificationApiPayload.assert_called_once_with(
   66             notification=notification, fault=mock_fault)
   67         mock_NotificationApiNotification.assert_called_once_with(
   68             context=mock_context,
   69             priority=fields.EventNotificationPriority.ERROR,
   70             publisher=mock_publisher,
   71             event_type=mock_event_type,
   72             payload=mock_payload)
   73         mock_NotificationPublisher.assert_called_once_with(
   74             context=mock_context, host=socket.gethostname(),
   75             binary='masakari-engine')
   76         mock_engine_notification.emit.assert_called_once_with(mock_context)