def send_notification(users, notification): populate_name_cache([notification]) contents = notification.get_contents() new_notification = Notification(ONESIGNAL_APP_ID, Notification.DEVICES_MODE) # set target new_notification.include_player_ids = get_player_ids(users) new_notification.contents = contents try: # Sends it! result = onesignal_client.create_notification(new_notification) print(result) except HTTPError as e: handle_error(e, ERROR_CODE.SEND_NOTIFICATION_ERROR)
def test_notification_instantiation(self, app_id): n = Notification(app_id, Notification.DEVICES_MODE) assert n.app_id == app_id assert n.mode == Notification.DEVICES_MODE
# It should return just one User instance. event.users.all() | event.signers.all() event.users.values_list('onesignal_id') list(Event.objects.all().values_list('users__onesignal_id', flat=True)) ############################################################################## from requests.exceptions import HTTPError from onesignalclient.app_client import OneSignalAppClient from onesignalclient.notification import Notification from django.conf import settings client = OneSignalAppClient(app_id=settings.ONE_SIGNAL_APPID, app_api_key=settings.ONE_SIGNAL_API_KEY) notification = Notification(settings.ONE_SIGNAL_APPID, Notification.DEVICES_MODE) notification.include_player_ids = ['d09804ed-e996-43b7-a7f4-578738c57cc1'] notification dir(notification) notification.get_payload_for_request() client.create_notification(notification) notification = Notification(settings.ONE_SIGNAL_APPID, Notification.DEVICES_MODE) notification.include_player_ids = ['*****@*****.**'] notification client.create_notification(notification) client.get_headers() ##############################################################################
def segment_notification(app_id): return Notification(app_id, Notification.SEGMENTS_MODE)
def sample_notification(app_id): notification = Notification(app_id) return notification
def device_notification(app_id, player_ids_list): notification = Notification(app_id, Notification.DEVICES_MODE) notification.include_player_ids = player_ids_list return notification
def test_notification_instantiation(self, app_id): n = Notification(app_id) assert n.mode == Notification.SEGMENTS_MODE
def test_notification_with_unknown_mode(self, app_id): with pytest.raises(ValueError): Notification(app_id, 'unknown')