def test_submit_event_without_subscriber(self, start_mock, subscription_mock, check_ov_availability): """Tests SubmitTestEvent action with no subscribers""" util.load_config(self.config_file) with open('oneview_redfish_toolkit/mockups/oneview/Alert.json') as f: event_mockup = Event(json.loads(f.read())) subscription_mock['Alert'].values.return_value = [] util.dispatch_event(event_mockup) self.assertFalse(start_mock.called)
def consume_message(ch, method, properties, body): body = json.loads(body.decode('utf-8')) resource = body['resource'] if (resource['category'] == 'alerts'): category = resource['associatedResource']['resourceCategory'] else: category = resource['category'] if (category in SCMB_RESOURCE_LIST): event = Event(body) util.dispatch_event(event) else: logging.debug('SCMB message received for an unmanaged resource')
def test_submit_event_with_subscriber(self, start_mock, subscription_mock, check_ov_availability): """Tests SubmitTestEvent action with two subscribers""" config.load_config(self.config_file) with open('oneview_redfish_toolkit/mockups/oneview/Alert.json') as f: event_mockup = Event(json.loads(f.read())) subscription_mock['Alert'].values.return_value = [ Subscription('1', 'destination1', [], 'context1'), Subscription('2', 'destination2', [], 'context2') ] util.dispatch_event(event_mockup) self.assertTrue(start_mock.call_count == 2)
def test_dispatch_event(self, exception_mock, request_mock): """Tests dispatch event""" with open('oneview_redfish_toolkit/mockups/oneview/Alert.json') as f: event_mockup = json.loads(f.read()) event = Event(event_mockup) with open( 'oneview_redfish_toolkit/mockups/redfish/EventDestination.json' ) as f: subscription_mockup = json.loads(f.read()) subscription = Subscription(subscription_mockup['Id'], subscription_mockup['Destination'], subscription_mockup['EventTypes'], subscription_mockup['Context']) dispatcher = EventDispatcher(event, subscription, 1, 1) dispatcher.run() self.assertTrue(request_mock.called) self.assertFalse(exception_mock.called)