From bf0d6753f7a3a20240886061eaf2332fda905cf9 Mon Sep 17 00:00:00 2001 From: Adam Taylor Date: Wed, 22 May 2024 17:54:38 -0600 Subject: [PATCH] When identifying a macOS or Windows platform, do not include the version --- tests/test_template_filters.py | 68 ++++++++++----------- user_sessions/templatetags/user_sessions.py | 13 ---- 2 files changed, 34 insertions(+), 47 deletions(-) diff --git a/tests/test_template_filters.py b/tests/test_template_filters.py index 7d759a1..4589596 100644 --- a/tests/test_template_filters.py +++ b/tests/test_template_filters.py @@ -49,21 +49,21 @@ def test_locations(self): class PlatformTemplateFilterTest(TestCase): def test_windows(self): # Generic Windows - self.assertEqual("Windows XP", platform("NT 5.1 not a real browser/10.3")) - self.assertEqual("Windows Vista", platform("NT 6.0 not a real browser/10.3")) - self.assertEqual("Windows 7", platform("NT 6.1 not a real browser/10.3")) - self.assertEqual("Windows 8", platform("NT 6.2 not a real browser/10.3")) - self.assertEqual("Windows 8.1", platform("NT 6.3 not a real browser/10.3")) + self.assertEqual("Windows", platform("Windows NT 5.1 not a real browser/10.3")) + self.assertEqual("Windows", platform("Windows NT 6.0 not a real browser/10.3")) + self.assertEqual("Windows", platform("Windows NT 6.1 not a real browser/10.3")) + self.assertEqual("Windows", platform("Windows NT 6.2 not a real browser/10.3")) + self.assertEqual("Windows", platform("Windows NT 6.3 not a real browser/10.3")) self.assertEqual("Windows", platform("Windows not a real browser/10.3")) # IE self.assertEqual( - 'Windows XP', + 'Windows', platform('Mozilla/4.0 (Windows; MSIE 6.0; Windows NT 5.1; SV1; ' '.NET CLR 2.0.50727)') ) self.assertEqual( - 'Windows Vista', + 'Windows', platform('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; ' 'Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322;' ' InfoPath.2; .NET CLR 3.5.21022; .NET CLR 3.5.30729; ' @@ -71,24 +71,24 @@ def test_windows(self): ' .NET CLR 3.0.30729)') ) self.assertEqual( - 'Windows 7', + 'Windows', platform('Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; ' 'Trident/6.0)') ) self.assertEqual( - 'Windows 8', + 'Windows', platform('Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ' 'Win64; x64; Trident/6.0)') ) self.assertEqual( - 'Windows 8.1', + 'Windows', platform('Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; ' '.NET4.0E; .NET4.0C; rv:11.0) like Gecko') ) # Edge self.assertEqual( - 'Windows 10', + 'Windows', platform('Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, ' 'like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10136') ) @@ -101,7 +101,7 @@ def test_windows(self): # Edge Chromium self.assertEqual( - 'Windows 10', + 'Windows', platform('Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 ' 'Safari/537.36 Edg/81.0.416.62') @@ -109,14 +109,14 @@ def test_windows(self): # Firefox self.assertEqual( - 'Windows 7', + 'Windows', platform('Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:22.0) ' 'Gecko/20130328 Firefox/22.0') ) # Chrome self.assertEqual( - 'Windows 8.1', + 'Windows', platform('Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (' 'KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36') ) @@ -143,13 +143,13 @@ def test_apple(self): ) self.assertEqual( - 'macOS Mojave', + 'macOS', platform('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) ' 'AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/85.0.4178.0 Safari/537.36') ) self.assertEqual( - 'macOS Catalina', + 'macOS', platform('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:77.0) ' 'Gecko/20100101 Firefox/77.0') ) @@ -162,7 +162,7 @@ def test_apple(self): # Edge Chromium self.assertEqual( - 'macOS Catalina', + 'macOS', platform('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) ' 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 ' 'Safari/537.36 Edg/85.0.564.51') @@ -319,12 +319,12 @@ def test_android(self): class DeviceTemplateFilterTest(TestCase): def test_ie(self): self.assertEqual( - 'Internet Explorer on Windows XP', + 'Internet Explorer on Windows', device('Mozilla/4.0 (Windows; MSIE 6.0; Windows NT 5.1; SV1; ' '.NET CLR 2.0.50727)') ) self.assertEqual( - 'Internet Explorer on Windows Vista', + 'Internet Explorer on Windows', device('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; ' 'Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322;' ' InfoPath.2; .NET CLR 3.5.21022; .NET CLR 3.5.30729; ' @@ -332,17 +332,17 @@ def test_ie(self): ' .NET CLR 3.0.30729)') ) self.assertEqual( - 'Internet Explorer on Windows 7', + 'Internet Explorer on Windows', device('Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; ' 'Trident/6.0)') ) self.assertEqual( - 'Internet Explorer on Windows 8', + 'Internet Explorer on Windows', device('Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ' 'Win64; x64; Trident/6.0)') ) self.assertEqual( - 'Internet Explorer on Windows 8.1', + 'Internet Explorer on Windows', device('Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; ' '.NET4.0E; .NET4.0C; rv:11.0) like Gecko') ) @@ -361,13 +361,13 @@ def test_apple(self): 'Mobile/11A465 Safari/9537.53') ) self.assertEqual( - 'Chrome on macOS Mojave', + 'Chrome on macOS', device('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) ' 'AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/85.0.4178.0 Safari/537.36') ) self.assertEqual( - 'Firefox on macOS Catalina', + 'Firefox on macOS', device('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:77.0) ' 'Gecko/20100101 Firefox/77.0') ) @@ -389,21 +389,21 @@ def test_android(self): def test_firefox(self): self.assertEqual( - 'Firefox on Windows 7', + 'Firefox on Windows', device('Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:22.0) ' 'Gecko/20130328 Firefox/22.0') ) def test_chrome(self): self.assertEqual( - 'Chrome on Windows 8.1', + 'Chrome on Windows', device('Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (' 'KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36') ) def test_edge(self): self.assertEqual( - 'Edge on Windows 10', + 'Edge on Windows', device('Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, ' 'like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10136') ) @@ -416,13 +416,13 @@ def test_edge(self): def test_edge_chromium(self): self.assertEqual( - 'Edge on Windows 10', + 'Edge on Windows', device('Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 ' 'Safari/537.36 Edg/81.0.416.62') ) self.assertEqual( - 'Edge on macOS Catalina', + 'Edge on macOS', device('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) ' 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 ' 'Safari/537.36 Edg/85.0.564.51') @@ -453,19 +453,19 @@ def test_iphone_only(self): self.assertEqual("iPhone", device("iPhone not a real browser/10.3")) def test_windowsxp_only(self): - self.assertEqual("Windows XP", device("NT 5.1 not a real browser/10.3")) + self.assertEqual("Windows", device("Windows NT 5.1 not a real browser/10.3")) def test_windowsvista_only(self): - self.assertEqual("Windows Vista", device("NT 6.0 not a real browser/10.3")) + self.assertEqual("Windows", device("Windows NT 6.0 not a real browser/10.3")) def test_windows7_only(self): - self.assertEqual("Windows 7", device("NT 6.1 not a real browser/10.3")) + self.assertEqual("Windows", device("Windows NT 6.1 not a real browser/10.3")) def test_windows8_only(self): - self.assertEqual("Windows 8", device("NT 6.2 not a real browser/10.3")) + self.assertEqual("Windows", device("Windows NT 6.2 not a real browser/10.3")) def test_windows81_only(self): - self.assertEqual("Windows 8.1", device("NT 6.3 not a real browser/10.3")) + self.assertEqual("Windows", device("Windows NT 6.3 not a real browser/10.3")) def test_windows_only(self): self.assertEqual("Windows", device("Windows not a real browser/10.3")) diff --git a/user_sessions/templatetags/user_sessions.py b/user_sessions/templatetags/user_sessions.py index ead560e..a7b5249 100644 --- a/user_sessions/templatetags/user_sessions.py +++ b/user_sessions/templatetags/user_sessions.py @@ -21,20 +21,7 @@ (re.compile('Linux'), _('Linux')), (re.compile('iPhone'), _('iPhone')), (re.compile('iPad'), _('iPad')), - (re.compile('Mac OS X 10[._]9'), _('OS X Mavericks')), - (re.compile('Mac OS X 10[._]10'), _('OS X Yosemite')), - (re.compile('Mac OS X 10[._]11'), _('OS X El Capitan')), - (re.compile('Mac OS X 10[._]12'), _('macOS Sierra')), - (re.compile('Mac OS X 10[._]13'), _('macOS High Sierra')), - (re.compile('Mac OS X 10[._]14'), _('macOS Mojave')), - (re.compile('Mac OS X 10[._]15'), _('macOS Catalina')), (re.compile('Mac OS X'), _('macOS')), - (re.compile('NT 5.1'), _('Windows XP')), - (re.compile('NT 6.0'), _('Windows Vista')), - (re.compile('NT 6.1'), _('Windows 7')), - (re.compile('NT 6.2'), _('Windows 8')), - (re.compile('NT 6.3'), _('Windows 8.1')), - (re.compile('NT 10.0'), _('Windows 10')), (re.compile('Windows'), _('Windows')), )