Fix mfi tests (#61904)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-12-16 13:59:58 +01:00 committed by GitHub
parent 105ad861bd
commit 550004f109
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,5 @@
"""The tests for the mFi sensor platform.""" """The tests for the mFi sensor platform."""
from copy import deepcopy
import unittest.mock as mock import unittest.mock as mock
from mficlient.client import FailedToLogin from mficlient.client import FailedToLogin
@ -38,20 +39,20 @@ async def test_setup_failed_login(hass):
"""Test setup with login failure.""" """Test setup with login failure."""
with mock.patch("homeassistant.components.mfi.sensor.MFiClient") as mock_client: with mock.patch("homeassistant.components.mfi.sensor.MFiClient") as mock_client:
mock_client.side_effect = FailedToLogin mock_client.side_effect = FailedToLogin
assert not PLATFORM.setup_platform(hass, dict(GOOD_CONFIG), None) assert not PLATFORM.setup_platform(hass, GOOD_CONFIG, None)
async def test_setup_failed_connect(hass): async def test_setup_failed_connect(hass):
"""Test setup with connection failure.""" """Test setup with connection failure."""
with mock.patch("homeassistant.components.mfi.sensor.MFiClient") as mock_client: with mock.patch("homeassistant.components.mfi.sensor.MFiClient") as mock_client:
mock_client.side_effect = requests.exceptions.ConnectionError mock_client.side_effect = requests.exceptions.ConnectionError
assert not PLATFORM.setup_platform(hass, dict(GOOD_CONFIG), None) assert not PLATFORM.setup_platform(hass, GOOD_CONFIG, None)
async def test_setup_minimum(hass): async def test_setup_minimum(hass):
"""Test setup with minimum configuration.""" """Test setup with minimum configuration."""
with mock.patch("homeassistant.components.mfi.sensor.MFiClient") as mock_client: with mock.patch("homeassistant.components.mfi.sensor.MFiClient") as mock_client:
config = dict(GOOD_CONFIG) config = deepcopy(GOOD_CONFIG)
del config[THING]["port"] del config[THING]["port"]
assert await async_setup_component(hass, COMPONENT.DOMAIN, config) assert await async_setup_component(hass, COMPONENT.DOMAIN, config)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -64,9 +65,7 @@ async def test_setup_minimum(hass):
async def test_setup_with_port(hass): async def test_setup_with_port(hass):
"""Test setup with port.""" """Test setup with port."""
with mock.patch("homeassistant.components.mfi.sensor.MFiClient") as mock_client: with mock.patch("homeassistant.components.mfi.sensor.MFiClient") as mock_client:
config = dict(GOOD_CONFIG) assert await async_setup_component(hass, COMPONENT.DOMAIN, GOOD_CONFIG)
config[THING]["port"] = 6123
assert await async_setup_component(hass, COMPONENT.DOMAIN, config)
await hass.async_block_till_done() await hass.async_block_till_done()
assert mock_client.call_count == 1 assert mock_client.call_count == 1
assert mock_client.call_args == mock.call( assert mock_client.call_args == mock.call(
@ -77,7 +76,7 @@ async def test_setup_with_port(hass):
async def test_setup_with_tls_disabled(hass): async def test_setup_with_tls_disabled(hass):
"""Test setup without TLS.""" """Test setup without TLS."""
with mock.patch("homeassistant.components.mfi.sensor.MFiClient") as mock_client: with mock.patch("homeassistant.components.mfi.sensor.MFiClient") as mock_client:
config = dict(GOOD_CONFIG) config = deepcopy(GOOD_CONFIG)
del config[THING]["port"] del config[THING]["port"]
config[THING]["ssl"] = False config[THING]["ssl"] = False
config[THING]["verify_ssl"] = False config[THING]["verify_ssl"] = False