mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Replace global test markers with fixtures in Devolo home control tests (#87676)
This commit is contained in:
parent
a4c4f77f73
commit
c3e733c0aa
@ -1,31 +1,34 @@
|
|||||||
"""Fixtures for tests."""
|
"""Fixtures for tests."""
|
||||||
|
|
||||||
|
from collections.abc import Generator
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure(config):
|
@pytest.fixture
|
||||||
"""Define custom markers."""
|
def credentials_valid() -> bool:
|
||||||
config.addinivalue_line(
|
"""Mark test as credentials invalid."""
|
||||||
"markers",
|
return True
|
||||||
"credentials_invalid: Treat credentials as invalid.",
|
|
||||||
)
|
|
||||||
config.addinivalue_line(
|
@pytest.fixture
|
||||||
"markers",
|
def maintenance() -> bool:
|
||||||
"maintenance: Set maintenance mode to on.",
|
"""Mark test as maintenance mode on."""
|
||||||
)
|
return False
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def patch_mydevolo(request):
|
def patch_mydevolo(
|
||||||
|
credentials_valid: bool, maintenance: bool
|
||||||
|
) -> Generator[None, None, None]:
|
||||||
"""Fixture to patch mydevolo into a desired state."""
|
"""Fixture to patch mydevolo into a desired state."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.devolo_home_control.Mydevolo.credentials_valid",
|
"homeassistant.components.devolo_home_control.Mydevolo.credentials_valid",
|
||||||
return_value=not bool(request.node.get_closest_marker("credentials_invalid")),
|
return_value=credentials_valid,
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.devolo_home_control.Mydevolo.maintenance",
|
"homeassistant.components.devolo_home_control.Mydevolo.maintenance",
|
||||||
return_value=bool(request.node.get_closest_marker("maintenance")),
|
return_value=maintenance,
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.devolo_home_control.Mydevolo.get_gateway_ids",
|
"homeassistant.components.devolo_home_control.Mydevolo.get_gateway_ids",
|
||||||
return_value=["1400000000000001", "1400000000000002"],
|
return_value=["1400000000000001", "1400000000000002"],
|
||||||
|
@ -30,7 +30,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||||||
await _setup(hass, result)
|
await _setup(hass, result)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.credentials_invalid
|
@pytest.mark.parametrize("credentials_valid", [False])
|
||||||
async def test_form_invalid_credentials_user(hass: HomeAssistant) -> None:
|
async def test_form_invalid_credentials_user(hass: HomeAssistant) -> None:
|
||||||
"""Test if we get the error message on invalid credentials."""
|
"""Test if we get the error message on invalid credentials."""
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ async def test_form_zeroconf(hass: HomeAssistant) -> None:
|
|||||||
await _setup(hass, result)
|
await _setup(hass, result)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.credentials_invalid
|
@pytest.mark.parametrize("credentials_valid", [False])
|
||||||
async def test_form_invalid_credentials_zeroconf(hass: HomeAssistant) -> None:
|
async def test_form_invalid_credentials_zeroconf(hass: HomeAssistant) -> None:
|
||||||
"""Test if we get the error message on invalid credentials."""
|
"""Test if we get the error message on invalid credentials."""
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ async def test_form_reauth(hass: HomeAssistant) -> None:
|
|||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.credentials_invalid
|
@pytest.mark.parametrize("credentials_valid", [False])
|
||||||
async def test_form_invalid_credentials_reauth(hass: HomeAssistant) -> None:
|
async def test_form_invalid_credentials_reauth(hass: HomeAssistant) -> None:
|
||||||
"""Test if we get the error message on invalid credentials."""
|
"""Test if we get the error message on invalid credentials."""
|
||||||
mock_config = MockConfigEntry(domain=DOMAIN, unique_id="123456", data={})
|
mock_config = MockConfigEntry(domain=DOMAIN, unique_id="123456", data={})
|
||||||
|
@ -25,7 +25,7 @@ async def test_setup_entry(hass: HomeAssistant, mock_zeroconf):
|
|||||||
assert entry.state is ConfigEntryState.LOADED
|
assert entry.state is ConfigEntryState.LOADED
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.credentials_invalid
|
@pytest.mark.parametrize("credentials_valid", [False])
|
||||||
async def test_setup_entry_credentials_invalid(hass: HomeAssistant):
|
async def test_setup_entry_credentials_invalid(hass: HomeAssistant):
|
||||||
"""Test setup entry fails if credentials are invalid."""
|
"""Test setup entry fails if credentials are invalid."""
|
||||||
entry = configure_integration(hass)
|
entry = configure_integration(hass)
|
||||||
@ -33,7 +33,7 @@ async def test_setup_entry_credentials_invalid(hass: HomeAssistant):
|
|||||||
assert entry.state is ConfigEntryState.SETUP_ERROR
|
assert entry.state is ConfigEntryState.SETUP_ERROR
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.maintenance
|
@pytest.mark.parametrize("maintenance", [True])
|
||||||
async def test_setup_entry_maintenance(hass: HomeAssistant):
|
async def test_setup_entry_maintenance(hass: HomeAssistant):
|
||||||
"""Test setup entry fails if mydevolo is in maintenance mode."""
|
"""Test setup entry fails if mydevolo is in maintenance mode."""
|
||||||
entry = configure_integration(hass)
|
entry = configure_integration(hass)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user