Beispiel #1
0
def test_event_container():
    container = EventContainer('test', {})
    container.set_owner('testowner')
    container.set_fingerprint('testfp')
    container.set_metadata({'a': 'b'})

    record = container.get_record()
    assert record.owner == 'testowner'
    assert record.fingerprint == 'testfp'
    assert 'a' in record.event_metadata
Beispiel #2
0
def test_event_container():
    container = EventContainer("test", {})
    container.set_owner("testowner")
    container.set_fingerprint("testfp")
    container.set_metadata({"a": "b"})

    record = container.get_record()
    assert record.owner == "testowner"
    assert record.fingerprint == "testfp"
    assert "a" in record.event_metadata
Beispiel #3
0
def messages() -> List[EventContainer]:
    """Get all test messages and their filenames as an iterator.

    Returns:
        EventContainer: some test event
    """
    event = EventContainer("test", {})
    event.set_owner("*****@*****.**")
    event.set_fingerprint("test")
    return [event]
Beispiel #4
0
def get_all_test_messages(parsed=False):
    """Get all test messages and their filenames as an iterator.

    Args:
        parsed (bool): returns Event objects if true otherwise strings
    Yields:
        EventContainer: some test event
    """
    event = EventContainer("test", {})
    event.set_owner("*****@*****.**")
    event.set_fingerprint("test")
    return [event]
Beispiel #5
0
def test_message_callback(app):
    @app.register_parser('test')
    def parse_message(message):
        ev = json.loads(message)
        if 'a' in ev:
            return ev, None
        raise ValueError('fail')

    hydrator_mock = mock.Mock()
    app.register_hydrator('test', hydrator_mock)

    filter_return_value = EventContainer('test', {"a": "b"})
    filter_mock = mock.Mock(return_value=filter_return_value)
    app.register_filter('test', filter_mock)

    assert not app.message_callback('test1', '{}')
    assert not app.message_callback('test', '{ "c": "d" }')

    app.message_callback('test', '{ "a": "b" }')
    assert hydrator_mock.called
    assert filter_mock.called
    assert filter_mock.return_value, filter_return_value
Beispiel #6
0
def test_message_callback(app):
    @app.register_parser("test")
    def parse_message(message):
        ev = json.loads(message)
        if "a" in ev:
            return ev, None
        raise ValueError("fail")

    hydrator_mock = mock.Mock()
    app.register_hydrator("test", hydrator_mock)

    filter_return_value = EventContainer("test", {"a": "b"})
    filter_mock = mock.Mock(return_value=filter_return_value)
    app.register_filter("test", filter_mock)

    assert not app.message_callback("test1", "{}")
    assert not app.message_callback("test", '{ "c": "d" }')

    app.message_callback("test", '{ "a": "b" }')
    assert hydrator_mock.called
    assert filter_mock.called
    assert filter_mock.return_value, filter_return_value