File: test_gcm_push_payload.py

package info (click to toggle)
python-django-push-notifications 1.6.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 352 kB
  • sloc: python: 2,694; makefile: 4
file content (74 lines) | stat: -rw-r--r-- 3,247 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from __future__ import absolute_import
from django.test import TestCase
from push_notifications.gcm import send_bulk_message, send_message
from ._mock import mock
from .responses import GCM_JSON, GCM_JSON_MULTIPLE


class GCMPushPayloadTest(TestCase):

	def test_fcm_push_payload(self):
		with mock.patch("push_notifications.gcm._fcm_send", return_value=GCM_JSON) as p:
			send_message("abc", {"message": "Hello world"}, "FCM")
			p.assert_called_once_with(
				b'{"notification":{"body":"Hello world"},"registration_ids":["abc"]}',
				"application/json", application_id=None)

	def test_push_payload_with_app_id(self):
		with mock.patch("push_notifications.gcm._gcm_send", return_value=GCM_JSON) as p:
			send_message("abc", {"message": "Hello world"}, "GCM")
			p.assert_called_once_with(
				b'{"data":{"message":"Hello world"},"registration_ids":["abc"]}',
				"application/json", application_id=None)
		with mock.patch("push_notifications.gcm._gcm_send", return_value=GCM_JSON) as p:
			send_message("abc", {"message": "Hello world"}, "GCM")
			p.assert_called_once_with(
				b'{"data":{"message":"Hello world"},"registration_ids":["abc"]}',
				"application/json", application_id=None)

	def test_fcm_push_payload_params(self):
		with mock.patch("push_notifications.gcm._fcm_send", return_value=GCM_JSON) as p:
			send_message(
				"abc",
				{"message": "Hello world", "title": "Push notification", "other": "misc"},
				"FCM",
				delay_while_idle=True, time_to_live=3600, foo="bar",
			)
			p.assert_called_once_with(
				b'{"data":{"other":"misc"},"delay_while_idle":true,'
				b'"notification":{"body":"Hello world","title":"Push notification"},'
				b'"registration_ids":["abc"],"time_to_live":3600}',
				"application/json", application_id=None)

	def test_fcm_push_payload_many(self):
		with mock.patch("push_notifications.gcm._fcm_send", return_value=GCM_JSON_MULTIPLE) as p:
			send_bulk_message(["abc", "123"], {"message": "Hello world"}, "FCM")
			p.assert_called_once_with(
				b'{"notification":{"body":"Hello world"},"registration_ids":["abc","123"]}',
				"application/json", application_id=None)

	def test_gcm_push_payload(self):
		with mock.patch("push_notifications.gcm._gcm_send", return_value=GCM_JSON) as p:
			send_message("abc", {"message": "Hello world"}, "GCM")
			p.assert_called_once_with(
				b'{"data":{"message":"Hello world"},"registration_ids":["abc"]}',
				"application/json", application_id=None)

	def test_gcm_push_payload_params(self):
		with mock.patch("push_notifications.gcm._gcm_send", return_value=GCM_JSON) as p:
			send_message(
				"abc", {"message": "Hello world"}, "GCM",
				delay_while_idle=True, time_to_live=3600, foo="bar",
			)
			p.assert_called_once_with(
				b'{"data":{"message":"Hello world"},"delay_while_idle":true,'
				b'"registration_ids":["abc"],"time_to_live":3600}',
				"application/json", application_id=None)

	def test_gcm_push_payload_many(self):
		with mock.patch("push_notifications.gcm._gcm_send", return_value=GCM_JSON_MULTIPLE) as p:
			send_bulk_message(["abc", "123"], {"message": "Hello world"}, "GCM")
			p.assert_called_once_with(
				b'{"data":{"message":"Hello world"},"registration_ids":["abc","123"]}',
				"application/json",
				application_id=None)