def test_default_exchange_topics(self): topics = NetworkBandwidthNotification.get_exchange_topics(cfg.CONF) assert len(topics) == 1 got_exchange = topics[0].exchange got_topics = topics[0].topics expected_exchange = 'akanda' expected_topics = set(['notifications.info']) assert got_exchange == expected_exchange assert got_topics == expected_topics
def test_multiple_exchange_topics(self): CONF = mock.Mock() CONF.akanda_notification_exchange = 'the_exchange' CONF.akanda_notification_topics = ['topic1', 'topic2'] topics = NetworkBandwidthNotification.get_exchange_topics(CONF) assert len(topics) == 1 got_exchange = topics[0].exchange got_topics = topics[0].topics expected_exchange = 'the_exchange' expected_topics = set(['topic1.info', 'topic2.info']) assert got_exchange == expected_exchange assert got_topics == expected_topics
def setUp(self): self.bw_handler = NetworkBandwidthNotification()
class TestNotifications(unittest.TestCase): def setUp(self): self.bw_handler = NetworkBandwidthNotification() @staticmethod def _find_counter(counters, name): for counter in counters: if counter.name == name: return counter return None def test_default_exchange_topics(self): topics = NetworkBandwidthNotification.get_exchange_topics(cfg.CONF) assert len(topics) == 1 got_exchange = topics[0].exchange got_topics = topics[0].topics expected_exchange = 'akanda' expected_topics = set(['notifications.info']) assert got_exchange == expected_exchange assert got_topics == expected_topics def test_multiple_exchange_topics(self): CONF = mock.Mock() CONF.akanda_notification_exchange = 'the_exchange' CONF.akanda_notification_topics = ['topic1', 'topic2'] topics = NetworkBandwidthNotification.get_exchange_topics(CONF) assert len(topics) == 1 got_exchange = topics[0].exchange got_topics = topics[0].topics expected_exchange = 'the_exchange' expected_topics = set(['topic1.info', 'topic2.info']) assert got_exchange == expected_exchange assert got_topics == expected_topics def _check_notification(self, message, expected_counters): got = list( self.bw_handler.process_notification(message) ) assert len(got) == len(expected_counters) for name in expected_counters: counter = TestNotifications._find_counter(got, name) assert counter is not None got_volume = counter.volume expected_volume = expected_counters[name] assert got_volume == expected_volume got_project_id = counter.project_id expected_project_id = message['tenant_id'] assert got_project_id == expected_project_id got_timestamp = counter.timestamp expected_timestamp = message['timestamp'] assert got_timestamp == expected_timestamp def test_process_notification(self): self._check_notification(BW_NOTIFICATION, EXPECTED_COUNTERS) def test_process_notification_alt(self): self._check_notification(BW_NOTIFICATION_ALT, EXPECTED_COUNTERS)