1+ # flake8: noqa
2+
13import unittest
24
35from ua_parser import user_agent_parser
2527google_bot_ua_string = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
2628nokia_n97_ua_string = 'Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/12.0.024; Profile/MIDP-2.1 Configuration/CLDC-1.1; en-us) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.12344'
2729android_firefox_aurora_ua_string = 'Mozilla/5.0 (Android; Mobile; rv:27.0) Gecko/27.0 Firefox/27.0'
30+ samsung_galaxy_s_ua_string = 'Mozilla/5.0 (Linux; Android 4.4.2; en-us; SAMSUNG SCH-I545 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Mobile Safari/537.36'
31+ playstation_vita_ua_string = 'Mozilla/5.0 (PlayStation Vita 3.12) AppleWebKit/536.26 (KHTML, like Gecko) Silk/3.2'
32+ playstation_ua_string = 'Mozilla/5.0 (PLAYSTATION 3 4.60) AppleWebKit/531.22.8 (KHTML, like Gecko)'
33+ samsung_gt_ua_string = 'Mozilla/5.0 (SAMSUNG; SAMSUNG-GT-S8530/S8530DDLC2; U; Bada/2.0; en-us) AppleWebKit/534.20 (KHTML, like Gecko) Dolfin/3.0 Mobile WVGA SMM-MMS/1.2.0 OPN-B'
34+
2835
2936iphone_ua = parse (iphone_ua_string )
3037ipad_ua = parse (ipad_ua_string )
4754google_bot_ua = parse (google_bot_ua_string )
4855nokia_n97_ua = parse (nokia_n97_ua_string )
4956android_firefox_aurora_ua = parse (android_firefox_aurora_ua_string )
57+ samsung_galaxy_s_ua = parse (samsung_galaxy_s_ua_string )
58+ playstation_vita_ua = parse (playstation_vita_ua_string )
59+ playstation_ua = parse (playstation_ua_string )
60+ samsung_gt_ua = parse (samsung_gt_ua_string )
5061
5162
5263class UserAgentsTest (unittest .TestCase ):
@@ -61,7 +72,7 @@ def test_user_agent_object_assignments(self):
6172 iphone_ua .browser .version ,
6273 (int (ua_dict ['user_agent' ]['major' ]), int (ua_dict ['user_agent' ]['minor' ]))
6374 )
64-
75+
6576 # Ensure os attributes are assigned correctly
6677 self .assertEqual (iphone_ua .os .family , ua_dict ['os' ]['family' ])
6778 self .assertEqual (
@@ -93,6 +104,11 @@ def test_is_tablet_property(self):
93104 self .assertTrue (kindle_fire_ua .is_tablet )
94105 self .assertTrue (nexus_7_ua .is_tablet )
95106 self .assertFalse (android_firefox_aurora_ua .is_tablet )
107+ self .assertFalse (samsung_galaxy_s_ua .is_tablet )
108+ self .assertFalse (playstation_vita_ua .is_tablet )
109+ self .assertFalse (playstation_ua .is_tablet )
110+ self .assertFalse (samsung_gt_ua .is_tablet )
111+
96112
97113 def test_is_mobile_property (self ):
98114 self .assertTrue (iphone_ua .is_mobile )
@@ -114,6 +130,11 @@ def test_is_mobile_property(self):
114130 self .assertFalse (ubuntu_firefox_ua .is_mobile )
115131 self .assertFalse (google_bot_ua .is_mobile )
116132 self .assertTrue (android_firefox_aurora_ua .is_mobile )
133+ self .assertTrue (samsung_galaxy_s_ua .is_mobile )
134+ self .assertTrue (playstation_vita_ua .is_mobile )
135+ self .assertFalse (playstation_ua .is_mobile )
136+ self .assertTrue (samsung_gt_ua .is_mobile )
137+
117138
118139 def test_is_touch_property (self ):
119140 self .assertTrue (iphone_ua .is_touch_capable )
@@ -135,6 +156,11 @@ def test_is_touch_property(self):
135156 self .assertFalse (google_bot_ua .is_touch_capable )
136157 self .assertFalse (nokia_n97_ua .is_touch_capable )
137158 self .assertTrue (android_firefox_aurora_ua .is_touch_capable )
159+ self .assertTrue (samsung_galaxy_s_ua .is_touch_capable )
160+ self .assertFalse (playstation_vita_ua .is_touch_capable )
161+ self .assertFalse (playstation_ua .is_touch_capable )
162+ self .assertFalse (samsung_gt_ua .is_touch_capable )
163+
138164
139165 def test_is_pc (self ):
140166 self .assertFalse (iphone_ua .is_pc )
@@ -145,7 +171,7 @@ def test_is_pc(self):
145171 self .assertFalse (nexus_7_ua .is_pc )
146172 self .assertFalse (windows_phone_ua .is_pc )
147173 self .assertFalse (blackberry_bold_touch_ua .is_pc )
148- self .assertFalse (blackberry_torch_ua .is_pc )
174+ self .assertFalse (blackberry_torch_ua .is_pc )
149175 self .assertFalse (blackberry_bold_ua .is_pc )
150176 self .assertFalse (j2me_opera_ua .is_pc )
151177 self .assertFalse (google_bot_ua .is_pc )
@@ -156,6 +182,11 @@ def test_is_pc(self):
156182 self .assertTrue (ie_touch_ua .is_pc )
157183 self .assertTrue (ie_ua .is_pc )
158184 self .assertFalse (android_firefox_aurora_ua .is_pc )
185+ self .assertFalse (samsung_galaxy_s_ua .is_pc )
186+ self .assertFalse (playstation_vita_ua .is_pc )
187+ self .assertFalse (playstation_ua .is_pc )
188+ self .assertFalse (samsung_gt_ua .is_pc )
189+
159190
160191 def test_is_bot (self ):
161192 self .assertTrue (google_bot_ua .is_bot )
@@ -167,16 +198,21 @@ def test_is_bot(self):
167198 self .assertFalse (nexus_7_ua .is_bot )
168199 self .assertFalse (windows_phone_ua .is_bot )
169200 self .assertFalse (blackberry_bold_touch_ua .is_bot )
170- self .assertFalse (blackberry_torch_ua .is_bot )
201+ self .assertFalse (blackberry_torch_ua .is_bot )
171202 self .assertFalse (blackberry_bold_ua .is_bot )
172- self .assertFalse (j2me_opera_ua .is_bot )
203+ self .assertFalse (j2me_opera_ua .is_bot )
173204 self .assertFalse (mac_safari_ua .is_bot )
174205 self .assertFalse (windows_ie_ua .is_bot )
175206 self .assertFalse (ubuntu_firefox_ua .is_bot )
176207 self .assertFalse (ie_touch_ua .is_bot )
177208 self .assertFalse (ie_ua .is_bot )
178209 self .assertFalse (nokia_n97_ua .is_bot )
179210 self .assertFalse (android_firefox_aurora_ua .is_bot )
211+ self .assertFalse (samsung_galaxy_s_ua .is_bot )
212+ self .assertFalse (playstation_vita_ua .is_bot )
213+ self .assertFalse (playstation_ua .is_bot )
214+ self .assertFalse (samsung_gt_ua .is_bot )
215+
180216
181217 def test_strings (self ):
182218 self .assertEqual (str (iphone_ua ), "iPhone / iOS 5.1 / Mobile Safari 5.1" )
0 commit comments