-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the setup function (#85)
* Add tests for the setup function * 'Value error' -> 'ValueError' * Add missing quotes * 'DEVICE_PROPERTIES_DICT2' -> 'DEVICE_PROPERTIES_DICT1'
- Loading branch information
1 parent
7c7c4c4
commit 1b48c27
Showing
1 changed file
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import sys | ||
import unittest | ||
|
||
try: | ||
# Python3 | ||
from unittest.mock import patch | ||
except ImportError: | ||
# Python2 | ||
from mock import patch | ||
|
||
|
||
sys.path.insert(0, '..') | ||
|
||
from androidtv import constants, ha_state_detection_rules_validator, setup | ||
from androidtv.androidtv import AndroidTV | ||
from androidtv.firetv import FireTV | ||
from . import patchers | ||
|
||
|
||
DEVICE_PROPERTIES_OUTPUT1 = """Amazon | ||
AFTT | ||
SERIALNO | ||
5.1.1 | ||
link/ether ab:cd:ef:gh:ij:kl brd ff:ff:ff:ff:ff:ff | ||
Device "eth0" does not exist. | ||
""" | ||
|
||
DEVICE_PROPERTIES_DICT1 = {'manufacturer': 'Amazon', | ||
'model': 'AFTT', | ||
'serialno': 'SERIALNO', | ||
'sw_version': '5.1.1', | ||
'wifimac': 'ab:cd:ef:gh:ij:kl', | ||
'ethmac': None} | ||
|
||
DEVICE_PROPERTIES_OUTPUT2 = """Not Amazon | ||
AFTT | ||
SERIALNO | ||
5.1.1 | ||
Device "wlan0" does not exist. | ||
link/ether ab:cd:ef:gh:ij:kl brd ff:ff:ff:ff:ff:ff | ||
""" | ||
|
||
DEVICE_PROPERTIES_DICT2 = {'manufacturer': 'Not Amazon', | ||
'model': 'AFTT', | ||
'serialno': 'SERIALNO', | ||
'sw_version': '5.1.1', | ||
'wifimac': None, | ||
'ethmac': 'ab:cd:ef:gh:ij:kl'} | ||
|
||
|
||
class TestSetup(unittest.TestCase): | ||
PATCH_KEY = 'python' | ||
|
||
def test_setup(self): | ||
"""Test that the ``setup`` function works correctly. | ||
""" | ||
with self.assertRaises(ValueError): | ||
setup('IP:PORT', device_class='INVALID') | ||
|
||
with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]: | ||
ftv = setup('IP:PORT') | ||
self.assertIsInstance(ftv, FireTV) | ||
self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1) | ||
|
||
with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]: | ||
atv = setup('IP:PORT') | ||
self.assertIsInstance(atv, AndroidTV) | ||
self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |