def test_push_payload(self): with mock.patch("push_notifications.gcm._gcm_send", return_value=GCM_PLAIN_RESPONSE) as p: gcm_send_message("abc", {"message": "Hello world"}) p.assert_called_once_with( b"data.message=Hello+world®istration_id=abc", "application/x-www-form-urlencoded;charset=UTF-8", None)
def test_push_payload(self): with mock.patch("push_notifications.gcm._gcm_send", return_value=GCM_PLAIN_RESPONSE) as p: gcm_send_message("abc", {"message": "Hello world"}) p.assert_called_once_with( b"data.message=Hello+world®istration_id=abc", "application/x-www-form-urlencoded;charset=UTF-8")
def test_push_payload_params(self): with mock.patch("push_notifications.gcm._gcm_send", return_value=GCM_PLAIN_RESPONSE) as p: gcm_send_message("abc", {"message": "Hello world"}, delay_while_idle=True, time_to_live=3600) p.assert_called_once_with( b"data.message=Hello+world&delay_while_idle=1®istration_id=abc&time_to_live=3600", "application/x-www-form-urlencoded;charset=UTF-8", None)
def test_push_payload_params(self): with mock.patch("push_notifications.gcm._gcm_send", return_value=GCM_PLAIN_RESPONSE) as p: gcm_send_message("abc", {"message": "Hello world"}, delay_while_idle=True, time_to_live=3600) p.assert_called_once_with( b"data.message=Hello+world&delay_while_idle=1®istration_id=abc&time_to_live=3600", "application/x-www-form-urlencoded;charset=UTF-8")
def test_push_nested_payload(self): with mock.patch("push_notifications.gcm._gcm_send") as p: payload = { "message": "Hello world", "extra": { "key0": ["value0_0", "value0_1", "value0_2"], "key1": "value1", "key2": {"key2_0": "value2_0"}, }, } payload_string = json.dumps(payload, separators=(",", ":")).encode("utf-8") gcm_send_message("abc", payload) p.assert_called_once_with('{"data":%s,"registration_ids":["abc"]}' % payload_string, "application/json")
def test_push_nested_payload(self): with mock.patch("push_notifications.gcm._gcm_send", return_value=GCM_JSON_RESPONSE) as p: payload = { "message": "Hello world", "extra": { "key0": ["value0_0", "value0_1", "value0_2"], "key1": "value1", "key2": {"key2_0": "value2_0"} } } payload_string = json.dumps(payload, separators=(",", ":"), sort_keys=True).encode("utf-8") gcm_send_message("abc", payload) p.assert_called_once_with( b'{"data":' + payload_string + b',"registration_ids":["abc"]}', "application/json")
def _send_gcm(registration_ids, message, **kwargs): ''' Send a message to one or more GCM recipients :param registration_ids: a single or iterable collection of registraion ids (GCM tokens) :param message: the payload to send. This is sent as the value of the 'message' GCM key, itself within the 'extra' key. :param kwargs: additional GCM arguments. Currently inserted directly into the payload ''' data = kwargs.pop("extra", {}) if message is not None: data["message"] = message if isinstance(registration_ids, collections.Iterable): gcm_send_bulk_message(registration_ids, data, **kwargs) else: gcm_send_message(registration_ids, data, **kwargs)
def send_gcm(registration_ids, message, **kwargs): ''' Send a message to one or more GCM recipients :param registration_ids: a single or iterable collection of registraion ids (GCM tokens) :param message: the payload to send. This is sent as the value of the 'message' GCM key, itself within the 'extra' key. :param kwargs: additional GCM arguments. Currently inserted directly into the payload ''' data = kwargs.pop("extra", {}) if message is not None: data["message"] = message if isinstance(registration_ids, collections.Iterable): gcm_send_bulk_message(registration_ids, data, **kwargs) else: gcm_send_message(registration_ids, data, **kwargs)
def test_push_payload(self): with mock.patch("push_notifications.gcm._gcm_send") as p: gcm_send_message("abc", {"message": "Hello world"}) p.assert_called_once_with( b"registration_id=abc&data.message=Hello+world", "application/x-www-form-urlencoded;charset=UTF-8")
def send_message(self, message, **kwargs): from .gcm import gcm_send_message data = kwargs.pop("extra", {}) if message is not None: data["message"] = message return gcm_send_message(registration_id=self.registration_id, data=data, **kwargs)