@@ -474,3 +474,97 @@ def test_delete_user_should_fail_if_user_id_too_long(self):
474
474
with self .assertRaises (ValueError ) as e :
475
475
pn_client .delete_user ('A' * 165 )
476
476
self .assertIn ('longer than the maximum of 164 chars' , str (e .exception ))
477
+
478
+ def test_delete_user_should_raise_on_http_4xx_error (self ):
479
+ pn_client = PushNotifications (
480
+ 'INSTANCE_ID' ,
481
+ 'SECRET_KEY'
482
+ )
483
+ with requests_mock .Mocker () as http_mock :
484
+ http_mock .register_uri (
485
+ requests_mock .ANY ,
486
+ requests_mock .ANY ,
487
+ status_code = 400 ,
488
+ json = {'error' : 'Invalid request' , 'description' : 'blah' },
489
+ )
490
+ with self .assertRaises (PusherValidationError ) as e :
491
+ pn_client .delete_user ('user-0001' )
492
+ self .assertIn ('Invalid request: blah' , str (e .exception ))
493
+
494
+ def test_delete_user_should_raise_on_http_5xx_error (self ):
495
+ pn_client = PushNotifications (
496
+ 'INSTANCE_ID' ,
497
+ 'SECRET_KEY'
498
+ )
499
+ with requests_mock .Mocker () as http_mock :
500
+ http_mock .register_uri (
501
+ requests_mock .ANY ,
502
+ requests_mock .ANY ,
503
+ status_code = 500 ,
504
+ json = {'error' : 'Server error' , 'description' : 'blah' },
505
+ )
506
+ with self .assertRaises (PusherServerError ) as e :
507
+ pn_client .delete_user ('user-0001' )
508
+ self .assertIn ('Server error: blah' , str (e .exception ))
509
+
510
+ def test_delete_user_should_raise_on_http_401_error (self ):
511
+ pn_client = PushNotifications (
512
+ 'INSTANCE_ID' ,
513
+ 'SECRET_KEY'
514
+ )
515
+ with requests_mock .Mocker () as http_mock :
516
+ http_mock .register_uri (
517
+ requests_mock .ANY ,
518
+ requests_mock .ANY ,
519
+ status_code = 401 ,
520
+ json = {'error' : 'Auth error' , 'description' : 'blah' },
521
+ )
522
+ with self .assertRaises (PusherAuthError ) as e :
523
+ pn_client .delete_user ('user-0001' )
524
+ self .assertIn ('Auth error: blah' , str (e .exception ))
525
+
526
+ def test_publish_to_users_should_raise_on_http_404_error (self ):
527
+ pn_client = PushNotifications (
528
+ 'INSTANCE_ID' ,
529
+ 'SECRET_KEY'
530
+ )
531
+ with requests_mock .Mocker () as http_mock :
532
+ http_mock .register_uri (
533
+ requests_mock .ANY ,
534
+ requests_mock .ANY ,
535
+ status_code = 404 ,
536
+ json = {'error' : 'Instance not found' , 'description' : 'blah' },
537
+ )
538
+ with self .assertRaises (PusherMissingInstanceError ) as e :
539
+ pn_client .delete_user ('user-0001' )
540
+ self .assertIn ('Instance not found: blah' , str (e .exception ))
541
+
542
+ def test_delete_user_should_error_correctly_if_error_not_json (self ):
543
+ pn_client = PushNotifications (
544
+ 'INSTANCE_ID' ,
545
+ 'SECRET_KEY'
546
+ )
547
+ with requests_mock .Mocker () as http_mock :
548
+ http_mock .register_uri (
549
+ requests_mock .ANY ,
550
+ requests_mock .ANY ,
551
+ status_code = 500 ,
552
+ text = '<notjson></notjson>' ,
553
+ )
554
+ with self .assertRaises (PusherServerError ) as e :
555
+ pn_client .delete_user ('user-0001' )
556
+ self .assertIn ('Unknown error: no description' , str (e .exception ))
557
+
558
+ def test_delete_user_should_not_error_on_not_json_success (self ):
559
+ pn_client = PushNotifications (
560
+ 'INSTANCE_ID' ,
561
+ 'SECRET_KEY'
562
+ )
563
+ with requests_mock .Mocker () as http_mock :
564
+ http_mock .register_uri (
565
+ requests_mock .ANY ,
566
+ requests_mock .ANY ,
567
+ status_code = 200 ,
568
+ text = '<notjson></notjson>' ,
569
+ )
570
+ pn_client .delete_user ('alice' )
0 commit comments