1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Fix tests no internet (#6411)

* Fix honeywell tests without internet

* Fix device tracker without internet

* Fix MFI using internet during tests

* Remove I/O from apns tests
This commit is contained in:
Paulus Schoutsen
2017-03-04 17:15:20 -08:00
committed by GitHub
parent 1522e67351
commit b939626497
6 changed files with 201 additions and 110 deletions

View File

@@ -38,29 +38,31 @@ class TestMfiSensorSetup(unittest.TestCase):
"""Stop everything that was started."""
self.hass.stop()
def test_setup_missing_config(self):
@mock.patch('mficlient.client.MFiClient')
def test_setup_missing_config(self, mock_client):
"""Test setup with missing configuration."""
config = {
'sensor': {
'platform': 'mfi',
}
}
self.assertFalse(self.PLATFORM.setup_platform(self.hass, config, None))
assert setup_component(self.hass, 'sensor', config)
assert not mock_client.called
@mock.patch('mficlient.client')
@mock.patch('mficlient.client.MFiClient')
def test_setup_failed_login(self, mock_client):
"""Test setup with login failure."""
mock_client.FailedToLogin = Exception()
mock_client.MFiClient.side_effect = mock_client.FailedToLogin
from mficlient.client import FailedToLogin
mock_client.side_effect = FailedToLogin
self.assertFalse(
self.PLATFORM.setup_platform(
self.hass, dict(self.GOOD_CONFIG), None))
@mock.patch('mficlient.client')
@mock.patch('mficlient.client.MFiClient')
def test_setup_failed_connect(self, mock_client):
"""Test setup with conection failure."""
mock_client.FailedToLogin = Exception()
mock_client.MFiClient.side_effect = requests.exceptions.ConnectionError
mock_client.side_effect = requests.exceptions.ConnectionError
self.assertFalse(
self.PLATFORM.setup_platform(
self.hass, dict(self.GOOD_CONFIG), None))
@@ -116,7 +118,6 @@ class TestMfiSensorSetup(unittest.TestCase):
ports = {i: mock.MagicMock(model=model)
for i, model in enumerate(mfi.SENSOR_MODELS)}
ports['bad'] = mock.MagicMock(model='notasensor')
print(ports['bad'].model)
mock_client.return_value.get_devices.return_value = \
[mock.MagicMock(ports=ports)]
assert setup_component(self.hass, sensor.DOMAIN, self.GOOD_CONFIG)