From b136e38f7ce3558473c76e382b21bacb7578541b Mon Sep 17 00:00:00 2001 From: PeteRager <76050312+PeteRager@users.noreply.github.com> Date: Wed, 17 Apr 2024 11:32:51 -0400 Subject: [PATCH] Test changes for HA changes --- .vscode/settings.json | 2 +- tests/conftest.py | 22 +++++++++------------- tests/test_async_setup_entry.py | 14 +++++++------- tests/test_config_flow.py | 12 ++++++------ 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 541629d..9b83183 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,9 +2,9 @@ "python.testing.pytestArgs": [ "tests","--asyncio-mode=auto" ], + "python.experiments.optOutFrom": ["pythonTestAdapter"], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, - "python.experiments.enabled": false, "cSpell.words": [ "ASHRAE", "automations", diff --git a/tests/conftest.py b/tests/conftest.py index d04bcaa..926d720 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,6 +14,7 @@ from unittest.mock import patch import pytest +import pytest_socket from lennoxs30api.s30api_async import ( lennox_system, @@ -78,7 +79,9 @@ @pytest.fixture(autouse=True) def socket_enabled(): - pass + pytest_socket.socket_allow_hosts(["127.0.0.1"]) + pytest_socket.disable_socket(allow_unix_socket=True) + @pytest.fixture(autouse=True) def auto_enable_custom_integrations(enable_custom_integrations): @@ -131,8 +134,7 @@ def loadfile(name: str, sysId: str = None) -> json: @pytest.fixture def config_entry_local() -> config_entries.ConfigEntry: - config = config_entries.ConfigEntry(version=1, domain=DOMAIN, title="10.0.0.1", data={}, source="User") - config.unique_id = "12345" + config = config_entries.ConfigEntry(version=1, minor_version=0, domain=DOMAIN, title="10.0.0.1", data={}, source="User", unique_id="12345") config.data = {} config.data[CONF_CLOUD_CONNECTION] = False config.data[CONF_HOST] = "10.0.0.1" @@ -158,8 +160,7 @@ def config_entry_local() -> config_entries.ConfigEntry: @pytest.fixture def config_entry_cloud() -> config_entries.ConfigEntry: - config = config_entries.ConfigEntry(version=1, domain=DOMAIN, title="10.0.0.1", data={}, source="User") - config.unique_id = "12345" + config = config_entries.ConfigEntry(version=1, minor_version = 0, domain=DOMAIN, title="10.0.0.1", data={}, source="User", unique_id="12345") config.data = {} config.data[CONF_CLOUD_CONNECTION] = True config.data[CONF_EMAIL] = "pete.rage@rage.com" @@ -270,8 +271,7 @@ def manager_us_customary_units(hass: HomeAssistant, config_entry_local) -> Manag @pytest.fixture def manager_2_systems(hass) -> Manager: - config = config_entries.ConfigEntry(version=1, domain=DOMAIN, title="10.0.0.1", data={}, source="User") - config.unique_id = "12345" + config = config_entries.ConfigEntry(version=1, minor_version = 0, domain=DOMAIN, title="10.0.0.1", data={}, source="User", unique_id="12345") manager_to_return = Manager( hass=hass, @@ -326,9 +326,7 @@ def manager_2_systems(hass) -> Manager: @pytest.fixture def manager_mz(hass) -> Manager: - config = config_entries.ConfigEntry(version=1, domain=DOMAIN, title="10.0.0.1", data={}, source="User") - config.unique_id = "12345" - + config = config_entries.ConfigEntry(version=1, minor_version = 0, domain=DOMAIN, title="10.0.0.1", data={}, source="User", unique_id="12345") manager_to_return = Manager( hass=hass, config=config, @@ -371,9 +369,7 @@ def manager_mz(hass) -> Manager: @pytest.fixture def manager_system_04_furn_ac_zoning(hass) -> Manager: - config = config_entries.ConfigEntry(version=1, domain=DOMAIN, title="10.0.0.1", data={}, source="User") - config.unique_id = "12345" - + config = config_entries.ConfigEntry(version=1, minor_version = 0, domain=DOMAIN, title="10.0.0.1", data={}, source="User", unique_id="12345") manager_to_return = Manager( hass=hass, config=config, diff --git a/tests/test_async_setup_entry.py b/tests/test_async_setup_entry.py index aab2bb6..a271eaf 100644 --- a/tests/test_async_setup_entry.py +++ b/tests/test_async_setup_entry.py @@ -64,7 +64,7 @@ async def test_async_setup_entry_local(hass: HomeAssistant, caplog): } hass.data[LENNOX_DOMAIN] = {} - config_entry = config_entries.ConfigEntry(1, DOMAIN, "Test", data, "my_source") + config_entry = config_entries.ConfigEntry(version=1, minor_version=0, domain=DOMAIN, title = "Test", data = data, source="my_source") with patch("custom_components.lennoxs30.Manager.s30_initialize") as s30_initialize: res = await async_setup_entry(hass, config_entry) @@ -182,7 +182,7 @@ async def test_async_setup_entry_cloud(hass, caplog): } hass.data[LENNOX_DOMAIN] = {} - config_entry = config_entries.ConfigEntry(1, DOMAIN, "Test", data, "my_source") + config_entry = config_entries.ConfigEntry(version=1, minor_version=0, domain=DOMAIN, title = "Test", data = data, source="my_source") with patch("custom_components.lennoxs30.Manager.s30_initialize") as s30_initialize: res = await async_setup_entry(hass, config_entry) @@ -236,7 +236,7 @@ async def test_async_setup_entry_multiple(hass, caplog): } hass.data[LENNOX_DOMAIN] = {} - config_entry = config_entries.ConfigEntry(1, DOMAIN, "Test", data, "my_source") + config_entry = config_entries.ConfigEntry(version=1, minor_version=0, domain=DOMAIN, title = "Test", data = data, source="my_source", unique_id="12345") with patch("custom_components.lennoxs30.Manager.s30_initialize") as s30_initialize: res = await async_setup_entry(hass, config_entry) @@ -286,7 +286,7 @@ async def test_async_setup_entry_multiple(hass, caplog): } hass.data[LENNOX_DOMAIN] = {} - config_entry = config_entries.ConfigEntry(1, DOMAIN, "Test1", data, "my_source") + config_entry = config_entries.ConfigEntry(version=1, minor_version=0, domain=DOMAIN, title = "Test1", data = data, source="my_source", unique_id="123456") with patch("custom_components.lennoxs30.Manager.s30_initialize") as s30_initialize: res = await async_setup_entry(hass, config_entry) @@ -337,7 +337,7 @@ async def test_async_setup_entry_multiple(hass, caplog): } hass.data[LENNOX_DOMAIN] = {} - config_entry = config_entries.ConfigEntry(1, DOMAIN, "Test3", data, "my_source") + config_entry = config_entries.ConfigEntry(version=1, minor_version=0, domain=DOMAIN, title = "Test2", data = data, source="my_source", unique_id="1234567") with patch("custom_components.lennoxs30.Manager.s30_initialize") as s30_initialize: res = await async_setup_entry(hass, config_entry) @@ -391,7 +391,7 @@ async def test_async_unload_entry_success(hass, caplog): } hass.data[LENNOX_DOMAIN] = {} - config_entry = config_entries.ConfigEntry(1, DOMAIN, "Test", data, "my_source") + config_entry = config_entries.ConfigEntry(version=1, minor_version=0, domain=DOMAIN, title = "Test", data = data, source="my_source") with patch("custom_components.lennoxs30.Manager.s30_initialize") as _: res = await async_setup_entry(hass, config_entry) @@ -437,7 +437,7 @@ async def test_async_unload_entry_unload_fail(hass, caplog): } hass.data[LENNOX_DOMAIN] = {} - config_entry = config_entries.ConfigEntry(1, DOMAIN, "Test", data, "my_source") + config_entry = config_entries.ConfigEntry(version=1, minor_version=0, domain=DOMAIN, title = "Test", data = data, source="my_source") with caplog.at_level(logging.ERROR): caplog.clear() diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index da8281d..115adc4 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -426,7 +426,7 @@ async def test_upgrade_config_v1(hass): "message_debug_file": "", } - config_entry = config_entries.ConfigEntry(1, DOMAIN, "Test", data, "my_source") + config_entry = config_entries.ConfigEntry(version=1, minor_version=0, domain=DOMAIN, title = "Test", data = data, source="my_source") with patch.object(hass.config_entries, "async_update_entry") as update_entry: await async_migrate_entry(hass, config_entry) assert update_entry.call_count == 1 @@ -469,7 +469,7 @@ async def test_upgrade_config_v1(hass): "message_debug_file": "", } - config_entry = config_entries.ConfigEntry(1, DOMAIN, "Test", data, "my_source") + config_entry = config_entries.ConfigEntry(version=1, minor_version=0, domain=DOMAIN, title = "Test", data = data, source="my_source") with patch.object(hass.config_entries, "async_update_entry") as update_entry: await async_migrate_entry(hass, config_entry) assert update_entry.call_count == 1 @@ -516,7 +516,7 @@ async def test_upgrade_config_v2(hass): "timeout": 30, } - config_entry = config_entries.ConfigEntry(1, DOMAIN, "Test", data, "my_source") + config_entry = config_entries.ConfigEntry(version=1, minor_version=0, domain=DOMAIN, title = "Test", data = data, source="my_source") with patch.object(hass.config_entries, "async_update_entry") as update_entry: await async_migrate_entry(hass, config_entry) assert update_entry.call_count == 1 @@ -562,7 +562,7 @@ async def test_upgrade_config_v2(hass): "timeout": 30, } - config_entry = config_entries.ConfigEntry(1, DOMAIN, "Test", data, "my_source") + config_entry = config_entries.ConfigEntry(version=1, minor_version=0, domain=DOMAIN, title = "Test", data = data, source="my_source") with patch.object(hass.config_entries, "async_update_entry") as update_entry: await async_migrate_entry(hass, config_entry) assert update_entry.call_count == 1 @@ -611,7 +611,7 @@ async def test_upgrade_config_v3(hass, caplog): "timeout": 30, } - config_entry = config_entries.ConfigEntry(1, DOMAIN, "Test", data, "my_source") + config_entry = config_entries.ConfigEntry(version=1, minor_version=0, domain=DOMAIN, title = "Test", data = data, source="my_source") with patch.object(hass.config_entries, "async_update_entry") as update_entry: await async_migrate_entry(hass, config_entry) assert update_entry.call_count == 1 @@ -657,7 +657,7 @@ async def test_upgrade_config_v3(hass, caplog): "timeout": 30, } - config_entry = config_entries.ConfigEntry(1, DOMAIN, "Test", data, "my_source") + config_entry = config_entries.ConfigEntry(version=1, minor_version=0, domain=DOMAIN, title = "Test", data = data, source="my_source") with patch.object(hass.config_entries, "async_update_entry") as update_entry: await async_migrate_entry(hass, config_entry) assert update_entry.call_count == 1