32
32
NON_DICT_ARGS = ['' , list (), tuple (), True , False , 1 , 0 , {1 : 'foo' }, {'foo' : 1 }]
33
33
NON_OBJECT_ARGS = [list (), tuple (), dict (), 'foo' , 0 , 1 , True , False ]
34
34
NON_LIST_ARGS = ['' , tuple (), dict (), True , False , 1 , 0 , [1 ], ['foo' , 1 ]]
35
+ NON_UNUM_ARGS = ['1.23s' , list (), tuple (), dict (), - 1.23 ]
35
36
HTTP_ERROR_CODES = {
36
37
400 : exceptions .InvalidArgumentError ,
37
38
403 : exceptions .PermissionDeniedError ,
@@ -292,7 +293,7 @@ def test_invalid_priority(self, data):
292
293
else :
293
294
assert str (excinfo .value ) == 'AndroidConfig.priority must be a non-empty string.'
294
295
295
- @pytest .mark .parametrize ('data' , [ '1.23s' , list (), tuple (), dict (), - 1.23 ] )
296
+ @pytest .mark .parametrize ('data' , NON_UNUM_ARGS )
296
297
def test_invalid_ttl (self , data ):
297
298
with pytest .raises (ValueError ) as excinfo :
298
299
check_encoding (messaging .Message (
@@ -479,60 +480,51 @@ def test_invalid_channel_id(self, data):
479
480
excinfo = self ._check_notification (notification )
480
481
assert str (excinfo .value ) == 'AndroidNotification.channel_id must be a string.'
481
482
482
- @pytest .mark .parametrize ('data ' , NON_STRING_ARGS )
483
- def test_invalid_event_timestamp (self , data ):
484
- notification = messaging .AndroidNotification (event_timestamp = data )
483
+ @pytest .mark .parametrize ('timestamp ' , [ 100 , '' , 'foo' , {}, [], list (), dict ()] )
484
+ def test_invalid_event_timestamp (self , timestamp ):
485
+ notification = messaging .AndroidNotification (event_timestamp = timestamp )
485
486
excinfo = self ._check_notification (notification )
486
487
expected = 'AndroidNotification.event_timestamp must be a datetime.'
487
488
assert str (excinfo .value ) == expected
488
489
489
- @pytest .mark .parametrize ('data ' , NON_STRING_ARGS + ['' , 'topic' , 'priority' , 'foo' ])
490
- def test_invalid_priority (self , data ):
491
- notification = messaging .AndroidNotification (priority = data )
490
+ @pytest .mark .parametrize ('priority ' , NON_STRING_ARGS + ['foo' ])
491
+ def test_invalid_priority (self , priority ):
492
+ notification = messaging .AndroidNotification (priority = priority )
492
493
excinfo = self ._check_notification (notification )
493
- if isinstance (data , six .string_types ):
494
- if not data :
494
+ if isinstance (priority , six .string_types ):
495
+ if not priority :
495
496
expected = 'AndroidNotification.priority must be a non-empty string.'
496
497
else :
497
498
expected = ('AndroidNotification.priority must be "default", "min", "low", "high" '
498
499
'or "max".' )
499
- assert str (excinfo .value ) == expected
500
500
else :
501
501
expected = 'AndroidNotification.priority must be a non-empty string.'
502
- assert str (excinfo .value ) == expected
502
+ assert str (excinfo .value ) == expected
503
503
504
- @pytest .mark .parametrize ('data ' , NON_STRING_ARGS + ['' , 'topic' , 'priority' , 'foo' ])
505
- def test_invalid_visibility (self , data ):
506
- notification = messaging .AndroidNotification (visibility = data )
504
+ @pytest .mark .parametrize ('visibility ' , NON_STRING_ARGS + ['' , 'topic' , 'priority' , 'foo' ])
505
+ def test_invalid_visibility (self , visibility ):
506
+ notification = messaging .AndroidNotification (visibility = visibility )
507
507
excinfo = self ._check_notification (notification )
508
- if isinstance (data , six .string_types ):
509
- if not data :
508
+ if isinstance (visibility , six .string_types ):
509
+ if not visibility :
510
510
expected = 'AndroidNotification.visibility must be a non-empty string.'
511
511
else :
512
512
expected = ('AndroidNotification.visibility must be "private", "public" or'
513
513
' "secret".' )
514
- assert str (excinfo .value ) == expected
515
514
else :
516
515
expected = 'AndroidNotification.visibility must be a non-empty string.'
517
- assert str (excinfo .value ) == expected
516
+ assert str (excinfo .value ) == expected
518
517
519
- @pytest .mark .parametrize ('data ' , ['' , 1 , True , 'msec' , ['500' , 500 ], [0 , 'abc' ]])
520
- def test_invalid_vibrate_timings_millis (self , data ):
521
- notification = messaging .AndroidNotification (vibrate_timings_millis = data )
518
+ @pytest .mark .parametrize ('vibrate_timings ' , ['' , 1 , True , 'msec' , ['500' , 500 ], [0 , 'abc' ]])
519
+ def test_invalid_vibrate_timings_millis (self , vibrate_timings ):
520
+ notification = messaging .AndroidNotification (vibrate_timings_millis = vibrate_timings )
522
521
excinfo = self ._check_notification (notification )
523
- if isinstance (data , list ):
522
+ if isinstance (vibrate_timings , list ):
524
523
expected = ('AndroidNotification.vibrate_timings_millis must not contain non-number '
525
524
'values.' )
526
- assert str (excinfo .value ) == expected
527
525
else :
528
526
expected = 'AndroidNotification.vibrate_timings_millis must be a list of numbers.'
529
- assert str (excinfo .value ) == expected
530
-
531
- @pytest .mark .parametrize ('data' , ['' , 'foo' , list (), tuple (), dict ()])
532
- def test_invalid_notification_count (self , data ):
533
- notification = messaging .AndroidNotification (notification_count = data )
534
- excinfo = self ._check_notification (notification )
535
- assert str (excinfo .value ) == 'AndroidNotification.notification_count must be a number.'
527
+ assert str (excinfo .value ) == expected
536
528
537
529
def test_negative_vibrate_timings_millis (self ):
538
530
notification = messaging .AndroidNotification (
@@ -541,6 +533,12 @@ def test_negative_vibrate_timings_millis(self):
541
533
expected = 'AndroidNotification.vibrate_timings_millis must not be negative.'
542
534
assert str (excinfo .value ) == expected
543
535
536
+ @pytest .mark .parametrize ('notification_count' , ['' , 'foo' , list (), tuple (), dict ()])
537
+ def test_invalid_notification_count (self , notification_count ):
538
+ notification = messaging .AndroidNotification (notification_count = notification_count )
539
+ excinfo = self ._check_notification (notification )
540
+ assert str (excinfo .value ) == 'AndroidNotification.notification_count must be a number.'
541
+
544
542
def test_android_notification (self ):
545
543
msg = messaging .Message (
546
544
topic = 'topic' ,
@@ -628,27 +626,27 @@ def test_invalid_light_settings(self, data):
628
626
assert str (excinfo .value ) == expected
629
627
630
628
def test_no_color (self ):
631
- light_settings = messaging .LightSettings (light_on_duration_millis = 200 ,
629
+ light_settings = messaging .LightSettings (color = None , light_on_duration_millis = 200 ,
632
630
light_off_duration_millis = 200 )
633
631
excinfo = self ._check_light_settings (light_settings )
634
632
expected = 'LightSettings.color is required.'
635
633
assert str (excinfo .value ) == expected
636
634
637
635
def test_no_light_on_duration_millis (self ):
638
- light_settings = messaging .LightSettings (color = '#aabbcc' ,
636
+ light_settings = messaging .LightSettings (color = '#aabbcc' , light_on_duration_millis = None ,
639
637
light_off_duration_millis = 200 )
640
638
excinfo = self ._check_light_settings (light_settings )
641
639
expected = 'LightSettings.light_on_duration_millis is required.'
642
640
assert str (excinfo .value ) == expected
643
641
644
642
def test_no_light_off_duration_millis (self ):
645
- light_settings = messaging .LightSettings (color = '#aabbcc' ,
646
- light_on_duration_millis = 200 )
643
+ light_settings = messaging .LightSettings (color = '#aabbcc' , light_on_duration_millis = 200 ,
644
+ light_off_duration_millis = None )
647
645
excinfo = self ._check_light_settings (light_settings )
648
646
expected = 'LightSettings.light_off_duration_millis is required.'
649
647
assert str (excinfo .value ) == expected
650
648
651
- @pytest .mark .parametrize ('data' , [ '1.23s' , list (), tuple (), dict (), - 1.23 ] )
649
+ @pytest .mark .parametrize ('data' , NON_UNUM_ARGS )
652
650
def test_invalid_light_off_duration_millis (self , data ):
653
651
light_settings = messaging .LightSettings (color = '#aabbcc' ,
654
652
light_on_duration_millis = 200 ,
@@ -662,7 +660,7 @@ def test_invalid_light_off_duration_millis(self, data):
662
660
'duration in milliseconds or '
663
661
'an instance of datetime.timedelta.' )
664
662
665
- @pytest .mark .parametrize ('data' , [ '1.23s' , list (), tuple (), dict (), - 1.23 ] )
663
+ @pytest .mark .parametrize ('data' , NON_UNUM_ARGS )
666
664
def test_invalid_light_on_duration_millis (self , data ):
667
665
light_settings = messaging .LightSettings (color = '#aabbcc' ,
668
666
light_on_duration_millis = data ,
0 commit comments