Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 44 additions & 12 deletions tests/components/media_player/test_samsungtv.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@
}


class PackageException(Exception):
class AccessDenied(Exception):
"""Dummy Exception."""


class ConnectionClosed(Exception):
"""Dummy Exception."""


class UnhandledResponse(Exception):
"""Dummy Exception."""


Expand All @@ -45,9 +53,9 @@ def setUp(self, samsung_mock, wol_mock):
self.hass.block_till_done()
self.device = SamsungTVDevice(**WORKING_CONFIG)
self.device._exceptions_class = mock.Mock()
self.device._exceptions_class.UnhandledResponse = PackageException
self.device._exceptions_class.AccessDenied = PackageException
self.device._exceptions_class.ConnectionClosed = PackageException
self.device._exceptions_class.UnhandledResponse = UnhandledResponse
self.device._exceptions_class.AccessDenied = AccessDenied
self.device._exceptions_class.ConnectionClosed = ConnectionClosed

def tearDown(self):
"""Tear down test data."""
Expand Down Expand Up @@ -123,22 +131,46 @@ def test_send_key(self):
def test_send_key_broken_pipe(self):
"""Testing broken pipe Exception."""
_remote = mock.Mock()
self.device.get_remote = mock.Mock()
_remote.control = mock.Mock(
side_effect=BrokenPipeError("Boom"))
self.device.get_remote.return_value = _remote
self.device.send_key("HELLO")
side_effect=BrokenPipeError('Boom'))
self.device.get_remote = mock.Mock(return_value=_remote)
self.device.send_key('HELLO')
self.assertIsNone(self.device._remote)
self.assertEqual(STATE_ON, self.device._state)

def test_send_key_connection_closed_retry_succeed(self):
"""Test retry on connection closed."""
_remote = mock.Mock()
_remote.control = mock.Mock(side_effect=[
self.device._exceptions_class.ConnectionClosed('Boom'),
mock.DEFAULT])
self.device.get_remote = mock.Mock(return_value=_remote)
command = 'HELLO'
self.device.send_key(command)
self.assertEqual(STATE_ON, self.device._state)
# verify that _remote.control() get called twice because of retry logic
expected = [mock.call(command),
mock.call(command)]
self.assertEqual(expected, _remote.control.call_args_list)

def test_send_key_unhandled_response(self):
"""Testing unhandled response exception."""
_remote = mock.Mock()
_remote.control = mock.Mock(
side_effect=self.device._exceptions_class.UnhandledResponse('Boom')
)
self.device.get_remote = mock.Mock(return_value=_remote)
self.device.send_key('HELLO')
self.assertIsNone(self.device._remote)
self.assertEqual(STATE_ON, self.device._state)

def test_send_key_os_error(self):
"""Testing broken pipe Exception."""
_remote = mock.Mock()
self.device.get_remote = mock.Mock()
_remote.control = mock.Mock(
side_effect=OSError("Boom"))
self.device.get_remote.return_value = _remote
self.device.send_key("HELLO")
side_effect=OSError('Boom'))
self.device.get_remote = mock.Mock(return_value=_remote)
self.device.send_key('HELLO')
self.assertIsNone(self.device._remote)
self.assertEqual(STATE_OFF, self.device._state)

Expand Down