X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Ftest%2FOpenStack%2Funit%2Ftest_notifier.py;h=a420c708467755cbec010ff37d37c34bdcdcbb94;hb=93699898c51364cde193d8d441f4aed45670e7bf;hp=f0fbf55f0de7758d8af3c2e6cd997a0e65cb31ab;hpb=a4ffa936b4f8a2bfcd1b64541e00c93aac449a56;p=osm%2FMON.git diff --git a/osm_mon/test/OpenStack/unit/test_notifier.py b/osm_mon/test/OpenStack/unit/test_notifier.py index f0fbf55..a420c70 100644 --- a/osm_mon/test/OpenStack/unit/test_notifier.py +++ b/osm_mon/test/OpenStack/unit/test_notifier.py @@ -25,9 +25,9 @@ import json import unittest import mock +from kafka import KafkaProducer from osm_mon.core.database import DatabaseManager, Alarm -from osm_mon.core.message_bus.producer import KafkaProducer from osm_mon.plugins.OpenStack.Aodh.notifier import NotifierHandler post_data = {"severity": "critical", @@ -52,7 +52,7 @@ class Response(object): class RFile(): def read(self, content_length): - return post_data + return json.dumps(post_data, sort_keys=True) class MockNotifierHandler(NotifierHandler): @@ -76,6 +76,8 @@ class MockNotifierHandler(NotifierHandler): pass +@mock.patch.object(KafkaProducer, "__init__", lambda *args, **kwargs: None) +@mock.patch.object(KafkaProducer, "flush", mock.Mock()) class TestNotifier(unittest.TestCase): """Test the NotifierHandler class for requests from aodh.""" @@ -98,9 +100,9 @@ class TestNotifier(unittest.TestCase): self.handler.do_POST() set_head.assert_called_once() - notify.assert_called_with(json.dumps(post_data)) + notify.assert_called_with(post_data) - @mock.patch.object(KafkaProducer, "publish_alarm_response") + @mock.patch.object(NotifierHandler, "_publish_response") @mock.patch.object(DatabaseManager, "get_alarm") def test_notify_alarm_valid_alarm( self, get_alarm, notify): @@ -113,10 +115,9 @@ class TestNotifier(unittest.TestCase): get_alarm.return_value = mock_alarm self.handler.notify_alarm(post_data) + notify.assert_called_with('notify_alarm', mock.ANY) - notify.assert_called_with("notify_alarm", mock.ANY) - - @mock.patch.object(KafkaProducer, "publish_alarm_response") + @mock.patch.object(NotifierHandler, "_publish_response") @mock.patch.object(DatabaseManager, "get_alarm") def test_notify_alarm_invalid_alarm( self, get_alarm, notify):