コード例 #1
0
 def test_subscribe_queue(self):
     # LongPollApplicationRequestSubscriber.subscribe() creates a new queue
     # with a new unique name that is bound to the event's event_key.
     request = LaunchpadTestRequest()
     event = FakeEvent()
     subscriber = ILongPollSubscriber(request)
     subscriber.subscribe(event)
     message = '{"hello": 1234}'
     session = getUtility(IMessageSession)
     routing_key = session.getProducer(event.event_key)
     routing_key.send(message)
     session.flush()
     subscribe_queue = session.getConsumer(subscriber.subscribe_key)
     self.assertEqual(message, subscribe_queue.receive(timeout=5))
コード例 #2
0
 def test_subscribe_queue(self):
     # LongPollApplicationRequestSubscriber.subscribe() creates a new queue
     # with a new unique name that is bound to the event's event_key.
     request = LaunchpadTestRequest()
     event = FakeEvent()
     subscriber = ILongPollSubscriber(request)
     subscriber.subscribe(event)
     message = '{"hello": 1234}'
     session = getUtility(IMessageSession)
     routing_key = session.getProducer(event.event_key)
     routing_key.send(message)
     session.flush()
     subscribe_queue = session.getConsumer(subscriber.subscribe_key)
     self.assertEqual(
         message, subscribe_queue.receive(timeout=5))
コード例 #3
0
def subscribe(target, event_name=u"", request=None):
    """Convenience method to subscribe the current request.

    :param target: Something that can be adapted to `ILongPollEvent`.
    :param event_name: The name of the event to subscribe to. This is used to
        look up a named adapter from `target` to `ILongPollEvent`.
    :param request: The request for which to get an `ILongPollSubscriber`. It
        a request is not specified the currently active request is used.
    :return: The `ILongPollEvent` that has been subscribed to.
    """
    event = getAdapter(target, ILongPollEvent, name=event_name)
    if request is None:
        request = get_current_browser_request()
    subscriber = ILongPollSubscriber(request)
    subscriber.subscribe(event)
    return event
コード例 #4
0
def subscribe(target, event_name=u"", request=None):
    """Convenience method to subscribe the current request.

    :param target: Something that can be adapted to `ILongPollEvent`.
    :param event_name: The name of the event to subscribe to. This is used to
        look up a named adapter from `target` to `ILongPollEvent`.
    :param request: The request for which to get an `ILongPollSubscriber`. It
        a request is not specified the currently active request is used.
    :return: The `ILongPollEvent` that has been subscribed to.
    """
    event = getAdapter(target, ILongPollEvent, name=event_name)
    if request is None:
        request = get_current_browser_request()
    subscriber = ILongPollSubscriber(request)
    subscriber.subscribe(event)
    return event