Exemplo n.º 1
0
def test_registered_source_receiver(mocked_uuid):
    source = IMessageSource.component()
    assert source.__class__ == components.SessionSource

    source.send(u'Message that is a test.')
    assert 'dolmen.message.session' in SESSION
    assert len(source) == 1
    
    assert [msg for msg in source] == [{
        'type': 'message',
        'body': 'Message that is a test.',
        'id': '2abc74bdfd784bf5ba81e9d79d2a9f21',
    }]

    # iterating did not pop anything
    assert len(source) == 1

    # a receiver can be fetched through adapation of the source.
    receiver = IMessageReceiver(source)
    assert receiver.__class__ == components.MessageReceiver

    # Receiving will delete by default.
    messages = list(receiver.receive())
    assert len(messages) == 1
    assert len(source) == 0
    assert messages[0]['type'] == BASE_MESSAGE_TYPE
Exemplo n.º 2
0
def receive(name='', type=BASE_MESSAGE_TYPE):
    """Receives messages from a given receiver.

    If the received has been found with success, an iterable
    of messages is returned. Otherwise, None is returned.
    """
    source = queryUtility(IMessageSource, name=name)
    if source is None:
        return None
    receiver = IMessageReceiver(source)
    if receiver is None:
        return None
    return receiver.receive(type)
Exemplo n.º 3
0
def test_registered_source_receiver():
    source = getUtility(IMessageSource)
    assert source.__class__ == components.SessionSource

    source.send(u'Message that is a test.')
    assert 'dolmen.message.session' in SESSION
    assert len(source) == 1

    assert ([(msg.message, msg.type) for msg in source] ==
            [(u'Message that is a test.', u'message')])

    # iterating did not pop anything
    assert len(source) == 1

    # a receiver can be fetched through adapation of the source.
    receiver = IMessageReceiver(source)
    assert receiver.__class__ == components.MessageReceiver

    # Receiving will delete by default.
    messages = list(receiver.receive())
    assert len(messages) == 1
    assert len(source) == 0
    assert messages[0].type == BASE_MESSAGE_TYPE