mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Replace global test markers with fixtures in Synology DSM tests (#87678)
This commit is contained in:
parent
c98b4e3204
commit
e749521b29
@ -1,26 +1,17 @@
|
|||||||
"""Configure Synology DSM tests."""
|
"""Configure Synology DSM tests."""
|
||||||
|
from collections.abc import Generator
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure(config):
|
@pytest.fixture
|
||||||
"""Register custom marker for tests."""
|
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
|
||||||
config.addinivalue_line(
|
"""Mock setting up a config entry."""
|
||||||
"markers", "no_bypass_setup: mark test to disable bypass_setup_fixture"
|
with patch(
|
||||||
)
|
"homeassistant.components.synology_dsm.async_setup_entry", return_value=True
|
||||||
|
) as mock_setup:
|
||||||
|
yield mock_setup
|
||||||
@pytest.fixture(name="bypass_setup", autouse=True)
|
|
||||||
def bypass_setup_fixture(request):
|
|
||||||
"""Mock component setup."""
|
|
||||||
if "no_bypass_setup" in request.keywords:
|
|
||||||
yield
|
|
||||||
else:
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.synology_dsm.async_setup_entry", return_value=True
|
|
||||||
):
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_dsm")
|
@pytest.fixture(name="mock_dsm")
|
||||||
|
@ -146,6 +146,7 @@ def mock_controller_service_failed():
|
|||||||
yield dsm
|
yield dsm
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
async def test_user(hass: HomeAssistant, service: MagicMock):
|
async def test_user(hass: HomeAssistant, service: MagicMock):
|
||||||
"""Test user config."""
|
"""Test user config."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -217,6 +218,7 @@ async def test_user(hass: HomeAssistant, service: MagicMock):
|
|||||||
assert result["data"].get(CONF_VOLUMES) is None
|
assert result["data"].get(CONF_VOLUMES) is None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
async def test_user_2sa(hass: HomeAssistant, service_2sa: MagicMock):
|
async def test_user_2sa(hass: HomeAssistant, service_2sa: MagicMock):
|
||||||
"""Test user with 2sa authentication config."""
|
"""Test user with 2sa authentication config."""
|
||||||
with patch(
|
with patch(
|
||||||
@ -269,6 +271,7 @@ async def test_user_2sa(hass: HomeAssistant, service_2sa: MagicMock):
|
|||||||
assert result["data"].get(CONF_VOLUMES) is None
|
assert result["data"].get(CONF_VOLUMES) is None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
async def test_user_vdsm(hass: HomeAssistant, service_vdsm: MagicMock):
|
async def test_user_vdsm(hass: HomeAssistant, service_vdsm: MagicMock):
|
||||||
"""Test user config."""
|
"""Test user config."""
|
||||||
with patch(
|
with patch(
|
||||||
@ -313,6 +316,7 @@ async def test_user_vdsm(hass: HomeAssistant, service_vdsm: MagicMock):
|
|||||||
assert result["data"].get(CONF_VOLUMES) is None
|
assert result["data"].get(CONF_VOLUMES) is None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
async def test_reauth(hass: HomeAssistant, service: MagicMock):
|
async def test_reauth(hass: HomeAssistant, service: MagicMock):
|
||||||
"""Test reauthentication."""
|
"""Test reauthentication."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
@ -362,6 +366,7 @@ async def test_reauth(hass: HomeAssistant, service: MagicMock):
|
|||||||
assert result["reason"] == "reauth_successful"
|
assert result["reason"] == "reauth_successful"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
async def test_reconfig_user(hass: HomeAssistant, service: MagicMock):
|
async def test_reconfig_user(hass: HomeAssistant, service: MagicMock):
|
||||||
"""Test re-configuration of already existing entry by user."""
|
"""Test re-configuration of already existing entry by user."""
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
@ -390,6 +395,7 @@ async def test_reconfig_user(hass: HomeAssistant, service: MagicMock):
|
|||||||
assert result["reason"] == "reconfigure_successful"
|
assert result["reason"] == "reconfigure_successful"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
async def test_login_failed(hass: HomeAssistant, service: MagicMock):
|
async def test_login_failed(hass: HomeAssistant, service: MagicMock):
|
||||||
"""Test when we have errors during login."""
|
"""Test when we have errors during login."""
|
||||||
service.return_value.login = Mock(
|
service.return_value.login = Mock(
|
||||||
@ -405,6 +411,7 @@ async def test_login_failed(hass: HomeAssistant, service: MagicMock):
|
|||||||
assert result["errors"] == {CONF_USERNAME: "invalid_auth"}
|
assert result["errors"] == {CONF_USERNAME: "invalid_auth"}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
async def test_connection_failed(hass: HomeAssistant, service: MagicMock):
|
async def test_connection_failed(hass: HomeAssistant, service: MagicMock):
|
||||||
"""Test when we have errors during connection."""
|
"""Test when we have errors during connection."""
|
||||||
service.return_value.login = Mock(
|
service.return_value.login = Mock(
|
||||||
@ -421,6 +428,7 @@ async def test_connection_failed(hass: HomeAssistant, service: MagicMock):
|
|||||||
assert result["errors"] == {CONF_HOST: "cannot_connect"}
|
assert result["errors"] == {CONF_HOST: "cannot_connect"}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
async def test_unknown_failed(hass: HomeAssistant, service: MagicMock):
|
async def test_unknown_failed(hass: HomeAssistant, service: MagicMock):
|
||||||
"""Test when we have an unknown error."""
|
"""Test when we have an unknown error."""
|
||||||
service.return_value.login = Mock(side_effect=SynologyDSMException(None, None))
|
service.return_value.login = Mock(side_effect=SynologyDSMException(None, None))
|
||||||
@ -435,6 +443,7 @@ async def test_unknown_failed(hass: HomeAssistant, service: MagicMock):
|
|||||||
assert result["errors"] == {"base": "unknown"}
|
assert result["errors"] == {"base": "unknown"}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
async def test_missing_data_after_login(hass: HomeAssistant, service_failed: MagicMock):
|
async def test_missing_data_after_login(hass: HomeAssistant, service_failed: MagicMock):
|
||||||
"""Test when we have errors during connection."""
|
"""Test when we have errors during connection."""
|
||||||
with patch(
|
with patch(
|
||||||
@ -450,6 +459,7 @@ async def test_missing_data_after_login(hass: HomeAssistant, service_failed: Mag
|
|||||||
assert result["errors"] == {"base": "missing_data"}
|
assert result["errors"] == {"base": "missing_data"}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
async def test_form_ssdp(hass: HomeAssistant, service: MagicMock):
|
async def test_form_ssdp(hass: HomeAssistant, service: MagicMock):
|
||||||
"""Test we can setup from ssdp."""
|
"""Test we can setup from ssdp."""
|
||||||
|
|
||||||
@ -493,6 +503,7 @@ async def test_form_ssdp(hass: HomeAssistant, service: MagicMock):
|
|||||||
assert result["data"].get(CONF_VOLUMES) is None
|
assert result["data"].get(CONF_VOLUMES) is None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
async def test_reconfig_ssdp(hass: HomeAssistant, service: MagicMock):
|
async def test_reconfig_ssdp(hass: HomeAssistant, service: MagicMock):
|
||||||
"""Test re-configuration of already existing entry by ssdp."""
|
"""Test re-configuration of already existing entry by ssdp."""
|
||||||
|
|
||||||
@ -525,6 +536,7 @@ async def test_reconfig_ssdp(hass: HomeAssistant, service: MagicMock):
|
|||||||
assert result["reason"] == "reconfigure_successful"
|
assert result["reason"] == "reconfigure_successful"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
async def test_skip_reconfig_ssdp(hass: HomeAssistant, service: MagicMock):
|
async def test_skip_reconfig_ssdp(hass: HomeAssistant, service: MagicMock):
|
||||||
"""Test re-configuration of already existing entry by ssdp."""
|
"""Test re-configuration of already existing entry by ssdp."""
|
||||||
|
|
||||||
@ -557,6 +569,7 @@ async def test_skip_reconfig_ssdp(hass: HomeAssistant, service: MagicMock):
|
|||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
async def test_existing_ssdp(hass: HomeAssistant, service: MagicMock):
|
async def test_existing_ssdp(hass: HomeAssistant, service: MagicMock):
|
||||||
"""Test abort of already existing entry by ssdp."""
|
"""Test abort of already existing entry by ssdp."""
|
||||||
|
|
||||||
@ -589,6 +602,7 @@ async def test_existing_ssdp(hass: HomeAssistant, service: MagicMock):
|
|||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
async def test_options_flow(hass: HomeAssistant, service: MagicMock):
|
async def test_options_flow(hass: HomeAssistant, service: MagicMock):
|
||||||
"""Test config flow options."""
|
"""Test config flow options."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
@ -632,6 +646,7 @@ async def test_options_flow(hass: HomeAssistant, service: MagicMock):
|
|||||||
assert config_entry.options[CONF_SNAPSHOT_QUALITY] == 0
|
assert config_entry.options[CONF_SNAPSHOT_QUALITY] == 0
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
async def test_discovered_via_zeroconf(hass: HomeAssistant, service: MagicMock):
|
async def test_discovered_via_zeroconf(hass: HomeAssistant, service: MagicMock):
|
||||||
"""Test we can setup from zeroconf."""
|
"""Test we can setup from zeroconf."""
|
||||||
|
|
||||||
@ -677,6 +692,7 @@ async def test_discovered_via_zeroconf(hass: HomeAssistant, service: MagicMock):
|
|||||||
assert result["data"].get(CONF_VOLUMES) is None
|
assert result["data"].get(CONF_VOLUMES) is None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_setup_entry")
|
||||||
async def test_discovered_via_zeroconf_missing_mac(
|
async def test_discovered_via_zeroconf_missing_mac(
|
||||||
hass: HomeAssistant, service: MagicMock
|
hass: HomeAssistant, service: MagicMock
|
||||||
):
|
):
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
"""Tests for the Synology DSM component."""
|
"""Tests for the Synology DSM component."""
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
|
||||||
from synology_dsm.exceptions import SynologyDSMLoginInvalidException
|
from synology_dsm.exceptions import SynologyDSMLoginInvalidException
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
@ -21,7 +20,6 @@ from .consts import HOST, MACS, PASSWORD, PORT, USE_SSL, USERNAME
|
|||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.no_bypass_setup
|
|
||||||
async def test_services_registered(hass: HomeAssistant, mock_dsm: MagicMock):
|
async def test_services_registered(hass: HomeAssistant, mock_dsm: MagicMock):
|
||||||
"""Test if all services are registered."""
|
"""Test if all services are registered."""
|
||||||
with patch(
|
with patch(
|
||||||
@ -45,7 +43,6 @@ async def test_services_registered(hass: HomeAssistant, mock_dsm: MagicMock):
|
|||||||
assert hass.services.has_service(DOMAIN, service)
|
assert hass.services.has_service(DOMAIN, service)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.no_bypass_setup
|
|
||||||
async def test_reauth_triggered(hass: HomeAssistant):
|
async def test_reauth_triggered(hass: HomeAssistant):
|
||||||
"""Test if reauthentication flow is triggered."""
|
"""Test if reauthentication flow is triggered."""
|
||||||
with patch(
|
with patch(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user