Added checks for empty replies from REST calls and supporting tests (#12904)
This commit is contained in:
1 parent
3682080da2
commit
03225cf20f
2 files changed
+26
-12
No files matched your search
@@ -207,6 +207,18 @@ class TestRestSensor(unittest.TestCase):
|
||||
self.assertEqual('some_json_value',
|
||||
self.sensor.device_state_attributes['key'])
|
||||
|
||||
@patch('homeassistant.components.sensor.rest._LOGGER')
|
||||
def test_update_with_json_attrs_no_data(self, mock_logger):
|
||||
"""Test attributes when no JSON result fetched."""
|
||||
self.rest.update = Mock('rest.RestData.update',
|
||||
side_effect=self.update_side_effect(None))
|
||||
self.sensor = rest.RestSensor(self.hass, self.rest, self.name,
|
||||
self.unit_of_measurement, None, ['key'],
|
||||
self.force_update)
|
||||
self.sensor.update()
|
||||
self.assertEqual({}, self.sensor.device_state_attributes)
|
||||
self.assertTrue(mock_logger.warning.called)
|
||||
|
||||
@patch('homeassistant.components.sensor.rest._LOGGER')
|
||||
def test_update_with_json_attrs_not_dict(self, mock_logger):
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
|
||||
Reference in new issue
Block a user