예제 #1
0
    def test_filter(self):
        with make_client(endpoint=endpoint, appkey=appkey) as client:
            ch = make_channel_name('filter')
            so = SubscriptionObserver()
            mode = SubscriptionMode.RELIABLE
            args = {'filter': 'select test from ' + ch}
            client.subscribe(ch, mode, so, args=args)
            so.wait_subscribed()

            sync_publish(client, ch, {'test': 42, 'unused': 1})
            message = so.wait_for_channel_data()['messages'][0]
            self.assertEqual(message, {'test': 42})

            sync_publish(client, ch, {'unused': 1})
            message = so.wait_for_channel_data()['messages'][0]
            self.assertEqual(message, {'test': None})
 def test_before_start(self):
     client = Client(endpoint=endpoint, appkey=appkey)
     co = ClientObserver()
     client.observer = co
     so = SubscriptionObserver()
     client.subscribe(channel,
                      SubscriptionMode.ADVANCED,
                      subscription_observer=so)
     client.start()
     co.wait_connected()
     sync_publish(client, channel, 'message')
     channel_data = so.wait_for_channel_data()
     self.assertEqual(channel_data['messages'], ['message'])
     client.stop()
     co.wait_stopped()