2018-01-30 12:30:47 +01:00
|
|
|
"""Test requirements module."""
|
|
|
|
import os
|
2021-01-01 22:31:56 +01:00
|
|
|
from unittest.mock import call, patch
|
2019-12-11 12:12:06 +01:00
|
|
|
|
2019-12-10 09:24:49 +01:00
|
|
|
import pytest
|
2019-12-09 16:52:24 +01:00
|
|
|
|
2019-12-11 12:12:06 +01:00
|
|
|
from homeassistant import loader, setup
|
2018-08-28 12:52:18 +02:00
|
|
|
from homeassistant.requirements import (
|
2019-07-31 21:25:30 +02:00
|
|
|
CONSTRAINT_FILE,
|
2019-08-08 00:35:50 +02:00
|
|
|
RequirementsNotFound,
|
2021-09-26 21:47:03 +02:00
|
|
|
async_clear_install_history,
|
2019-12-09 16:52:24 +01:00
|
|
|
async_get_integration_with_requirements,
|
|
|
|
async_process_requirements,
|
2019-07-31 21:25:30 +02:00
|
|
|
)
|
2018-08-28 12:52:18 +02:00
|
|
|
|
2020-04-30 22:29:50 +02:00
|
|
|
from tests.common import MockModule, mock_integration
|
2018-08-28 12:52:18 +02:00
|
|
|
|
2018-01-30 12:30:47 +01:00
|
|
|
|
2019-10-04 22:49:51 +02:00
|
|
|
def env_without_wheel_links():
|
|
|
|
"""Return env without wheel links."""
|
|
|
|
env = dict(os.environ)
|
|
|
|
env.pop("WHEEL_LINKS", None)
|
|
|
|
return env
|
|
|
|
|
|
|
|
|
2020-04-30 22:29:50 +02:00
|
|
|
async def test_requirement_installed_in_venv(hass):
|
|
|
|
"""Test requirement installed in virtual environment."""
|
|
|
|
with patch("os.path.dirname", return_value="ha_package_path"), patch(
|
|
|
|
"homeassistant.util.package.is_virtual_env", return_value=True
|
|
|
|
), patch("homeassistant.util.package.is_docker_env", return_value=False), patch(
|
|
|
|
"homeassistant.util.package.install_package", return_value=True
|
|
|
|
) as mock_install, patch.dict(
|
|
|
|
os.environ, env_without_wheel_links(), clear=True
|
2019-07-31 21:25:30 +02:00
|
|
|
):
|
2020-04-30 22:29:50 +02:00
|
|
|
hass.config.skip_pip = False
|
|
|
|
mock_integration(hass, MockModule("comp", requirements=["package==0.0.1"]))
|
|
|
|
assert await setup.async_setup_component(hass, "comp", {})
|
|
|
|
assert "comp" in hass.config.components
|
2018-08-28 12:52:18 +02:00
|
|
|
assert mock_install.call_args == call(
|
2019-07-31 21:25:30 +02:00
|
|
|
"package==0.0.1",
|
|
|
|
constraints=os.path.join("ha_package_path", CONSTRAINT_FILE),
|
2021-07-24 14:07:10 +02:00
|
|
|
timeout=60,
|
2019-06-01 10:04:12 +02:00
|
|
|
no_cache_dir=False,
|
|
|
|
)
|
2018-01-30 12:30:47 +01:00
|
|
|
|
2020-04-30 22:29:50 +02:00
|
|
|
|
|
|
|
async def test_requirement_installed_in_deps(hass):
|
|
|
|
"""Test requirement installed in deps directory."""
|
|
|
|
with patch("os.path.dirname", return_value="ha_package_path"), patch(
|
|
|
|
"homeassistant.util.package.is_virtual_env", return_value=False
|
|
|
|
), patch("homeassistant.util.package.is_docker_env", return_value=False), patch(
|
|
|
|
"homeassistant.util.package.install_package", return_value=True
|
|
|
|
) as mock_install, patch.dict(
|
|
|
|
os.environ, env_without_wheel_links(), clear=True
|
2019-07-31 21:25:30 +02:00
|
|
|
):
|
2020-04-30 22:29:50 +02:00
|
|
|
hass.config.skip_pip = False
|
|
|
|
mock_integration(hass, MockModule("comp", requirements=["package==0.0.1"]))
|
|
|
|
assert await setup.async_setup_component(hass, "comp", {})
|
|
|
|
assert "comp" in hass.config.components
|
2018-08-28 12:52:18 +02:00
|
|
|
assert mock_install.call_args == call(
|
2019-07-31 21:25:30 +02:00
|
|
|
"package==0.0.1",
|
2020-04-30 22:29:50 +02:00
|
|
|
target=hass.config.path("deps"),
|
2019-07-31 21:25:30 +02:00
|
|
|
constraints=os.path.join("ha_package_path", CONSTRAINT_FILE),
|
2021-07-24 14:07:10 +02:00
|
|
|
timeout=60,
|
2019-06-01 10:04:12 +02:00
|
|
|
no_cache_dir=False,
|
|
|
|
)
|
2018-08-28 12:52:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
async def test_install_existing_package(hass):
|
|
|
|
"""Test an install attempt on an existing package."""
|
2019-07-31 21:25:30 +02:00
|
|
|
with patch(
|
2019-08-01 16:37:37 +02:00
|
|
|
"homeassistant.util.package.install_package", return_value=True
|
2019-07-31 21:25:30 +02:00
|
|
|
) as mock_inst:
|
2019-08-08 00:35:50 +02:00
|
|
|
await async_process_requirements(hass, "test_component", ["hello==1.0.0"])
|
2018-08-28 12:52:18 +02:00
|
|
|
|
|
|
|
assert len(mock_inst.mock_calls) == 1
|
|
|
|
|
2019-07-31 21:25:30 +02:00
|
|
|
with patch("homeassistant.util.package.is_installed", return_value=True), patch(
|
|
|
|
"homeassistant.util.package.install_package"
|
|
|
|
) as mock_inst:
|
2019-08-08 00:35:50 +02:00
|
|
|
await async_process_requirements(hass, "test_component", ["hello==1.0.0"])
|
2018-08-28 12:52:18 +02:00
|
|
|
|
|
|
|
assert len(mock_inst.mock_calls) == 0
|
2019-05-30 00:30:09 +02:00
|
|
|
|
|
|
|
|
2019-08-08 00:35:50 +02:00
|
|
|
async def test_install_missing_package(hass):
|
|
|
|
"""Test an install attempt on an existing package."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.util.package.install_package", return_value=False
|
2021-03-27 09:17:15 +01:00
|
|
|
) as mock_inst, pytest.raises(RequirementsNotFound):
|
|
|
|
await async_process_requirements(hass, "test_component", ["hello==1.0.0"])
|
2019-08-08 00:35:50 +02:00
|
|
|
|
2021-09-26 21:47:03 +02:00
|
|
|
assert len(mock_inst.mock_calls) == 3
|
2019-08-08 00:35:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
async def test_get_integration_with_requirements(hass):
|
|
|
|
"""Check getting an integration with loaded requirements."""
|
|
|
|
hass.config.skip_pip = False
|
2019-10-31 19:39:26 +01:00
|
|
|
mock_integration(
|
|
|
|
hass, MockModule("test_component_dep", requirements=["test-comp-dep==1.0.0"])
|
|
|
|
)
|
2019-11-02 01:21:50 +01:00
|
|
|
mock_integration(
|
|
|
|
hass,
|
|
|
|
MockModule(
|
|
|
|
"test_component_after_dep", requirements=["test-comp-after-dep==1.0.0"]
|
|
|
|
),
|
|
|
|
)
|
2019-10-31 19:39:26 +01:00
|
|
|
mock_integration(
|
|
|
|
hass,
|
|
|
|
MockModule(
|
|
|
|
"test_component",
|
|
|
|
requirements=["test-comp==1.0.0"],
|
|
|
|
dependencies=["test_component_dep"],
|
2019-11-02 01:21:50 +01:00
|
|
|
partial_manifest={"after_dependencies": ["test_component_after_dep"]},
|
2019-10-31 19:39:26 +01:00
|
|
|
),
|
|
|
|
)
|
2019-08-08 00:35:50 +02:00
|
|
|
|
|
|
|
with patch(
|
|
|
|
"homeassistant.util.package.is_installed", return_value=False
|
|
|
|
) as mock_is_installed, patch(
|
|
|
|
"homeassistant.util.package.install_package", return_value=True
|
|
|
|
) as mock_inst:
|
|
|
|
|
|
|
|
integration = await async_get_integration_with_requirements(
|
|
|
|
hass, "test_component"
|
|
|
|
)
|
|
|
|
assert integration
|
|
|
|
assert integration.domain == "test_component"
|
|
|
|
|
2019-11-02 01:21:50 +01:00
|
|
|
assert len(mock_is_installed.mock_calls) == 3
|
2019-11-03 05:21:13 +01:00
|
|
|
assert sorted(mock_call[1][0] for mock_call in mock_is_installed.mock_calls) == [
|
|
|
|
"test-comp-after-dep==1.0.0",
|
|
|
|
"test-comp-dep==1.0.0",
|
|
|
|
"test-comp==1.0.0",
|
|
|
|
]
|
2021-04-22 22:32:38 +02:00
|
|
|
|
|
|
|
assert len(mock_inst.mock_calls) == 3
|
|
|
|
assert sorted(mock_call[1][0] for mock_call in mock_inst.mock_calls) == [
|
|
|
|
"test-comp-after-dep==1.0.0",
|
|
|
|
"test-comp-dep==1.0.0",
|
|
|
|
"test-comp==1.0.0",
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
async def test_get_integration_with_requirements_pip_install_fails_two_passes(hass):
|
|
|
|
"""Check getting an integration with loaded requirements and the pip install fails two passes."""
|
|
|
|
hass.config.skip_pip = False
|
|
|
|
mock_integration(
|
|
|
|
hass, MockModule("test_component_dep", requirements=["test-comp-dep==1.0.0"])
|
|
|
|
)
|
|
|
|
mock_integration(
|
|
|
|
hass,
|
|
|
|
MockModule(
|
|
|
|
"test_component_after_dep", requirements=["test-comp-after-dep==1.0.0"]
|
|
|
|
),
|
|
|
|
)
|
|
|
|
mock_integration(
|
|
|
|
hass,
|
|
|
|
MockModule(
|
|
|
|
"test_component",
|
|
|
|
requirements=["test-comp==1.0.0"],
|
|
|
|
dependencies=["test_component_dep"],
|
|
|
|
partial_manifest={"after_dependencies": ["test_component_after_dep"]},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
def _mock_install_package(package, **kwargs):
|
|
|
|
if package == "test-comp==1.0.0":
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
# 1st pass
|
|
|
|
with pytest.raises(RequirementsNotFound), patch(
|
|
|
|
"homeassistant.util.package.is_installed", return_value=False
|
|
|
|
) as mock_is_installed, patch(
|
|
|
|
"homeassistant.util.package.install_package", side_effect=_mock_install_package
|
|
|
|
) as mock_inst:
|
|
|
|
|
|
|
|
integration = await async_get_integration_with_requirements(
|
|
|
|
hass, "test_component"
|
|
|
|
)
|
|
|
|
assert integration
|
|
|
|
assert integration.domain == "test_component"
|
|
|
|
|
|
|
|
assert len(mock_is_installed.mock_calls) == 3
|
|
|
|
assert sorted(mock_call[1][0] for mock_call in mock_is_installed.mock_calls) == [
|
|
|
|
"test-comp-after-dep==1.0.0",
|
|
|
|
"test-comp-dep==1.0.0",
|
|
|
|
"test-comp==1.0.0",
|
|
|
|
]
|
|
|
|
|
2021-09-26 21:47:03 +02:00
|
|
|
assert len(mock_inst.mock_calls) == 7
|
2021-04-22 22:32:38 +02:00
|
|
|
assert sorted(mock_call[1][0] for mock_call in mock_inst.mock_calls) == [
|
|
|
|
"test-comp-after-dep==1.0.0",
|
2021-09-26 21:47:03 +02:00
|
|
|
"test-comp-after-dep==1.0.0",
|
|
|
|
"test-comp-after-dep==1.0.0",
|
|
|
|
"test-comp-dep==1.0.0",
|
|
|
|
"test-comp-dep==1.0.0",
|
2021-04-22 22:32:38 +02:00
|
|
|
"test-comp-dep==1.0.0",
|
|
|
|
"test-comp==1.0.0",
|
|
|
|
]
|
|
|
|
|
|
|
|
# 2nd pass
|
|
|
|
with pytest.raises(RequirementsNotFound), patch(
|
|
|
|
"homeassistant.util.package.is_installed", return_value=False
|
|
|
|
) as mock_is_installed, patch(
|
|
|
|
"homeassistant.util.package.install_package", side_effect=_mock_install_package
|
|
|
|
) as mock_inst:
|
|
|
|
|
|
|
|
integration = await async_get_integration_with_requirements(
|
|
|
|
hass, "test_component"
|
|
|
|
)
|
|
|
|
assert integration
|
|
|
|
assert integration.domain == "test_component"
|
|
|
|
|
2022-06-13 22:10:05 +02:00
|
|
|
assert len(mock_is_installed.mock_calls) == 0
|
2021-09-26 21:47:03 +02:00
|
|
|
# On another attempt we remember failures and don't try again
|
2022-06-13 22:10:05 +02:00
|
|
|
assert len(mock_inst.mock_calls) == 0
|
2021-09-26 21:47:03 +02:00
|
|
|
|
|
|
|
# Now clear the history and so we try again
|
|
|
|
async_clear_install_history(hass)
|
|
|
|
|
|
|
|
with pytest.raises(RequirementsNotFound), patch(
|
|
|
|
"homeassistant.util.package.is_installed", return_value=False
|
|
|
|
) as mock_is_installed, patch(
|
|
|
|
"homeassistant.util.package.install_package", side_effect=_mock_install_package
|
|
|
|
) as mock_inst:
|
|
|
|
|
|
|
|
integration = await async_get_integration_with_requirements(
|
|
|
|
hass, "test_component"
|
|
|
|
)
|
|
|
|
assert integration
|
|
|
|
assert integration.domain == "test_component"
|
|
|
|
|
2022-06-13 22:10:05 +02:00
|
|
|
assert len(mock_is_installed.mock_calls) == 2
|
2021-09-26 21:47:03 +02:00
|
|
|
assert sorted(mock_call[1][0] for mock_call in mock_is_installed.mock_calls) == [
|
|
|
|
"test-comp-after-dep==1.0.0",
|
|
|
|
"test-comp-dep==1.0.0",
|
|
|
|
]
|
|
|
|
|
2022-06-13 22:10:05 +02:00
|
|
|
assert len(mock_inst.mock_calls) == 6
|
2021-09-26 21:47:03 +02:00
|
|
|
assert sorted(mock_call[1][0] for mock_call in mock_inst.mock_calls) == [
|
|
|
|
"test-comp-after-dep==1.0.0",
|
|
|
|
"test-comp-after-dep==1.0.0",
|
|
|
|
"test-comp-after-dep==1.0.0",
|
|
|
|
"test-comp-dep==1.0.0",
|
|
|
|
"test-comp-dep==1.0.0",
|
|
|
|
"test-comp-dep==1.0.0",
|
|
|
|
]
|
|
|
|
|
|
|
|
# Now clear the history and mock success
|
|
|
|
async_clear_install_history(hass)
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
"homeassistant.util.package.is_installed", return_value=False
|
|
|
|
) as mock_is_installed, patch(
|
|
|
|
"homeassistant.util.package.install_package", return_value=True
|
|
|
|
) as mock_inst:
|
|
|
|
|
|
|
|
integration = await async_get_integration_with_requirements(
|
|
|
|
hass, "test_component"
|
|
|
|
)
|
|
|
|
assert integration
|
|
|
|
assert integration.domain == "test_component"
|
|
|
|
|
2022-06-13 22:10:05 +02:00
|
|
|
assert len(mock_is_installed.mock_calls) == 2
|
2021-09-26 21:47:03 +02:00
|
|
|
assert sorted(mock_call[1][0] for mock_call in mock_is_installed.mock_calls) == [
|
|
|
|
"test-comp-after-dep==1.0.0",
|
|
|
|
"test-comp-dep==1.0.0",
|
|
|
|
]
|
|
|
|
|
2022-06-13 22:10:05 +02:00
|
|
|
assert len(mock_inst.mock_calls) == 2
|
2019-11-03 05:21:13 +01:00
|
|
|
assert sorted(mock_call[1][0] for mock_call in mock_inst.mock_calls) == [
|
|
|
|
"test-comp-after-dep==1.0.0",
|
|
|
|
"test-comp-dep==1.0.0",
|
|
|
|
]
|
2019-08-08 00:35:50 +02:00
|
|
|
|
|
|
|
|
2021-04-01 20:30:52 +02:00
|
|
|
async def test_get_integration_with_missing_dependencies(hass):
|
|
|
|
"""Check getting an integration with missing dependencies."""
|
|
|
|
hass.config.skip_pip = False
|
|
|
|
mock_integration(
|
|
|
|
hass,
|
|
|
|
MockModule("test_component_after_dep"),
|
|
|
|
)
|
|
|
|
mock_integration(
|
|
|
|
hass,
|
|
|
|
MockModule(
|
|
|
|
"test_component",
|
|
|
|
dependencies=["test_component_dep"],
|
|
|
|
partial_manifest={"after_dependencies": ["test_component_after_dep"]},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
mock_integration(
|
|
|
|
hass,
|
|
|
|
MockModule(
|
|
|
|
"test_custom_component",
|
|
|
|
dependencies=["test_component_dep"],
|
|
|
|
partial_manifest={"after_dependencies": ["test_component_after_dep"]},
|
|
|
|
),
|
|
|
|
built_in=False,
|
|
|
|
)
|
|
|
|
with pytest.raises(loader.IntegrationNotFound):
|
|
|
|
await async_get_integration_with_requirements(hass, "test_component")
|
|
|
|
with pytest.raises(loader.IntegrationNotFound):
|
|
|
|
await async_get_integration_with_requirements(hass, "test_custom_component")
|
|
|
|
|
|
|
|
|
|
|
|
async def test_get_built_in_integration_with_missing_after_dependencies(hass):
|
|
|
|
"""Check getting a built_in integration with missing after_dependencies results in exception."""
|
|
|
|
hass.config.skip_pip = False
|
|
|
|
mock_integration(
|
|
|
|
hass,
|
|
|
|
MockModule(
|
|
|
|
"test_component",
|
|
|
|
partial_manifest={"after_dependencies": ["test_component_after_dep"]},
|
|
|
|
),
|
|
|
|
built_in=True,
|
|
|
|
)
|
|
|
|
with pytest.raises(loader.IntegrationNotFound):
|
|
|
|
await async_get_integration_with_requirements(hass, "test_component")
|
|
|
|
|
|
|
|
|
|
|
|
async def test_get_custom_integration_with_missing_after_dependencies(hass):
|
|
|
|
"""Check getting a custom integration with missing after_dependencies."""
|
|
|
|
hass.config.skip_pip = False
|
|
|
|
mock_integration(
|
|
|
|
hass,
|
|
|
|
MockModule(
|
|
|
|
"test_custom_component",
|
|
|
|
partial_manifest={"after_dependencies": ["test_component_after_dep"]},
|
|
|
|
),
|
|
|
|
built_in=False,
|
|
|
|
)
|
|
|
|
integration = await async_get_integration_with_requirements(
|
|
|
|
hass, "test_custom_component"
|
|
|
|
)
|
|
|
|
assert integration
|
|
|
|
assert integration.domain == "test_custom_component"
|
|
|
|
|
|
|
|
|
2019-05-30 00:30:09 +02:00
|
|
|
async def test_install_with_wheels_index(hass):
|
|
|
|
"""Test an install attempt with wheels index URL."""
|
|
|
|
hass.config.skip_pip = False
|
2019-07-31 21:25:30 +02:00
|
|
|
mock_integration(hass, MockModule("comp", requirements=["hello==1.0.0"]))
|
|
|
|
|
|
|
|
with patch("homeassistant.util.package.is_installed", return_value=False), patch(
|
|
|
|
"homeassistant.util.package.is_docker_env", return_value=True
|
|
|
|
), patch("homeassistant.util.package.install_package") as mock_inst, patch.dict(
|
|
|
|
os.environ, {"WHEELS_LINKS": "https://wheels.hass.io/test"}
|
|
|
|
), patch(
|
|
|
|
"os.path.dirname"
|
|
|
|
) as mock_dir:
|
|
|
|
mock_dir.return_value = "ha_package_path"
|
|
|
|
assert await setup.async_setup_component(hass, "comp", {})
|
|
|
|
assert "comp" in hass.config.components
|
2019-10-04 22:49:51 +02:00
|
|
|
|
2019-05-30 00:30:09 +02:00
|
|
|
assert mock_inst.call_args == call(
|
2019-07-31 21:25:30 +02:00
|
|
|
"hello==1.0.0",
|
|
|
|
find_links="https://wheels.hass.io/test",
|
|
|
|
constraints=os.path.join("ha_package_path", CONSTRAINT_FILE),
|
2021-07-24 14:07:10 +02:00
|
|
|
timeout=60,
|
2019-06-01 10:04:12 +02:00
|
|
|
no_cache_dir=True,
|
|
|
|
)
|
2019-05-30 00:30:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
async def test_install_on_docker(hass):
|
|
|
|
"""Test an install attempt on an docker system env."""
|
|
|
|
hass.config.skip_pip = False
|
2019-07-31 21:25:30 +02:00
|
|
|
mock_integration(hass, MockModule("comp", requirements=["hello==1.0.0"]))
|
|
|
|
|
|
|
|
with patch("homeassistant.util.package.is_installed", return_value=False), patch(
|
|
|
|
"homeassistant.util.package.is_docker_env", return_value=True
|
|
|
|
), patch("homeassistant.util.package.install_package") as mock_inst, patch(
|
|
|
|
"os.path.dirname"
|
2019-10-04 22:49:51 +02:00
|
|
|
) as mock_dir, patch.dict(
|
|
|
|
os.environ, env_without_wheel_links(), clear=True
|
|
|
|
):
|
2019-07-31 21:25:30 +02:00
|
|
|
mock_dir.return_value = "ha_package_path"
|
|
|
|
assert await setup.async_setup_component(hass, "comp", {})
|
|
|
|
assert "comp" in hass.config.components
|
2019-10-04 22:49:51 +02:00
|
|
|
|
2019-05-30 00:30:09 +02:00
|
|
|
assert mock_inst.call_args == call(
|
2019-07-31 21:25:30 +02:00
|
|
|
"hello==1.0.0",
|
|
|
|
constraints=os.path.join("ha_package_path", CONSTRAINT_FILE),
|
2021-07-24 14:07:10 +02:00
|
|
|
timeout=60,
|
2019-06-01 10:04:12 +02:00
|
|
|
no_cache_dir=True,
|
|
|
|
)
|
2019-06-04 20:04:20 +02:00
|
|
|
|
|
|
|
|
2020-10-07 18:30:51 +02:00
|
|
|
async def test_discovery_requirements_mqtt(hass):
|
|
|
|
"""Test that we load discovery requirements."""
|
|
|
|
hass.config.skip_pip = False
|
|
|
|
mqtt = await loader.async_get_integration(hass, "mqtt")
|
|
|
|
|
|
|
|
mock_integration(
|
|
|
|
hass, MockModule("mqtt_comp", partial_manifest={"mqtt": ["foo/discovery"]})
|
|
|
|
)
|
|
|
|
with patch(
|
2022-06-13 22:10:05 +02:00
|
|
|
"homeassistant.requirements.RequirementsManager.async_process_requirements",
|
2020-10-07 18:30:51 +02:00
|
|
|
) as mock_process:
|
|
|
|
await async_get_integration_with_requirements(hass, "mqtt_comp")
|
|
|
|
|
|
|
|
assert len(mock_process.mock_calls) == 2 # mqtt also depends on http
|
2022-06-13 22:10:05 +02:00
|
|
|
assert mock_process.mock_calls[0][1][1] == mqtt.requirements
|
2020-10-07 18:30:51 +02:00
|
|
|
|
|
|
|
|
2019-12-10 09:24:49 +01:00
|
|
|
async def test_discovery_requirements_ssdp(hass):
|
|
|
|
"""Test that we load discovery requirements."""
|
|
|
|
hass.config.skip_pip = False
|
|
|
|
ssdp = await loader.async_get_integration(hass, "ssdp")
|
|
|
|
|
|
|
|
mock_integration(
|
|
|
|
hass, MockModule("ssdp_comp", partial_manifest={"ssdp": [{"st": "roku:ecp"}]})
|
|
|
|
)
|
|
|
|
with patch(
|
2022-06-13 22:10:05 +02:00
|
|
|
"homeassistant.requirements.RequirementsManager.async_process_requirements",
|
2019-12-10 09:24:49 +01:00
|
|
|
) as mock_process:
|
|
|
|
await async_get_integration_with_requirements(hass, "ssdp_comp")
|
|
|
|
|
2021-05-26 18:06:30 +02:00
|
|
|
assert len(mock_process.mock_calls) == 4
|
2022-06-13 22:10:05 +02:00
|
|
|
assert mock_process.mock_calls[0][1][1] == ssdp.requirements
|
2020-06-05 23:33:26 +02:00
|
|
|
# Ensure zeroconf is a dep for ssdp
|
2021-05-29 04:18:59 +02:00
|
|
|
assert {
|
2022-06-13 22:10:05 +02:00
|
|
|
mock_process.mock_calls[1][1][0],
|
|
|
|
mock_process.mock_calls[2][1][0],
|
|
|
|
mock_process.mock_calls[3][1][0],
|
2021-05-29 04:18:59 +02:00
|
|
|
} == {"network", "zeroconf", "http"}
|
2019-12-10 09:24:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"partial_manifest",
|
|
|
|
[{"zeroconf": ["_googlecast._tcp.local."]}, {"homekit": {"models": ["LIFX"]}}],
|
|
|
|
)
|
|
|
|
async def test_discovery_requirements_zeroconf(hass, partial_manifest):
|
|
|
|
"""Test that we load discovery requirements."""
|
|
|
|
hass.config.skip_pip = False
|
|
|
|
zeroconf = await loader.async_get_integration(hass, "zeroconf")
|
|
|
|
|
|
|
|
mock_integration(
|
2020-08-27 13:56:20 +02:00
|
|
|
hass,
|
|
|
|
MockModule("comp", partial_manifest=partial_manifest),
|
2019-12-10 09:24:49 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
with patch(
|
2022-06-13 22:10:05 +02:00
|
|
|
"homeassistant.requirements.RequirementsManager.async_process_requirements",
|
2019-12-10 09:24:49 +01:00
|
|
|
) as mock_process:
|
|
|
|
await async_get_integration_with_requirements(hass, "comp")
|
|
|
|
|
2021-05-26 18:06:30 +02:00
|
|
|
assert len(mock_process.mock_calls) == 3 # zeroconf also depends on http
|
2022-06-13 22:10:05 +02:00
|
|
|
assert mock_process.mock_calls[0][1][1] == zeroconf.requirements
|
2021-01-14 09:09:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def test_discovery_requirements_dhcp(hass):
|
|
|
|
"""Test that we load dhcp discovery requirements."""
|
|
|
|
hass.config.skip_pip = False
|
|
|
|
dhcp = await loader.async_get_integration(hass, "dhcp")
|
|
|
|
|
|
|
|
mock_integration(
|
|
|
|
hass,
|
|
|
|
MockModule(
|
|
|
|
"comp",
|
|
|
|
partial_manifest={
|
|
|
|
"dhcp": [{"hostname": "somfy_*", "macaddress": "B8B7F1*"}]
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
with patch(
|
2022-06-13 22:10:05 +02:00
|
|
|
"homeassistant.requirements.RequirementsManager.async_process_requirements",
|
2021-01-14 09:09:08 +01:00
|
|
|
) as mock_process:
|
|
|
|
await async_get_integration_with_requirements(hass, "comp")
|
|
|
|
|
|
|
|
assert len(mock_process.mock_calls) == 1 # dhcp does not depend on http
|
2022-06-13 22:10:05 +02:00
|
|
|
assert mock_process.mock_calls[0][1][1] == dhcp.requirements
|