def make_tags(self, val): if isinstance(val, list): return ua.and_(*[self.make_tags(v) for v in val]) elif isinstance(val, dict): if 'or' in val: return ua.or_(*[self.make_tags(v) for v in val['or']]) elif 'and' in val: return ua.and_(*[self.make_tags(v) for v in val['and']]) else: return ua.tag(val)
def test_compound_selectors(self): self.assertEqual( ua.or_( ua.tag('foo'), ua.tag('bar') ), {'or': [ {'tag': 'foo'}, {'tag': 'bar'} ]} ) self.assertEqual( ua.and_( ua.tag('foo'), ua.tag('bar') ), { 'and': [ {'tag': 'foo'}, {'tag': 'bar'} ] } ) self.assertEqual( ua.not_( ua.tag('foo') ), { 'not': { 'tag': 'foo' } } )
def push_notification(devices: list, title: str, message: str, extra: dict): push = airship.create_push() push.device_types = ua.device_types(*DeviceType.choices_list()) channels = [ua.android_channel(device.channel_id) for device in devices if device.device_type == 'android'] + \ [ua.ios_channel(device.channel_id) for device in devices if device.device_type == 'ios'] if len(channels) == 0: return push.audience = ua.and_(*channels) push.notification = ua.notification( alert=message, android=ua.android(alert=message, title=title, extra={'payload': json.dumps(extra)}), ios=ua.ios(alert=message, title=title, extra={'payload': json.dumps(extra)})) # print(push.payload) response = push.send() print(response.ok) return response
def test_compound_selectors(self): self.assertEqual(ua.or_(ua.tag("foo"), ua.tag("bar")), {"or": [{"tag": "foo"}, {"tag": "bar"}]}) self.assertEqual(ua.and_(ua.tag("foo"), ua.tag("bar")), {"and": [{"tag": "foo"}, {"tag": "bar"}]}) self.assertEqual(ua.not_(ua.tag("foo")), {"not": {"tag": "foo"}})