Skip to content

Commit 689a304

Browse files
authored
Merge pull request #81 from pusher/kill-the-spare
Remove notification validation code
2 parents b9a945f + ff26659 commit 689a304

File tree

6 files changed

+6
-182
lines changed

6 files changed

+6
-182
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#### 1.4.0 2016-08-15
2+
3+
* Add support for sending push notifications.
14

25
#### 1.3.0 2016-05-24
36

pusher/http.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ def make_query_string(params):
4242
return '&'.join(map('='.join, sorted(params.items(), key=lambda x: x[0])))
4343

4444
def process_response(status, body):
45-
if status == 200:
45+
if status == 200 or status == 202:
4646
return json.loads(body)
47-
if status == 202:
48-
return True
4947
elif status == 400:
5048
raise PusherBadRequest(body)
5149
elif status == 401:

pusher/notification_client.py

-45
Original file line numberDiff line numberDiff line change
@@ -41,50 +41,5 @@ def notify(self, interests, notification):
4141
'interests': interests,
4242
}
4343
params.update(notification)
44-
self.validate_notification(params)
4544
path = "/%s/%s/apps/%s/notifications" % (API_PREFIX, API_VERSION, self.app_id)
4645
return Request(self, POST, path, params)
47-
48-
def validate_notification(self, notification):
49-
gcm_payload = notification.get('gcm')
50-
51-
if not gcm_payload and not notification.get('apns') :
52-
raise ValueError("Notification must have fields APNS or GCM")
53-
54-
if gcm_payload:
55-
for restricted_key in RESTRICTED_GCM_KEYS:
56-
gcm_payload.pop(restricted_key, None)
57-
58-
ttl = gcm_payload.get('time_to_live')
59-
if ttl:
60-
if not isinstance(ttl, int):
61-
raise ValueError("GCM time_to_live must be an int")
62-
63-
if not (0 <= ttl <= GCM_TTL):
64-
raise ValueError("GCM time_to_live must be between 0 and 241920 (4 weeks)")
65-
66-
gcm_payload_notification = gcm_payload.get('notification')
67-
if gcm_payload_notification:
68-
title = gcm_payload_notification.get('title')
69-
icon = gcm_payload_notification.get('icon')
70-
if not isinstance(title, str):
71-
raise ValueError("GCM notification title is required must be a string")
72-
73-
if not isinstance(icon, str):
74-
raise ValueError("GCM notification icon is required must be a string")
75-
76-
if len(title) is 0:
77-
raise ValueError("GCM notification title must not be empty")
78-
79-
if len(icon) is 0:
80-
raise ValueError("GCM notification icon must not be empty")
81-
82-
webhook_url = notification.get('webhook_url')
83-
webhook_level = notification.get('webhook_level')
84-
85-
if webhook_level:
86-
if not webhook_url:
87-
raise ValueError("webhook_level cannot be used without a webhook_url")
88-
89-
if not webhook_level in WEBHOOK_LEVELS:
90-
raise ValueError("webhook_level must be either INFO or DEBUG. Blank will default to INFO")

pusher/pusher.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def notification_client(self):
270270
return self._notification_client
271271

272272
def notify(self, interest, notification):
273-
self._notification_client.notify(interest, notification)
273+
return self._notification_client.notify(interest, notification)
274274

275275
def _data_to_string(self, data):
276276
if isinstance(data, six.string_types):

pusher/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Don't change the format of this line: the version is extracted by ../setup.py
2-
VERSION = '1.4rc3'
2+
VERSION = '1.4'

pusher_tests/test_notification_client.py

-132
Original file line numberDiff line numberDiff line change
@@ -51,137 +51,5 @@ def test_notify_supplied_ssl_and_host(self):
5151
request = configured_client.notify.make_request([u'blargh'], self.success_fixture)
5252
self.assertEqual(request.base_url, u'http://foo.bar.io:80')
5353

54-
def test_either_apns_or_gcm_must_be_present(self):
55-
self.assertRaises(ValueError, lambda:
56-
self.client.notify([u'yolo'], {})
57-
)
58-
5954
def test_only_one_interest_sent_to(self):
6055
self.assertRaises(ValueError, lambda: self.client.notify([u'yolo', u'woot'], self.success_fixture))
61-
62-
def test_gcm_restricted_keys_removed(self):
63-
request = self.client.notify.make_request(['yolo'], {
64-
'gcm': {
65-
'to': 'woot',
66-
'registration_ids': ['woot', 'bla'],
67-
'notification': {
68-
'title': 'yipee',
69-
'icon': 'huh'
70-
}
71-
}
72-
})
73-
self.assertEqual(request.params, {
74-
'interests': ['yolo'],
75-
'gcm': {
76-
'notification': {
77-
'title': 'yipee',
78-
'icon': 'huh'
79-
}
80-
}
81-
})
82-
83-
def test_gcm_validations(self):
84-
invalid_gcm_payloads = [
85-
{
86-
'gcm': {
87-
'time_to_live': -1,
88-
'notification': {
89-
'title': 'yipee',
90-
'icon': 'huh'
91-
}
92-
}
93-
},
94-
{
95-
'gcm': {
96-
'time_to_live': 241921,
97-
'notification': {
98-
'title': 'yipee',
99-
'icon': 'huh'
100-
}
101-
}
102-
},
103-
{
104-
'gcm': {
105-
'notification': {
106-
'title': 'yipee',
107-
}
108-
}
109-
},
110-
{
111-
'gcm': {
112-
'notification': {
113-
'icon': 'huh'
114-
}
115-
}
116-
},
117-
{
118-
'gcm': {
119-
'notification': {
120-
'title': '',
121-
'icon': 'huh'
122-
}
123-
}
124-
},
125-
{
126-
'gcm': {
127-
'notification': {
128-
'title': 'yipee',
129-
'icon': ''
130-
}
131-
}
132-
}
133-
]
134-
135-
for payload in invalid_gcm_payloads:
136-
self.assertRaises(ValueError, lambda:
137-
self.client.notify([u'yolo'], payload)
138-
)
139-
140-
valid_gcm_payload = \
141-
{
142-
'gcm': {
143-
'time_to_live': 42,
144-
'notification': {
145-
'title': 'yipee',
146-
'icon': 'huh'
147-
}
148-
}
149-
}
150-
self.client.notify.make_request([u'yolo'], valid_gcm_payload)
151-
152-
def test_webhook_level_validation(self):
153-
invalid_webhook_configs = [
154-
{
155-
'webhook_level': 'DEBUG',
156-
'apns': {
157-
'alert': {
158-
'title': 'yolo',
159-
'body': 'woot'
160-
}
161-
},
162-
'gcm': {
163-
'notification': {
164-
'title': 'yipee',
165-
'icon': 'huh'
166-
}
167-
}
168-
},
169-
{
170-
'webhook_level': 'FOOBAR',
171-
'webhook_url': 'http://webhook.com',
172-
'apns': {
173-
'alert': {
174-
'title': 'yolo',
175-
'body': 'woot'
176-
}
177-
},
178-
'gcm': {
179-
'notification': {
180-
'title': 'yipee',
181-
'icon': 'huh'
182-
}
183-
}
184-
}]
185-
186-
for config in invalid_webhook_configs:
187-
self.assertRaises(ValueError, lambda: self.client.notify.make_request([u'yolo'], config))

0 commit comments

Comments
 (0)