4
4
5
5
import requests_mock
6
6
7
+
7
8
from pusher_push_notifications import (
8
9
PushNotifications ,
9
10
PusherAuthError ,
@@ -130,22 +131,21 @@ def test_publish_should_make_correct_http_request(self):
130
131
},
131
132
)
132
133
133
-
134
134
def test_publish_should_fail_if_interests_not_list (self ):
135
135
pn_client = PushNotifications (
136
136
'INSTANCE_ID' ,
137
137
'SECRET_KEY'
138
138
)
139
139
with self .assertRaises (TypeError ):
140
140
pn_client .publish (
141
- interests = False ,
142
- publish_body = {
143
- 'apns' : {
144
- 'aps' : {
145
- 'alert' : 'Hello World!' ,
146
- },
141
+ interests = False ,
142
+ publish_body = {
143
+ 'apns' : {
144
+ 'aps' : {
145
+ 'alert' : 'Hello World!' ,
147
146
},
148
147
},
148
+ },
149
149
)
150
150
151
151
def test_publish_should_fail_if_body_not_dict (self ):
@@ -155,8 +155,8 @@ def test_publish_should_fail_if_body_not_dict(self):
155
155
)
156
156
with self .assertRaises (TypeError ):
157
157
pn_client .publish (
158
- interests = ['donuts' ],
159
- publish_body = False ,
158
+ interests = ['donuts' ],
159
+ publish_body = False ,
160
160
)
161
161
162
162
def test_publish_should_fail_if_no_interests_passed (self ):
@@ -166,15 +166,66 @@ def test_publish_should_fail_if_no_interests_passed(self):
166
166
)
167
167
with self .assertRaises (ValueError ):
168
168
pn_client .publish (
169
- interests = [],
169
+ interests = [],
170
+ publish_body = {
171
+ 'apns' : {
172
+ 'aps' : {
173
+ 'alert' : 'Hello World!' ,
174
+ },
175
+ },
176
+ },
177
+ )
178
+
179
+ def test_publish_should_succeed_if_100_interests_passed (self ):
180
+ pn_client = PushNotifications (
181
+ 'INSTANCE_ID' ,
182
+ 'SECRET_KEY'
183
+ )
184
+ with requests_mock .Mocker () as http_mock :
185
+ http_mock .register_uri (
186
+ requests_mock .ANY ,
187
+ requests_mock .ANY ,
188
+ status_code = 200 ,
189
+ json = {
190
+ 'publishId' : '1234' ,
191
+ },
192
+ )
193
+ pn_client .publish (
194
+ interests = ['interest-' + str (i ) for i in range (0 , 100 )],
195
+ publish_body = {
196
+ 'apns' : {
197
+ 'aps' : {
198
+ 'alert' : 'Hello World!' ,
199
+ },
200
+ },
201
+ },
202
+ )
203
+
204
+ def test_publish_should_fail_if_too_many_interests_passed (self ):
205
+ pn_client = PushNotifications (
206
+ 'INSTANCE_ID' ,
207
+ 'SECRET_KEY'
208
+ )
209
+ with requests_mock .Mocker () as http_mock :
210
+ http_mock .register_uri (
211
+ requests_mock .ANY ,
212
+ requests_mock .ANY ,
213
+ status_code = 200 ,
214
+ json = {
215
+ 'publishId' : '1234' ,
216
+ },
217
+ )
218
+ with self .assertRaises (ValueError ):
219
+ pn_client .publish (
220
+ interests = ['interest-' + str (i ) for i in range (0 , 101 )],
170
221
publish_body = {
171
222
'apns' : {
172
223
'aps' : {
173
224
'alert' : 'Hello World!' ,
174
225
},
175
226
},
176
227
},
177
- )
228
+ )
178
229
179
230
def test_publish_should_fail_if_interest_not_a_string (self ):
180
231
pn_client = PushNotifications (
@@ -183,14 +234,14 @@ def test_publish_should_fail_if_interest_not_a_string(self):
183
234
)
184
235
with self .assertRaises (TypeError ):
185
236
pn_client .publish (
186
- interests = [False ],
187
- publish_body = {
188
- 'apns' : {
189
- 'aps' : {
190
- 'alert' : 'Hello World!' ,
191
- },
237
+ interests = [False ],
238
+ publish_body = {
239
+ 'apns' : {
240
+ 'aps' : {
241
+ 'alert' : 'Hello World!' ,
192
242
},
193
243
},
244
+ },
194
245
)
195
246
196
247
def test_publish_should_fail_if_interest_too_long (self ):
@@ -200,14 +251,14 @@ def test_publish_should_fail_if_interest_too_long(self):
200
251
)
201
252
with self .assertRaises (ValueError ):
202
253
pn_client .publish (
203
- interests = ['A' * 200 ],
204
- publish_body = {
205
- 'apns' : {
206
- 'aps' : {
207
- 'alert' : 'Hello World!' ,
208
- },
254
+ interests = ['A' * 200 ],
255
+ publish_body = {
256
+ 'apns' : {
257
+ 'aps' : {
258
+ 'alert' : 'Hello World!' ,
209
259
},
210
260
},
261
+ },
211
262
)
212
263
213
264
def test_publish_should_fail_if_interest_contains_invalid_chars (self ):
@@ -217,25 +268,25 @@ def test_publish_should_fail_if_interest_contains_invalid_chars(self):
217
268
)
218
269
with self .assertRaises (ValueError ):
219
270
pn_client .publish (
220
- interests = ['bad|interest' ],
221
- publish_body = {
222
- 'apns' : {
223
- 'aps' : {
224
- 'alert' : 'Hello World!' ,
225
- },
271
+ interests = ['bad|interest' ],
272
+ publish_body = {
273
+ 'apns' : {
274
+ 'aps' : {
275
+ 'alert' : 'Hello World!' ,
226
276
},
227
277
},
278
+ },
228
279
)
229
280
with self .assertRaises (ValueError ):
230
281
pn_client .publish (
231
- interests = ['bad(interest)' ],
232
- publish_body = {
233
- 'apns' : {
234
- 'aps' : {
235
- 'alert' : 'Hello World!' ,
236
- },
282
+ interests = ['bad(interest)' ],
283
+ publish_body = {
284
+ 'apns' : {
285
+ 'aps' : {
286
+ 'alert' : 'Hello World!' ,
237
287
},
238
288
},
289
+ },
239
290
)
240
291
241
292
def test_publish_should_raise_on_http_4xx_error (self ):
@@ -252,14 +303,14 @@ def test_publish_should_raise_on_http_4xx_error(self):
252
303
)
253
304
with self .assertRaises (PusherValidationError ):
254
305
pn_client .publish (
255
- interests = ['donuts' ],
256
- publish_body = {
257
- 'apns' : {
258
- 'aps' : {
259
- 'alert' : 'Hello World!' ,
260
- },
306
+ interests = ['donuts' ],
307
+ publish_body = {
308
+ 'apns' : {
309
+ 'aps' : {
310
+ 'alert' : 'Hello World!' ,
261
311
},
262
312
},
313
+ },
263
314
)
264
315
265
316
def test_publish_should_raise_on_http_5xx_error (self ):
@@ -276,14 +327,14 @@ def test_publish_should_raise_on_http_5xx_error(self):
276
327
)
277
328
with self .assertRaises (PusherServerError ):
278
329
pn_client .publish (
279
- interests = ['donuts' ],
280
- publish_body = {
281
- 'apns' : {
282
- 'aps' : {
283
- 'alert' : 'Hello World!' ,
284
- },
330
+ interests = ['donuts' ],
331
+ publish_body = {
332
+ 'apns' : {
333
+ 'aps' : {
334
+ 'alert' : 'Hello World!' ,
285
335
},
286
336
},
337
+ },
287
338
)
288
339
289
340
def test_publish_should_raise_on_http_401_error (self ):
@@ -300,14 +351,14 @@ def test_publish_should_raise_on_http_401_error(self):
300
351
)
301
352
with self .assertRaises (PusherAuthError ):
302
353
pn_client .publish (
303
- interests = ['donuts' ],
304
- publish_body = {
305
- 'apns' : {
306
- 'aps' : {
307
- 'alert' : 'Hello World!' ,
308
- },
354
+ interests = ['donuts' ],
355
+ publish_body = {
356
+ 'apns' : {
357
+ 'aps' : {
358
+ 'alert' : 'Hello World!' ,
309
359
},
310
360
},
361
+ },
311
362
)
312
363
313
364
def test_publish_should_raise_on_http_404_error (self ):
@@ -324,12 +375,12 @@ def test_publish_should_raise_on_http_404_error(self):
324
375
)
325
376
with self .assertRaises (PusherMissingInstanceError ):
326
377
pn_client .publish (
327
- interests = ['donuts' ],
328
- publish_body = {
329
- 'apns' : {
330
- 'aps' : {
331
- 'alert' : 'Hello World!' ,
332
- },
378
+ interests = ['donuts' ],
379
+ publish_body = {
380
+ 'apns' : {
381
+ 'aps' : {
382
+ 'alert' : 'Hello World!' ,
333
383
},
334
384
},
385
+ },
335
386
)
0 commit comments