示例#1
0
def test_process_external(find_event):
    core.cleanup_handlers()

    handler = Mock()
    eventlib.external_handler('app.Event')(handler)

    data = {'file': '/etc/passwd', 'server': 'yipster'}
    core.process_external('app.Event', data)

    handler.assert_called_once_with(data)
示例#2
0
def test_process_external(find_event):
    core.cleanup_handlers()

    handler = Mock()
    eventlib.external_handler('app.Event')(handler)

    data = {'file': '/etc/passwd', 'server': 'yipster'}
    core.process_external('app.Event', data)

    handler.assert_called_once_with(data)
示例#3
0
def listen_for_events():
    """Pubsub event listener

    Listen for events in the pubsub bus and calls the process function
    when somebody comes to play.
    """
    import_event_modules()
    conn = redis_connection.get_connection()
    pubsub = conn.pubsub()
    pubsub.subscribe("eventlib")
    for message in pubsub.listen():
        if message['type'] != 'message':
            continue
        data = loads(message["data"])
        if 'name' in data:
            event_name = data.pop('name')
            process_external(event_name, data)
示例#4
0
def test_process_external_fails_gracefully(settings, logger, find_event):
    core.cleanup_handlers()
    settings.DEBUG = False

    handler_fail = Mock()
    handler_fail.side_effect = ValueError('P0wned!!!')
    eventlib.external_handler('myapp.CoolEvent')(handler_fail)

    handler = Mock()
    eventlib.external_handler('myapp.CoolEvent')(handler)

    data = {'a': 1}
    event = 'myapp.CoolEvent'
    core.process_external(event, data)

    logger.warning.assert_called_once_with(
        'One of the handlers for the event "myapp.CoolEvent" has '
        'failed with the following exception: P0wned!!!')
    handler.assert_called_once_with(data)
示例#5
0
def test_process_external_fails_gracefully(settings, logger, find_event):
    core.cleanup_handlers()
    settings.DEBUG = False

    handler_fail = Mock()
    handler_fail.side_effect = ValueError('P0wned!!!')
    eventlib.external_handler('myapp.CoolEvent')(handler_fail)

    handler = Mock()
    eventlib.external_handler('myapp.CoolEvent')(handler)

    data = {'a': 1}
    event = 'myapp.CoolEvent'
    core.process_external(event, data)

    logger.warning.assert_called_once_with(
        'One of the handlers for the event "myapp.CoolEvent" has '
        'failed with the following exception: P0wned!!!')
    handler.assert_called_once_with(data)