@@ -22,26 +22,29 @@ def test_constructor_should_accept_valid_params(self):
22
22
)
23
23
24
24
def test_constructor_should_fail_if_instance_id_not_string (self ):
25
- with self .assertRaises (TypeError ):
25
+ with self .assertRaises (TypeError ) as e :
26
26
PushNotifications (
27
27
instance_id = False ,
28
28
secret_key = '1234' ,
29
29
)
30
+ self .assertIn ('instance_id must be a string' , str (e .exception ))
30
31
31
32
def test_constructor_should_fail_if_secret_key_not_string (self ):
32
- with self .assertRaises (TypeError ):
33
+ with self .assertRaises (TypeError ) as e :
33
34
PushNotifications (
34
35
instance_id = '1234' ,
35
36
secret_key = False ,
36
37
)
38
+ self .assertIn ('secret_key must be a string' , str (e .exception ))
37
39
38
40
def test_constructor_should_fail_if_endpoint_not_string (self ):
39
- with self .assertRaises (TypeError ):
41
+ with self .assertRaises (TypeError ) as e :
40
42
PushNotifications (
41
43
instance_id = '1234' ,
42
44
secret_key = '1234' ,
43
45
endpoint = False ,
44
46
)
47
+ self .assertIn ('endpoint must be a string' , str (e .exception ))
45
48
46
49
def test_constructor_should_set_endpoint_default (self ):
47
50
pn_client = PushNotifications (
@@ -136,7 +139,7 @@ def test_publish_should_fail_if_interests_not_list(self):
136
139
'INSTANCE_ID' ,
137
140
'SECRET_KEY'
138
141
)
139
- with self .assertRaises (TypeError ):
142
+ with self .assertRaises (TypeError ) as e :
140
143
pn_client .publish (
141
144
interests = False ,
142
145
publish_body = {
@@ -147,24 +150,26 @@ def test_publish_should_fail_if_interests_not_list(self):
147
150
},
148
151
},
149
152
)
153
+ self .assertIn ('interests must be a list' , str (e .exception ))
150
154
151
155
def test_publish_should_fail_if_body_not_dict (self ):
152
156
pn_client = PushNotifications (
153
157
'INSTANCE_ID' ,
154
158
'SECRET_KEY'
155
159
)
156
- with self .assertRaises (TypeError ):
160
+ with self .assertRaises (TypeError ) as e :
157
161
pn_client .publish (
158
162
interests = ['donuts' ],
159
163
publish_body = False ,
160
164
)
165
+ self .assertIn ('publish_body must be a dictionary' , str (e .exception ))
161
166
162
167
def test_publish_should_fail_if_no_interests_passed (self ):
163
168
pn_client = PushNotifications (
164
169
'INSTANCE_ID' ,
165
170
'SECRET_KEY'
166
171
)
167
- with self .assertRaises (ValueError ):
172
+ with self .assertRaises (ValueError ) as e :
168
173
pn_client .publish (
169
174
interests = [],
170
175
publish_body = {
@@ -175,6 +180,7 @@ def test_publish_should_fail_if_no_interests_passed(self):
175
180
},
176
181
},
177
182
)
183
+ self .assertIn ('must target at least one interest' , str (e .exception ))
178
184
179
185
def test_publish_should_succeed_if_100_interests_passed (self ):
180
186
pn_client = PushNotifications (
@@ -215,7 +221,7 @@ def test_publish_should_fail_if_too_many_interests_passed(self):
215
221
'publishId' : '1234' ,
216
222
},
217
223
)
218
- with self .assertRaises (ValueError ):
224
+ with self .assertRaises (ValueError ) as e :
219
225
pn_client .publish (
220
226
interests = ['interest-' + str (i ) for i in range (0 , 101 )],
221
227
publish_body = {
@@ -226,13 +232,14 @@ def test_publish_should_fail_if_too_many_interests_passed(self):
226
232
},
227
233
},
228
234
)
235
+ self .assertIn ('Number of interests (101) exceeds maximum' , str (e .exception ))
229
236
230
237
def test_publish_should_fail_if_interest_not_a_string (self ):
231
238
pn_client = PushNotifications (
232
239
'INSTANCE_ID' ,
233
240
'SECRET_KEY'
234
241
)
235
- with self .assertRaises (TypeError ):
242
+ with self .assertRaises (TypeError ) as e :
236
243
pn_client .publish (
237
244
interests = [False ],
238
245
publish_body = {
@@ -243,13 +250,14 @@ def test_publish_should_fail_if_interest_not_a_string(self):
243
250
},
244
251
},
245
252
)
253
+ self .assertIn ('Interest False is not a string' , str (e .exception ))
246
254
247
255
def test_publish_should_fail_if_interest_too_long (self ):
248
256
pn_client = PushNotifications (
249
257
'INSTANCE_ID' ,
250
258
'SECRET_KEY'
251
259
)
252
- with self .assertRaises (ValueError ):
260
+ with self .assertRaises (ValueError ) as e :
253
261
pn_client .publish (
254
262
interests = ['A' * 200 ],
255
263
publish_body = {
@@ -260,13 +268,14 @@ def test_publish_should_fail_if_interest_too_long(self):
260
268
},
261
269
},
262
270
)
271
+ self .assertIn ('longer than the maximum of 164 chars' , str (e .exception ))
263
272
264
273
def test_publish_should_fail_if_interest_contains_invalid_chars (self ):
265
274
pn_client = PushNotifications (
266
275
'INSTANCE_ID' ,
267
276
'SECRET_KEY'
268
277
)
269
- with self .assertRaises (ValueError ):
278
+ with self .assertRaises (ValueError ) as e :
270
279
pn_client .publish (
271
280
interests = ['bad|interest' ],
272
281
publish_body = {
@@ -277,7 +286,9 @@ def test_publish_should_fail_if_interest_contains_invalid_chars(self):
277
286
},
278
287
},
279
288
)
280
- with self .assertRaises (ValueError ):
289
+ self .assertIn ('"bad|interest" contains a forbidden character' , str (e .exception ))
290
+
291
+ with self .assertRaises (ValueError ) as e :
281
292
pn_client .publish (
282
293
interests = ['bad(interest)' ],
283
294
publish_body = {
@@ -288,6 +299,7 @@ def test_publish_should_fail_if_interest_contains_invalid_chars(self):
288
299
},
289
300
},
290
301
)
302
+ self .assertIn ('"bad(interest)" contains a forbidden character' , str (e .exception ))
291
303
292
304
def test_publish_should_raise_on_http_4xx_error (self ):
293
305
pn_client = PushNotifications (
@@ -301,7 +313,7 @@ def test_publish_should_raise_on_http_4xx_error(self):
301
313
status_code = 400 ,
302
314
json = {'error' : 'Invalid request' , 'description' : 'blah' },
303
315
)
304
- with self .assertRaises (PusherValidationError ):
316
+ with self .assertRaises (PusherValidationError ) as e :
305
317
pn_client .publish (
306
318
interests = ['donuts' ],
307
319
publish_body = {
@@ -312,6 +324,7 @@ def test_publish_should_raise_on_http_4xx_error(self):
312
324
},
313
325
},
314
326
)
327
+ self .assertIn ('Invalid request: blah' , str (e .exception ))
315
328
316
329
def test_publish_should_raise_on_http_5xx_error (self ):
317
330
pn_client = PushNotifications (
@@ -325,7 +338,7 @@ def test_publish_should_raise_on_http_5xx_error(self):
325
338
status_code = 500 ,
326
339
json = {'error' : 'Server error' , 'description' : 'blah' },
327
340
)
328
- with self .assertRaises (PusherServerError ):
341
+ with self .assertRaises (PusherServerError ) as e :
329
342
pn_client .publish (
330
343
interests = ['donuts' ],
331
344
publish_body = {
@@ -336,6 +349,7 @@ def test_publish_should_raise_on_http_5xx_error(self):
336
349
},
337
350
},
338
351
)
352
+ self .assertIn ('Server error: blah' , str (e .exception ))
339
353
340
354
def test_publish_should_raise_on_http_401_error (self ):
341
355
pn_client = PushNotifications (
@@ -349,7 +363,7 @@ def test_publish_should_raise_on_http_401_error(self):
349
363
status_code = 401 ,
350
364
json = {'error' : 'Auth error' , 'description' : 'blah' },
351
365
)
352
- with self .assertRaises (PusherAuthError ):
366
+ with self .assertRaises (PusherAuthError ) as e :
353
367
pn_client .publish (
354
368
interests = ['donuts' ],
355
369
publish_body = {
@@ -360,6 +374,7 @@ def test_publish_should_raise_on_http_401_error(self):
360
374
},
361
375
},
362
376
)
377
+ self .assertIn ('Auth error: blah' , str (e .exception ))
363
378
364
379
def test_publish_should_raise_on_http_404_error (self ):
365
380
pn_client = PushNotifications (
@@ -373,7 +388,7 @@ def test_publish_should_raise_on_http_404_error(self):
373
388
status_code = 404 ,
374
389
json = {'error' : 'Instance not found' , 'description' : 'blah' },
375
390
)
376
- with self .assertRaises (PusherMissingInstanceError ):
391
+ with self .assertRaises (PusherMissingInstanceError ) as e :
377
392
pn_client .publish (
378
393
interests = ['donuts' ],
379
394
publish_body = {
@@ -384,3 +399,4 @@ def test_publish_should_raise_on_http_404_error(self):
384
399
},
385
400
},
386
401
)
402
+ self .assertIn ('Instance not found: blah' , str (e .exception ))
0 commit comments