Exemplo n.º 1
0
 def test_subscribe_to_named_event(self):
     # When an event_name is given to subscribe(), a named adapter is used
     # to get the ILongPollEvent for the given target.
     request = LaunchpadTestRequest()
     an_object = FakeObject(12345)
     with ZopeAdapterFixture(FakeEvent, name="foo"):
         event = subscribe(an_object, event_name="foo", request=request)
     self.assertIsInstance(event, FakeEvent)
Exemplo n.º 2
0
 def test_subscribe_to_named_event(self):
     # When an event_name is given to subscribe(), a named adapter is used
     # to get the ILongPollEvent for the given target.
     request = LaunchpadTestRequest()
     an_object = FakeObject(12345)
     with ZopeAdapterFixture(FakeEvent, name="foo"):
         event = subscribe(an_object, event_name="foo", request=request)
     self.assertIsInstance(event, FakeEvent)
Exemplo n.º 3
0
 def test_subscribe(self):
     # subscribe() gets the ILongPollEvent for the given target and the
     # ILongPollSubscriber for the given request (or the current request is
     # discovered). It subscribes the latter to the event, then returns the
     # event.
     session = getUtility(IMessageSession)
     request = LaunchpadTestRequest()
     an_object = FakeObject(12345)
     with ZopeAdapterFixture(FakeEvent):
         event = subscribe(an_object, request=request)
     self.assertIsInstance(event, FakeEvent)
     self.assertEqual("event-key-12345", event.event_key)
     session.flush()
     # Emitting an event-key-12345 event will put something on the
     # subscriber's queue.
     event_data = {"1234": 5678}
     event.emit(**event_data)
     subscriber = ILongPollSubscriber(request)
     subscribe_queue = session.getConsumer(subscriber.subscribe_key)
     message = subscribe_queue.receive(timeout=5)
     self.assertEqual(event_data, message)
Exemplo n.º 4
0
 def test_subscribe(self):
     # subscribe() gets the ILongPollEvent for the given target and the
     # ILongPollSubscriber for the given request (or the current request is
     # discovered). It subscribes the latter to the event, then returns the
     # event.
     session = getUtility(IMessageSession)
     request = LaunchpadTestRequest()
     an_object = FakeObject(12345)
     with ZopeAdapterFixture(FakeEvent):
         event = subscribe(an_object, request=request)
     self.assertIsInstance(event, FakeEvent)
     self.assertEqual("event-key-12345", event.event_key)
     session.flush()
     # Emitting an event-key-12345 event will put something on the
     # subscriber's queue.
     event_data = {"1234": 5678}
     event.emit(**event_data)
     subscriber = ILongPollSubscriber(request)
     subscribe_queue = session.getConsumer(subscriber.subscribe_key)
     message = subscribe_queue.receive(timeout=5)
     self.assertEqual(event_data, message)