def test_push(self):
        """Test if PushConsumer works properly."""

        with self.app.test_request_context():
            user_hub = EventHub("TestPush", self.celery)
            user_hub_id = user_hub.hub_id
            push_function = PushConsumer(self.backend, user_hub_id)

            # The notifier that push notifications to the client via SSE
            sse_notifier = self.notifications.sse_notifier_for(user_hub_id)

            push_function.consume(self.event_json)

            # Popping subscribe message. Somehow, if the option
            # ignore_subscribe_messages is True, the other messages
            # are not detected.
            propagated_messages = sse_notifier.backend.listen()
            message = next(propagated_messages)

            # Getting expected message and checking it with the sent one
            message = next(propagated_messages)
            assert message['data'].decode("utf-8") == self.event_json
Example #2
0
 def create_hub(self, hub_alias):
     """Create an EventHub to aggregate certain types of events."""
     hub = EventHub(hub_alias, self.celery)
     self._hubs[hub.hub_id] = hub
     return hub
    def setUp(self):
        super(EventHubAndFiltersTest, self).setUp()

        self.event_hub = EventHub("TestFilters", self.celery)
        self.event_hub_id = self.event_hub.hub_id