Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
CURRENT_APP_OUTPUT = "com.amazon.tv.launcher"
RUNNING_APPS_OUTPUT = """u0_a18 316 197 1189204 115000 ffffffff 00000000 S com.netflix.ninja
u0_a2 15121 197 998628 24628 ffffffff 00000000 S com.amazon.device.controllermanager"""
RUNNING_APPS_LIST = ['com.netflix.ninja', 'com.amazon.device.controllermanager']
GET_PROPERTIES_OUTPUT1 = ""
GET_PROPERTIES_DICT1 = {'screen_on': False,
'awake': False,
'wake_lock_size': -1,
'current_app': None,
'media_session_state': None,
'running_apps': None}
STATE1 = (constants.STATE_OFF, None, None)
GET_PROPERTIES_OUTPUT2 = "1"
GET_PROPERTIES_DICT2 = {'screen_on': True,
'awake': False,
'wake_lock_size': -1,
'current_app': None,
'media_session_state': None,
'running_apps': None}
STATE2 = (constants.STATE_STANDBY, None, None)
GET_PROPERTIES_OUTPUT3 = """11Wake Locks: size=2
com.amazon.tv.launcher
u0_a2 17243 197 998628 24932 ffffffff 00000000 S com.amazon.device.controllermanager
u0_a2 17374 197 995368 20764 ffffffff 00000000 S com.amazon.device.controllermanager:BluetoothReceiver"""
GET_PROPERTIES_DICT3 = {'screen_on': True,
(constants.STATE_PLAYING, constants.APP_PLEX, [constants.APP_PLEX], 'hmdi_arc', False, 0.5))
self.assertUpdate([True, True, constants.STATE_IDLE, 7, constants.APP_PLEX, 3, 'hmdi_arc', False, 30, None],
(constants.STATE_PLAYING, constants.APP_PLEX, [constants.APP_PLEX], 'hmdi_arc', False, 0.5))
self.assertUpdate([True, True, constants.STATE_IDLE, 1, constants.APP_PLEX, 3, 'hmdi_arc', False, 30, None],
(constants.STATE_PAUSED, constants.APP_PLEX, [constants.APP_PLEX], 'hmdi_arc', False, 0.5))
# TVheadend
self.assertUpdate([True, True, constants.STATE_IDLE, 5, constants.APP_TVHEADEND, 4, 'hmdi_arc', False, 30, None],
(constants.STATE_PAUSED, constants.APP_TVHEADEND, [constants.APP_TVHEADEND], 'hmdi_arc', False, 0.5))
self.assertUpdate([True, True, constants.STATE_IDLE, 6, constants.APP_TVHEADEND, 4, 'hmdi_arc', False, 30, None],
(constants.STATE_PLAYING, constants.APP_TVHEADEND, [constants.APP_TVHEADEND], 'hmdi_arc', False, 0.5))
self.assertUpdate([True, True, constants.STATE_IDLE, 1, constants.APP_TVHEADEND, 4, 'hmdi_arc', False, 30, None],
(constants.STATE_IDLE, constants.APP_TVHEADEND, [constants.APP_TVHEADEND], 'hmdi_arc', False, 0.5))
# VLC
self.assertUpdate([True, True, constants.STATE_IDLE, 6, constants.APP_VLC, 2, 'hmdi_arc', False, 30, None],
(constants.STATE_PAUSED, constants.APP_VLC, [constants.APP_VLC], 'hmdi_arc', False, 0.5))
self.assertUpdate([True, True, constants.STATE_IDLE, 6, constants.APP_VLC, 3, 'hmdi_arc', False, 30, None],
(constants.STATE_PLAYING, constants.APP_VLC, [constants.APP_VLC], 'hmdi_arc', False, 0.5))
self.assertUpdate([True, True, constants.STATE_IDLE, 6, constants.APP_VLC, 4, 'hmdi_arc', False, 30, None],
(constants.STATE_IDLE, constants.APP_VLC, [constants.APP_VLC], 'hmdi_arc', False, 0.5))
# VRV
self.assertUpdate([True, True, constants.STATE_IDLE, 2, constants.APP_VRV, 3, 'hmdi_arc', False, 30, None],
(constants.STATE_IDLE, constants.APP_VRV, [constants.APP_VRV], 'hmdi_arc', False, 0.5))
def test_adb_command(self):
"""Test sending a command via the `androidtv.adb_command` service."""
patch_key = "server"
command = "test command"
response = "test response"
with patchers.patch_connect(True)[patch_key], patchers.patch_shell("")[patch_key]:
aftv = setup(
"HOST", 5555, adb_server_ip="ADB_SERVER_IP", device_class="androidtv"
)
self.aftv = AndroidTVDevice(aftv, "Fake Android TV", {}, True, None, None)
with patch("androidtv.basetv.basetv_sync.BaseTVSync.adb_shell", return_value=response) as patch_shell:
self.aftv.adb_command(command)
patch_shell.assert_called_with(command)
assert self.aftv._adb_response == response
def setUp(self):
"""Set up a `FireTVDevice` media player."""
with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell("")[self.PATCH_KEY]:
aftv = setup(
"HOST", 5555, adb_server_ip="ADB_SERVER_IP", device_class="firetv"
)
self.aftv = FireTVDevice(aftv, "Fake Fire TV", {}, True, None, None)
def test_update_lock_not_acquired(self):
"""Test that the state does not get updated when a `LockNotAcquiredException` is raised."""
patch_key = "server"
with patchers.patch_connect(True)[patch_key], patchers.patch_shell("")[patch_key]:
aftv = setup(
"HOST", 5555, adb_server_ip="ADB_SERVER_IP", device_class="androidtv"
)
self.aftv = AndroidTVDevice(aftv, "Fake Android TV", {}, True, None, None)
with patchers.patch_shell("")[patch_key]:
self.aftv.update()
assert self.aftv.state == STATE_OFF
with patch("androidtv.androidtv.androidtv_sync.AndroidTVSync.update", side_effect=LockNotAcquiredException):
with patchers.patch_shell("1")[patch_key]:
self.aftv.update()
assert self.aftv.state == STATE_OFF
with patchers.patch_shell("1")[patch_key]:
self.aftv.update()
assert self.aftv.state == STATE_STANDBY
def setUp(self):
"""Set up a `FireTVDevice` media player."""
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell("")[self.PATCH_KEY]:
aftv = setup("HOST", 5555, device_class="firetv")
self.aftv = FireTVDevice(aftv, "Fake Fire TV", {}, True, None, None)
def test_adb_command_key(self):
"""Test sending a key command via the `androidtv.adb_command` service."""
patch_key = "server"
command = "HOME"
response = None
with patchers.patch_connect(True)[patch_key], patchers.patch_shell("")[patch_key]:
aftv = setup(
"HOST", 5555, adb_server_ip="ADB_SERVER_IP", device_class="androidtv"
)
self.aftv = AndroidTVDevice(aftv, "Fake Android TV", {}, True, None, None)
with patch("androidtv.basetv.basetv_sync.BaseTVSync.adb_shell", return_value=response) as patch_shell:
self.aftv.adb_command(command)
patch_shell.assert_called_with("input keyevent {}".format(self.aftv._keys[command]))
assert self.aftv._adb_response is None
def test_setup(self):
"""Test that the ``setup`` function works correctly.
"""
with self.assertRaises(ValueError):
setup('HOST', 5555, device_class='INVALID')
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
ftv = setup('HOST', 5555)
self.assertIsInstance(ftv, FireTVSync)
self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]:
atv = setup('HOST', 5555)
self.assertIsInstance(atv, AndroidTVSync)
self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
ftv = setup('HOST', 5555, device_class='androidtv')
self.assertIsInstance(ftv, AndroidTVSync)
self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]:
atv = setup('HOST', 5555, device_class='firetv')
self.assertIsInstance(atv, FireTVSync)
self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)
def test_setup(self):
"""Test that the ``setup`` function works correctly.
"""
with self.assertRaises(ValueError):
setup('HOST', 5555, device_class='INVALID')
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
ftv = setup('HOST', 5555)
self.assertIsInstance(ftv, FireTVSync)
self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]:
atv = setup('HOST', 5555)
self.assertIsInstance(atv, AndroidTVSync)
self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
ftv = setup('HOST', 5555, device_class='androidtv')
self.assertIsInstance(ftv, AndroidTVSync)
self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)
"""
with self.assertRaises(ValueError):
setup('HOST', 5555, device_class='INVALID')
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
ftv = setup('HOST', 5555)
self.assertIsInstance(ftv, FireTVSync)
self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]:
atv = setup('HOST', 5555)
self.assertIsInstance(atv, AndroidTVSync)
self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
ftv = setup('HOST', 5555, device_class='androidtv')
self.assertIsInstance(ftv, AndroidTVSync)
self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]:
atv = setup('HOST', 5555, device_class='firetv')
self.assertIsInstance(atv, FireTVSync)
self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)