simplify crud notification test

test_alarms_sends_notification will hang forever if it fails.
we don't really need to test that its notification is received by
other, just that it sends a notification. drop the test so it
verifies only that.

also, uncap pbr to resolve requirements conflict

Change-Id: I99f9996e5a3dd1e652d4142c7b596ae87da5e698
(cherry picked from commit b231f83f38)
This commit is contained in:
gord chung 2017-06-21 16:34:15 +00:00 committed by gordon chung
parent 5c6b46ecc8
commit 0ffb1da9dd
2 changed files with 15 additions and 24 deletions

View File

@ -18,7 +18,6 @@ import datetime
import os import os
import mock import mock
import oslo_messaging.conffixture
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
from oslo_utils import uuidutils from oslo_utils import uuidutils
import six import six
@ -1707,30 +1706,22 @@ class TestAlarms(TestAlarmsBase):
} }
} }
endpoint = mock.MagicMock() with mock.patch.object(messaging, 'get_notifier') as get_notifier:
target = oslo_messaging.Target(topic="notifications") notifier = get_notifier.return_value
listener = messaging.get_batch_notification_listener( self.post_json('/alarms', params=json, headers=self.auth_headers)
self.transport, [target], [endpoint]) get_notifier.assert_called_once_with(mock.ANY,
listener.start() publisher_id='aodh.api')
endpoint.info.side_effect = lambda *args: listener.stop() calls = notifier.info.call_args_list
self.post_json('/alarms', params=json, headers=self.auth_headers) self.assertEqual(1, len(calls))
listener.wait() args, _ = calls[0]
context, event_type, payload = args
class NotificationsMatcher(object): self.assertEqual('alarm.creation', event_type)
def __eq__(self, notifications): self.assertEqual('sent_notification', payload['detail']['name'])
payload = notifications[0]['payload'] self.assertEqual('ameter', payload['detail']['rule']['meter_name'])
return (payload['detail']['name'] == 'sent_notification' and self.assertTrue(set(['alarm_id', 'detail', 'event_id', 'on_behalf_of',
payload['type'] == 'creation' and 'project_id', 'timestamp', 'type',
payload['detail']['rule']['meter_name'] == 'ameter' and
set(['alarm_id', 'detail', 'event_id', 'on_behalf_of',
'project_id', 'timestamp',
'user_id']).issubset(payload.keys())) 'user_id']).issubset(payload.keys()))
def __ne__(self, other):
return not self.__eq__(other)
endpoint.info.assert_called_once_with(NotificationsMatcher())
def test_alarm_sends_notification(self): def test_alarm_sends_notification(self):
with mock.patch.object(messaging, 'get_notifier') as get_notifier: with mock.patch.object(messaging, 'get_notifier') as get_notifier:
notifier = get_notifier.return_value notifier = get_notifier.return_value

View File

@ -16,7 +16,7 @@ oslo.i18n>=1.5.0,<3.13.0 # Apache-2.0
oslo.log>=1.2.0 # Apache-2.0 oslo.log>=1.2.0 # Apache-2.0
oslo.policy>=0.5.0 # Apache-2.0 oslo.policy>=0.5.0 # Apache-2.0
PasteDeploy>=1.5.0 PasteDeploy>=1.5.0
pbr>=1.8,<2.0.0 pbr>=1.8
pecan>=0.8.0 pecan>=0.8.0
oslo.messaging>=5.2.0 # Apache-2.0 oslo.messaging>=5.2.0 # Apache-2.0
oslo.middleware>=3.22.0,<3.24.0 # Apache-2.0 oslo.middleware>=3.22.0,<3.24.0 # Apache-2.0