66import requests
77import urbanairship as ua
88from tests import TEST_KEY , TEST_SECRET
9- from urbanairship .push . payload import in_app , localization
9+ from urbanairship .enums import LiveActivityEvent , LiveUpdateEvent
1010
1111
1212class TestPush (unittest .TestCase ):
1313 def test_full_payload (self ):
14-
1514 p = ua .Push (None )
1615 p .audience = ua .all_
1716 p .notification = ua .notification (alert = "Hello" )
@@ -547,6 +546,28 @@ def test_ios_overrides(self):
547546 interruption_level = "critical" ,
548547 relevance_score = 0.75 ,
549548 target_content_id = "big day coming" ,
549+ media_attachment = ua .media_attachment (
550+ url = "https://www.testurl.com" ,
551+ content = {
552+ "title" : "Moustache Twirl" ,
553+ "body" : "Have you ever seen a moustache like this?!" ,
554+ },
555+ options = {
556+ "crop" : {"height" : 0.5 , "width" : 0.5 , "x" : 0.25 , "y" : 0.25 },
557+ "time" : 15 ,
558+ },
559+ ),
560+ live_activity = ua .live_activity (
561+ event = LiveActivityEvent .UPDATE ,
562+ alert = {"title" : "test" , "sound" : "test" , "body" : "test" },
563+ name = "test" ,
564+ priority = 5 ,
565+ content_state = {"test" : "test" },
566+ relevance_score = 1.0 ,
567+ stale_date = 1234 ,
568+ dismissal_date = 1234 ,
569+ timestamp = 1234 ,
570+ ),
550571 )
551572 )
552573 p .options = ua .options (10080 )
@@ -570,22 +591,49 @@ def test_ios_overrides(self):
570591 "summary-arg" : "Matmos" ,
571592 "summary-arg-count" : 1 ,
572593 },
594+ "badge" : 3 ,
573595 "sound" : {
574596 "name" : "Amplified Synapse" ,
575597 "volume" : 0.8 ,
576598 "critical" : False ,
577599 },
578- "thread_id" : "plastic minor" ,
579- "priority" : 10 ,
580- "badge" : 3 ,
581600 "extra" : {"office" : "furniture" },
582- "mutable_content" : False ,
583601 "title" : "this is" ,
602+ "mutable_content" : False ,
584603 "subtitle" : "backwards" ,
604+ "media_attachment" : {
605+ "url" : "https://www.testurl.com" ,
606+ "content" : {
607+ "title" : "Moustache Twirl" ,
608+ "body" : "Have you ever seen a moustache like this?!" ,
609+ },
610+ "options" : {
611+ "crop" : {
612+ "height" : 0.5 ,
613+ "width" : 0.5 ,
614+ "x" : 0.25 ,
615+ "y" : 0.25 ,
616+ },
617+ "time" : 15 ,
618+ },
619+ },
620+ "priority" : 10 ,
585621 "collapse_id" : "nugent sand" ,
622+ "thread_id" : "plastic minor" ,
586623 "interruption_level" : "critical" ,
587624 "relevance_score" : 0.75 ,
588625 "target_content_id" : "big day coming" ,
626+ "live_activity" : {
627+ "alert" : {"title" : "test" , "sound" : "test" , "body" : "test" },
628+ "event" : "update" ,
629+ "name" : "test" ,
630+ "priority" : 5 ,
631+ "content_state" : {"test" : "test" },
632+ "relevance_score" : 1.0 ,
633+ "stale_date" : 1234 ,
634+ "dismissal_date" : 1234 ,
635+ "timestamp" : 1234 ,
636+ },
589637 }
590638 },
591639 "device_types" : "ios" ,
@@ -603,7 +651,7 @@ def test_full_scheduled_payload(self):
603651 p = ua .Push (None )
604652 p .audience = ua .all_
605653 p .notification = ua .notification (alert = "Hello" )
606- p .options = ua .options (10080 )
654+ p .options = ua .options (expiry = 10080 )
607655 p .device_types = ua .all_
608656 p .message = ua .message (
609657 title = "Title" ,
@@ -1110,3 +1158,83 @@ def test_localization_raises_no_country_lang(self):
11101158 def testlocalization_raises_no_content (self ):
11111159 with self .assertRaises (ValueError ):
11121160 ua .localization (country = "us" , language = "en" )
1161+
1162+ def test_options_expiry_as_int (self ):
1163+ result = ua .options (expiry = 300 )
1164+ assert result == {"expiry" : 300 }
1165+
1166+ def test_options_expiry_as_string (self ):
1167+ result = ua .options (expiry = "2023-10-19T10:00:00Z" )
1168+ assert result == {"expiry" : "2023-10-19T10:00:00Z" }
1169+
1170+ def test_options_with_multiple_values (self ):
1171+ result = ua .options (
1172+ expiry = "2023-10-19T10:00:00Z" ,
1173+ bypass_frequency_limits = True ,
1174+ bypass_holdout_groups = True ,
1175+ no_throttle = True ,
1176+ omit_from_activity_log = True ,
1177+ personalization = True ,
1178+ redact_payload = True ,
1179+ )
1180+ expected_result = {
1181+ "expiry" : "2023-10-19T10:00:00Z" ,
1182+ "bypass_frequency_limits" : True ,
1183+ "bypass_holdout_groups" : True ,
1184+ "no_throttle" : True ,
1185+ "omit_from_activity_log" : True ,
1186+ "personalization" : True ,
1187+ "redact_payload" : True ,
1188+ }
1189+ assert result == expected_result
1190+
1191+ def test_valid_live_activity (self ):
1192+ result = ua .live_activity (
1193+ event = LiveActivityEvent .UPDATE ,
1194+ name = "TestActivity" ,
1195+ alert = {"body" : "Test body" , "sound" : "default" , "title" : "Test Title" },
1196+ priority = 10 ,
1197+ )
1198+ self .assertIn ("alert" , result )
1199+ self .assertEqual (result ["event" ], "update" )
1200+ self .assertEqual (result ["name" ], "TestActivity" )
1201+ self .assertEqual (result ["priority" ], 10 )
1202+
1203+ def test_invalid_alert (self ):
1204+ with self .assertRaises (ValueError ):
1205+ ua .live_activity (
1206+ event = LiveActivityEvent .UPDATE ,
1207+ name = "TestActivity" ,
1208+ alert = {"other_key" : "test" , "title" : "test" },
1209+ priority = 10 ,
1210+ )
1211+
1212+ def test_missing_name_live_activity (self ):
1213+ with self .assertRaises (ValueError ):
1214+ ua .live_activity (name = None , event = LiveActivityEvent .END , priority = 10 )
1215+
1216+ def test_valid_live_update (self ):
1217+ result = ua .live_update (
1218+ event = LiveUpdateEvent .START ,
1219+ name = "TestUpdate" ,
1220+ content_state = {"key" : "value" },
1221+ )
1222+ self .assertEqual (result ["event" ], "start" )
1223+ self .assertEqual (result ["name" ], "TestUpdate" )
1224+ self .assertIn ("content_state" , result )
1225+
1226+ def test_invalid_content_state (self ):
1227+ with self .assertRaises (TypeError ):
1228+ ua .live_update (
1229+ event = LiveUpdateEvent .UPDATE , name = "TestUpdate" , content_state = "invalid"
1230+ )
1231+ with self .assertRaises (TypeError ):
1232+ ua .live_update (
1233+ event = LiveUpdateEvent .UPDATE ,
1234+ name = "TestUpdate" ,
1235+ content_state = {1 : "test" },
1236+ )
1237+
1238+ def test_missing_name_live_update (self ):
1239+ with self .assertRaises (ValueError ):
1240+ ua .live_update (name = None , event = LiveUpdateEvent .END )
0 commit comments