예제 #1
0
    def test_notifications(self):
        f = uaconnect.Filter()
        f.notifications(push_id='1234')
        self.assertEqual(f.filters['notifications'], {'push_id': '1234'})

        f.notifications(group_id='1234')
        self.assertEqual(f.filters['notifications'], {'group_id': '1234'})
예제 #2
0
    def test_device_type(self):
        f = uaconnect.Filter()
        f.device_types('ios')
        self.assertEqual(f.filters['device_types'], ['ios'])

        f.device_types('ios', 'android', 'amazon')
        self.assertEqual(f.filters['device_types'], ['ios', 'android', 'amazon'])
예제 #3
0
    def test_invalid_event_type(self):
        f = uaconnect.Filter()

        self.assertRaises(ValueError, f.types)

        # Invalid event type does not raise value error, as this list is more
        # likely to change.
        f.types('FUTURE_EVENT')
예제 #4
0
    def test_event_type(self):
        f = uaconnect.Filter()
        f.types('OPEN')
        self.assertEqual(f.filters['types'], ['OPEN'])

        f.types('OPEN', 'CLOSE')
        self.assertEqual(f.filters['types'], ['OPEN', 'CLOSE'])

        f.types('open')
        self.assertEqual(f.filters['types'], ['OPEN'])
예제 #5
0
    def test_devices(self):
        f = uaconnect.Filter()

        f.devices(ios_channel='1234')
        self.assertEqual(f.filters['devices'], [{'ios_channel': '1234'}])

        f.devices(android_channel=['1234', '5678'])
        self.assertEqual(f.filters['devices'],
            [{'android_channel': '1234'}, {'android_channel': '5678'}])

        f.devices(amazon_channel='1234', named_user_id='fred')
        self.assertEqual(f.filters['devices'],
            [{'amazon_channel': '1234'}, {'named_user_id': 'fred'}])
def consume(key, token, types):
    redisconn = redis.StrictRedis()
    consumer = uaconnect.Consumer(key, token, redisrecorder.RedisRecorder('uaconnect-offset'))
    if types:
        f = uaconnect.Filter()
        f.types(*types.split(','))
        consumer.add_filter(f)
    consumer.connect()

    def shutdown_handler(signum, frame):
        print("Shutting down", file=sys.stderr)
        consumer.stop()
    signal.signal(signal.SIGINT, shutdown_handler)

    for event in consumer.read():
        if event is None:
            continue
        redisconn.lpush("uaconnect-events", event.raw)
        consumer.ack(event)
예제 #7
0
    def test_invalid_device_type(self):
        f = uaconnect.Filter()

        self.assertRaises(ValueError, f.device_types, 'ios', 'foobar')
        self.assertRaises(ValueError, f.device_types)
        self.assertRaises(ValueError, f.device_types, 'blackberry')
예제 #8
0
 def test_invalid_devices(self):
     f = uaconnect.Filter()
     self.assertRaises(ValueError, f.devices)
예제 #9
0
 def test_invalid_notifications(self):
     f = uaconnect.Filter()
     self.assertRaises(ValueError, f.notifications)
     self.assertRaises(ValueError, f.notifications, push_id='1234', group_id='5678')
예제 #10
0
 def test_latency(self):
     f = uaconnect.Filter()
     f.latency(10000)
     self.assertEqual(f.filters['latency'], 10000)