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'})
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'])
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')
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'])
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)
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')
def test_invalid_devices(self): f = uaconnect.Filter() self.assertRaises(ValueError, f.devices)
def test_invalid_notifications(self): f = uaconnect.Filter() self.assertRaises(ValueError, f.notifications) self.assertRaises(ValueError, f.notifications, push_id='1234', group_id='5678')
def test_latency(self): f = uaconnect.Filter() f.latency(10000) self.assertEqual(f.filters['latency'], 10000)