-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test cached properties and add str/repr methods
Fixes #26
- Loading branch information
1 parent
b07f6b5
commit b5b1c58
Showing
4 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from ..base import ParserBaseTest | ||
from ...device_detector import DeviceDetector | ||
|
||
|
||
class TestCache(ParserBaseTest): | ||
""" | ||
Values should remain the same on multiple runs when | ||
the parsing on followup runs pulls from cached values. | ||
""" | ||
|
||
def test_is_bot(self): | ||
ua = "Mozilla/5.0 (compatible; CloudFlare-AlwaysOnline/1.0; +http://www.cloudflare.com/always-online) AppleWebKit/534.34" | ||
|
||
first_run = DeviceDetector(ua).parse() | ||
self.assertTrue(first_run.is_bot()) | ||
|
||
second_run = DeviceDetector(ua).parse() | ||
self.assertTrue(second_run.is_bot()) | ||
|
||
def test_device(self): | ||
ua = "Mozilla/5.0 (Linux; U; Android 2.3.3; ja-jp; COOLPIX S800c Build/CP01_WW) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1" | ||
|
||
first_run = DeviceDetector(ua).parse() | ||
self.assertEqual(first_run.device_type(), 'camera') | ||
self.assertEqual(first_run.device_brand(), 'NN') | ||
self.assertEqual(first_run.device_brand_name(), 'Nikon') | ||
|
||
second_run = DeviceDetector(ua).parse() | ||
self.assertEqual(second_run.device_type(), 'camera') | ||
self.assertEqual(second_run.device_brand(), 'NN') | ||
self.assertEqual(second_run.device_brand_name(), 'Nikon') | ||
|
||
def test_client(self): | ||
ua = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Safari/537.36" | ||
|
||
first_run = DeviceDetector(ua).parse() | ||
self.assertEqual(first_run.client_name(), 'Chrome') | ||
self.assertEqual(first_run.client_short_name(), 'CH') | ||
self.assertEqual(first_run.client_version(), '80.0.3987.162') | ||
|
||
second_run = DeviceDetector(ua).parse() | ||
self.assertEqual(second_run.client_name(), 'Chrome') | ||
self.assertEqual(second_run.client_short_name(), 'CH') | ||
self.assertEqual(second_run.client_version(), '80.0.3987.162') | ||
|
||
def test_os(self): | ||
ua = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0" | ||
|
||
first_run = DeviceDetector(ua).parse() | ||
self.assertEqual(first_run.os_name(), 'Ubuntu') | ||
self.assertEqual(first_run.os_short_name(), 'UBT') | ||
|
||
second_run = DeviceDetector(ua).parse() | ||
self.assertEqual(second_run.os_name(), 'Ubuntu') | ||
self.assertEqual(second_run.os_short_name(), 'UBT') | ||
|
||
|
||
__all__ = [ | ||
'TestCache', | ||
] |