mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Fixes for rest tests (#5495)
* Fixes for rest tests * Linter fixes * Alternate test_setup_missing_config implementation
This commit is contained in:
parent
8217a42960
commit
f54f68903d
@ -7,9 +7,11 @@ from requests.exceptions import Timeout, MissingSchema, RequestException
|
||||
import requests_mock
|
||||
|
||||
from homeassistant.bootstrap import setup_component
|
||||
import homeassistant.components.sensor as sensor
|
||||
import homeassistant.components.sensor.rest as rest
|
||||
from homeassistant.const import STATE_UNKNOWN
|
||||
from homeassistant.helpers.config_validation import template
|
||||
|
||||
from tests.common import get_test_home_assistant, assert_setup_component
|
||||
|
||||
|
||||
@ -26,10 +28,9 @@ class TestRestSwitchSetup(unittest.TestCase):
|
||||
|
||||
def test_setup_missing_config(self):
|
||||
"""Test setup with configuration missing required entries."""
|
||||
self.assertFalse(rest.setup_platform(self.hass, {
|
||||
'platform': 'rest',
|
||||
'resource': 'http://localhost'
|
||||
}, None))
|
||||
with assert_setup_component(0):
|
||||
assert setup_component(self.hass, sensor.DOMAIN, {
|
||||
'sensor': {'platform': 'rest'}})
|
||||
|
||||
def test_setup_missing_schema(self):
|
||||
"""Test setup with resource missing schema."""
|
||||
@ -40,7 +41,8 @@ class TestRestSwitchSetup(unittest.TestCase):
|
||||
'method': 'GET'
|
||||
}, None)
|
||||
|
||||
@patch('requests.get', side_effect=requests.exceptions.ConnectionError())
|
||||
@patch('requests.Session.send',
|
||||
side_effect=requests.exceptions.ConnectionError())
|
||||
def test_setup_failed_connect(self, mock_req):
|
||||
"""Test setup when connection error occurs."""
|
||||
self.assertFalse(rest.setup_platform(self.hass, {
|
||||
@ -48,7 +50,7 @@ class TestRestSwitchSetup(unittest.TestCase):
|
||||
'resource': 'http://localhost',
|
||||
}, None))
|
||||
|
||||
@patch('requests.get', side_effect=Timeout())
|
||||
@patch('requests.Session.send', side_effect=Timeout())
|
||||
def test_setup_timeout(self, mock_req):
|
||||
"""Test setup when connection timeout occurs."""
|
||||
self.assertFalse(rest.setup_platform(self.hass, {
|
||||
|
Loading…
x
Reference in New Issue
Block a user