Replace global test markers with fixtures in Devolo home control tests (#87676)
parent
a4c4f77f73
commit
c3e733c0aa
|
@ -1,31 +1,34 @@
|
|||
"""Fixtures for tests."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
"""Define custom markers."""
|
||||
config.addinivalue_line(
|
||||
"markers",
|
||||
"credentials_invalid: Treat credentials as invalid.",
|
||||
)
|
||||
config.addinivalue_line(
|
||||
"markers",
|
||||
"maintenance: Set maintenance mode to on.",
|
||||
)
|
||||
@pytest.fixture
|
||||
def credentials_valid() -> bool:
|
||||
"""Mark test as credentials invalid."""
|
||||
return True
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def maintenance() -> bool:
|
||||
"""Mark test as maintenance mode on."""
|
||||
return False
|
||||
|
||||
|
||||
@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."""
|
||||
with patch(
|
||||
"homeassistant.components.devolo_home_control.Mydevolo.credentials_valid",
|
||||
return_value=not bool(request.node.get_closest_marker("credentials_invalid")),
|
||||
return_value=credentials_valid,
|
||||
), patch(
|
||||
"homeassistant.components.devolo_home_control.Mydevolo.maintenance",
|
||||
return_value=bool(request.node.get_closest_marker("maintenance")),
|
||||
return_value=maintenance,
|
||||
), patch(
|
||||
"homeassistant.components.devolo_home_control.Mydevolo.get_gateway_ids",
|
||||
return_value=["1400000000000001", "1400000000000002"],
|
||||
|
|
|
@ -30,7 +30,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||
await _setup(hass, result)
|
||||
|
||||
|
||||
@pytest.mark.credentials_invalid
|
||||
@pytest.mark.parametrize("credentials_valid", [False])
|
||||
async def test_form_invalid_credentials_user(hass: HomeAssistant) -> None:
|
||||
"""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)
|
||||
|
||||
|
||||
@pytest.mark.credentials_invalid
|
||||
@pytest.mark.parametrize("credentials_valid", [False])
|
||||
async def test_form_invalid_credentials_zeroconf(hass: HomeAssistant) -> None:
|
||||
"""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
|
||||
|
||||
|
||||
@pytest.mark.credentials_invalid
|
||||
@pytest.mark.parametrize("credentials_valid", [False])
|
||||
async def test_form_invalid_credentials_reauth(hass: HomeAssistant) -> None:
|
||||
"""Test if we get the error message on invalid credentials."""
|
||||
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
|
||||
|
||||
|
||||
@pytest.mark.credentials_invalid
|
||||
@pytest.mark.parametrize("credentials_valid", [False])
|
||||
async def test_setup_entry_credentials_invalid(hass: HomeAssistant):
|
||||
"""Test setup entry fails if credentials are invalid."""
|
||||
entry = configure_integration(hass)
|
||||
|
@ -33,7 +33,7 @@ async def test_setup_entry_credentials_invalid(hass: HomeAssistant):
|
|||
assert entry.state is ConfigEntryState.SETUP_ERROR
|
||||
|
||||
|
||||
@pytest.mark.maintenance
|
||||
@pytest.mark.parametrize("maintenance", [True])
|
||||
async def test_setup_entry_maintenance(hass: HomeAssistant):
|
||||
"""Test setup entry fails if mydevolo is in maintenance mode."""
|
||||
entry = configure_integration(hass)
|
||||
|
|
Loading…
Reference in New Issue