mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Add exception handling to Sonarr (#4569)
* Add exception handling to request call to prevent failure in setup_platform if host is down * update for comments * update test for state being none * remove unused import
This commit is contained in:
committed by
Paulus Schoutsen
parent
92c6cee2a1
commit
44a508e86c
@@ -10,6 +10,11 @@ from homeassistant.components.sensor import sonarr
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
def mocked_exception(*args, **kwargs):
|
||||
"""Mock exception thrown by requests.get."""
|
||||
raise OSError
|
||||
|
||||
|
||||
def mocked_requests_get(*args, **kwargs):
|
||||
"""Mock requests.get invocations."""
|
||||
class MockResponse:
|
||||
@@ -814,3 +819,23 @@ class TestSonarrSetup(unittest.TestCase):
|
||||
'S04E11',
|
||||
device.device_state_attributes["Bob's Burgers"]
|
||||
)
|
||||
|
||||
@unittest.mock.patch('requests.get', side_effect=mocked_exception)
|
||||
def test_exception_handling(self, req_mock):
|
||||
"""Tests exception being handled"""
|
||||
config = {
|
||||
'platform': 'sonarr',
|
||||
'api_key': 'foo',
|
||||
'days': '1',
|
||||
'unit': 'GB',
|
||||
"include_paths": [
|
||||
'/data'
|
||||
],
|
||||
'monitored_conditions': [
|
||||
'upcoming'
|
||||
]
|
||||
}
|
||||
sonarr.setup_platform(self.hass, config, self.add_devices, None)
|
||||
for device in self.DEVICES:
|
||||
device.update()
|
||||
self.assertEqual(None, device.state)
|
||||
|
||||
Reference in New Issue
Block a user