66import requests
77import urbanairship as ua
88from tests import TEST_KEY , TEST_SECRET
9+ from urbanairship .push .payload import in_app , localization
910
1011
1112class TestPush (unittest .TestCase ):
1213 def test_full_payload (self ):
14+
1315 p = ua .Push (None )
1416 p .audience = ua .all_
1517 p .notification = ua .notification (alert = "Hello" )
@@ -26,6 +28,11 @@ def test_full_payload(self):
2628 icons = {"list_icon" : "http://cdn.example.com/message.png" },
2729 options = {"some_delivery_option" : "true" },
2830 )
31+ p .localizations = [
32+ ua .localization (
33+ country = "us" , language = "es" , notification = ua .notification (alert = "Hola" )
34+ )
35+ ]
2936 self .assertEqual (
3037 p .payload ,
3138 {
@@ -44,6 +51,13 @@ def test_full_payload(self):
4451 "icons" : {"list_icon" : "http://cdn.example.com/message.png" },
4552 "options" : {"some_delivery_option" : "true" },
4653 },
54+ "localizations" : [
55+ {
56+ "language" : "es" ,
57+ "country" : "us" ,
58+ "notification" : {"alert" : "Hola" },
59+ }
60+ ],
4761 },
4862 )
4963
@@ -1066,3 +1080,33 @@ def test_standard_amazon_push(self):
10661080 },
10671081 },
10681082 )
1083+
1084+ def test_localization (self ):
1085+ localization = ua .localization (
1086+ country = "fr" ,
1087+ language = "fr" ,
1088+ notification = ua .notification (alert = "bonjour" ),
1089+ in_app = ua .in_app (alert = "bonjour" , display_type = "banner" ),
1090+ message = ua .message (title = "bonjour" , body = "<html><h1>Bonjour!</h1></html>" ),
1091+ )
1092+ self .assertEqual (
1093+ localization ,
1094+ {
1095+ "country" : "fr" ,
1096+ "language" : "fr" ,
1097+ "notification" : {"alert" : "bonjour" },
1098+ "in_app" : {"alert" : "bonjour" , "display_type" : "banner" },
1099+ "message" : {
1100+ "title" : "bonjour" ,
1101+ "body" : "<html><h1>Bonjour!</h1></html>" ,
1102+ },
1103+ },
1104+ )
1105+
1106+ def test_localization_raises_no_country_lang (self ):
1107+ with self .assertRaises (ValueError ):
1108+ ua .localization (notification = ua .notification (alert = "oops" ))
1109+
1110+ def testlocalization_raises_no_content (self ):
1111+ with self .assertRaises (ValueError ):
1112+ ua .localization (country = "us" , language = "en" )
0 commit comments