Exemplo n.º 1
0
def test_event_handler(queue_consumer, mock_container):

    container = mock_container
    container.service_name = "destservice"

    # test default configuration
    event_handler = EventHandler("srcservice",
                                 "eventtype").bind(container, "foobar")
    event_handler.setup()

    assert event_handler.queue.durable is True
    assert event_handler.queue.routing_key == "eventtype"
    assert event_handler.queue.exchange.name == "srcservice.events"
    queue_consumer.register_provider.assert_called_once_with(event_handler)

    # test service pool handler
    event_handler = EventHandler("srcservice",
                                 "eventtype").bind(container, "foobar")
    event_handler.setup()

    assert (event_handler.queue.name ==
            "evt-srcservice-eventtype--destservice.foobar")

    # test broadcast handler
    event_handler = EventHandler("srcservice",
                                 "eventtype",
                                 handler_type=BROADCAST).bind(
                                     container, "foobar")
    event_handler.setup()

    assert event_handler.queue.name.startswith("evt-srcservice-eventtype-")

    # test singleton handler
    event_handler = EventHandler("srcservice",
                                 "eventtype",
                                 handler_type=SINGLETON).bind(
                                     container, "foobar")
    event_handler.setup()

    assert event_handler.queue.name == "evt-srcservice-eventtype"

    # test reliable delivery
    event_handler = EventHandler("srcservice",
                                 "eventtype").bind(container, "foobar")
    event_handler.setup()

    assert event_handler.queue.auto_delete is False
Exemplo n.º 2
0
def test_event_handler(queue_consumer):

    container = Mock(spec=ServiceContainer)
    container.service_name = "destservice"

    # test default configuration
    event_handler = EventHandler("srcservice", "eventtype").bind(
        container, "foobar")
    event_handler.setup()

    assert event_handler.queue.durable is True
    assert event_handler.queue.routing_key == "eventtype"
    assert event_handler.queue.exchange.name == "srcservice.events"
    queue_consumer.register_provider.assert_called_once_with(event_handler)

    # test service pool handler
    event_handler = EventHandler("srcservice", "eventtype").bind(
        container, "foobar")
    event_handler.setup()

    assert (event_handler.queue.name ==
            "evt-srcservice-eventtype--destservice.foobar")

    # test broadcast handler
    event_handler = EventHandler(
        "srcservice",
        "eventtype",
        handler_type=BROADCAST,
        reliable_delivery=False).bind(container, "foobar")
    event_handler.setup()

    assert event_handler.queue.name.startswith("evt-srcservice-eventtype-")

    # test singleton handler
    event_handler = EventHandler(
        "srcservice", "eventtype", handler_type=SINGLETON).bind(
            container, "foobar")
    event_handler.setup()

    assert event_handler.queue.name == "evt-srcservice-eventtype"

    # test reliable delivery
    event_handler = EventHandler("srcservice", "eventtype").bind(
        container, "foobar")
    event_handler.setup()

    assert event_handler.queue.auto_delete is False
Exemplo n.º 3
0
def test_event_handler(queue_consumer, mock_container):

    container = mock_container
    container.service_name = "destservice"

    # test default configuration
    event_handler = EventHandler("srcservice",
                                 "eventtype").bind(container, "foobar")
    event_handler.setup()

    assert event_handler.queue.durable is True
    assert event_handler.queue.routing_key == "eventtype"
    assert event_handler.queue.exchange.name == "srcservice.events"
    queue_consumer.register_provider.assert_called_once_with(event_handler)

    # test service pool handler
    event_handler = EventHandler("srcservice",
                                 "eventtype").bind(container, "foobar")
    event_handler.setup()

    assert event_handler.queue.name == (
        "evt-srcservice-eventtype--destservice.foobar")
    assert event_handler.queue.exclusive is False

    # test broadcast handler with default identifier
    with patch('nameko.events.uuid') as mock_uuid:
        mock_uuid.uuid4().hex = "uuid-value"
        event_handler = EventHandler("srcservice",
                                     "eventtype",
                                     handler_type=BROADCAST,
                                     reliable_delivery=False).bind(
                                         container, "foobar")
        event_handler.setup()

    assert event_handler.queue.name == (
        "evt-srcservice-eventtype--destservice.foobar-{}".format("uuid-value"))
    assert event_handler.queue.exclusive is True

    # test broadcast handler with custom identifier
    class BroadcastEventHandler(EventHandler):
        broadcast_identifier = "testbox"

    event_handler = BroadcastEventHandler("srcservice",
                                          "eventtype",
                                          handler_type=BROADCAST).bind(
                                              container, "foobar")
    event_handler.setup()

    assert event_handler.queue.name == (
        "evt-srcservice-eventtype--destservice.foobar-{}".format("testbox"))
    assert event_handler.queue.exclusive is False

    # test singleton handler
    event_handler = EventHandler("srcservice",
                                 "eventtype",
                                 handler_type=SINGLETON).bind(
                                     container, "foobar")
    event_handler.setup()

    assert event_handler.queue.name == "evt-srcservice-eventtype"
    assert event_handler.queue.exclusive is False

    # test reliable delivery
    event_handler = EventHandler("srcservice",
                                 "eventtype").bind(container, "foobar")
    event_handler.setup()

    assert event_handler.queue.auto_delete is False
Exemplo n.º 4
0
def test_event_handler(queue_consumer, mock_container):

    container = mock_container
    container.service_name = "destservice"

    # test default configuration
    event_handler = EventHandler("srcservice", "eventtype").bind(container,
                                                                 "foobar")
    event_handler.setup()

    assert event_handler.queue.durable is True
    assert event_handler.queue.routing_key == "eventtype"
    assert event_handler.queue.exchange.name == "srcservice.events"
    queue_consumer.register_provider.assert_called_once_with(event_handler)

    # test service pool handler
    event_handler = EventHandler(
        "srcservice", "eventtype"
    ).bind(
        container, "foobar"
    )
    event_handler.setup()

    assert event_handler.queue.name == (
        "evt-srcservice-eventtype--destservice.foobar")
    assert event_handler.queue.exclusive is False

    # test broadcast handler with default identifier
    with patch('nameko.events.uuid') as mock_uuid:
        mock_uuid.uuid4().hex = "uuid-value"
        event_handler = EventHandler(
            "srcservice", "eventtype",
            handler_type=BROADCAST, reliable_delivery=False
        ).bind(
            container, "foobar"
        )
        event_handler.setup()

    assert event_handler.queue.name == (
        "evt-srcservice-eventtype--destservice.foobar-{}".format("uuid-value"))
    assert event_handler.queue.exclusive is True

    # test broadcast handler with custom identifier
    class BroadcastEventHandler(EventHandler):
        broadcast_identifier = "testbox"

    event_handler = BroadcastEventHandler(
        "srcservice", "eventtype", handler_type=BROADCAST
    ).bind(
        container, "foobar"
    )
    event_handler.setup()

    assert event_handler.queue.name == (
        "evt-srcservice-eventtype--destservice.foobar-{}".format("testbox"))
    assert event_handler.queue.exclusive is False

    # test singleton handler
    event_handler = EventHandler(
        "srcservice", "eventtype", handler_type=SINGLETON
    ).bind(
        container, "foobar"
    )
    event_handler.setup()

    assert event_handler.queue.name == "evt-srcservice-eventtype"
    assert event_handler.queue.exclusive is False

    # test reliable delivery
    event_handler = EventHandler(
        "srcservice", "eventtype"
    ).bind(
        container, "foobar"
    )
    event_handler.setup()

    assert event_handler.queue.auto_delete is False