def test_emit(self): # emit() gets the ILongPollEvent for the given target and passes the # given data to its emit() method. It then returns the event. an_object = FakeObject(12345) with ZopeAdapterFixture(FakeEvent): event = emit(an_object) session = getUtility(IMessageSession) producer = session.getProducer(event.event_key) subscribe_queue = session.getConsumer("whatever") producer.associateConsumerNow(subscribe_queue) # Emit the event again; the subscribe queue was not associated # with the event before now. event_data = {"8765": 4321} event = emit(an_object, **event_data) message = subscribe_queue.receive(timeout=5) self.assertEqual(event_data, message)
def test_emit_named_event(self): # When an event_name is given to emit(), a named adapter is used to # get the ILongPollEvent for the given target. an_object = FakeObject(12345) with ZopeAdapterFixture(FakeEvent, name="foo"): event = emit(an_object, "foo") self.assertIsInstance(event, FakeEvent)