def simulator( device_id, app_id, title, body, expiration, immediately, topic, collapse_id, apns_id, verbose, ): target = Simulator(device_id, app_id,) logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO) context = Context( token="cli", target=target, expiration=expiration, priority=config.Priority.immediately if immediately else config.Priority.normal, topic=topic, collapse_id=collapse_id, apns_id=apns_id, verbose=verbose, ) try: notification = models.Notification(alert=models.Alert(title=title, body=body)) send(context, notification) except Exception: logging.exception("Simple notification")
def test_full(): notification = models.Notification( alert=models.Alert( title=models.Localized("Test", ["foo", "bar"]), body=models.Localized("Content", ["hoge"]), action_loc_key="action", launch_image="my/image.png", ), badge=13, sound="sounds/alert.mp3", content_available=True, category="my-category", thread_id="thread-id", extra={"myapp": {"is": "awesome"}}, ) assert notification.get_dict() == { "aps": { "alert": { "title-loc-key": "Test", "title-loc-args": ["foo", "bar"], "loc-key": "Content", "loc-args": ["hoge"], "action-loc-key": "action", "launch-image": "my/image.png", }, "badge": 13, "sound": "sounds/alert.mp3", "content-available": 1, "category": "my-category", "thread-id": "thread-id", }, "myapp": {"is": "awesome"}, }
def test_localize(): notification = models.Notification( alert=models.Alert( title=models.Localized("Test", ["foo", "bar"]), body=models.Localized("Content"), ) ) assert notification.get_dict() == { "aps": { "alert": { "title-loc-key": "Test", "title-loc-args": ["foo", "bar"], "loc-key": "Content", } } }
def server( title, body, token, client_cert_path, server, alt_port, expiration, immediately, topic, collapse_id, apns_id, verbose, ): target = Server( client_cert_path, ORIGINS[server], config.ALT_PORT if alt_port else config.DEFAULT_PORT, ) if server == "local": target = replace(target, ca_file="tests/functional/test-server-certificate.pem") logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO) context = Context( token=token, target=target, expiration=expiration, priority=config.Priority.immediately if immediately else config.Priority.normal, topic=topic, collapse_id=collapse_id, apns_id=apns_id, verbose=verbose, ) try: notification = models.Notification(alert=models.Alert(title=title, body=body)) send(context, notification) except Exception: logging.exception("Simple notification")
def test_encode(): notification = models.Notification(alert=models.Alert(title="Test", body="Content")) assert ( notification.encode() == b'{"aps":{"alert":{"body":"Content","title":"Test"}}}' )