def test_payload_should_not_contain_unused_notification_fields(self): notif = APNSNotification(device_token=self.device_token, alert="foobar") import json payload = json.loads(notif.get_payload()) self.assertNotIn("badge", payload["aps"]) self.assertNotIn("sound", payload["aps"])
def test_compose_message(self): notif = APNSNotification(device_token=self.device_token, alert="foobar", badge=1, sound="default") import struct command, identifier, expiry, token_len, token, payload_len, payload = struct.unpack( "!BIIH32sH%ds" % len(notif.get_payload()), str(notif) ) self.assertEquals(command, 1) self.assertEquals(identifier, 0) self.assertTrue(expiry > 0) self.assertEquals(token_len, 32) self.assertEquals(payload_len, len(notif.get_payload())) self.assertEquals(payload, notif.get_payload())
def handleNotify(self, command): log.msg("handleNotify: " + str(command)) for deviceToken, accountId in self.database.findRegistrations(command.args['dovecot-username'], command.args['dovecot-mailbox']): self.notificationService.queueNotification(APNSNotification(deviceToken, {"aps":{"account-id":accountId}})) return ("OK", "")