hass-core/tests/components/pyload/conftest.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
2 KiB
Python
Raw Normal View History

"""Fixtures for pyLoad integration tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
from pyloadapi.types import LoginResponse, StatusServerResponse
import pytest
from homeassistant.const import (
CONF_HOST,
CONF_MONITORED_VARIABLES,
CONF_NAME,
CONF_PASSWORD,
CONF_PLATFORM,
CONF_PORT,
CONF_SSL,
CONF_USERNAME,
)
from homeassistant.helpers.typing import ConfigType
@pytest.fixture
def pyload_config() -> ConfigType:
"""Mock pyload configuration entry."""
return {
"sensor": {
CONF_PLATFORM: "pyload",
CONF_HOST: "localhost",
CONF_PORT: 8000,
CONF_USERNAME: "username",
CONF_PASSWORD: "password",
CONF_SSL: True,
CONF_MONITORED_VARIABLES: ["speed"],
CONF_NAME: "pyload",
}
}
@pytest.fixture
def mock_pyloadapi() -> Generator[AsyncMock, None, None]:
"""Mock PyLoadAPI."""
with (
patch(
"homeassistant.components.pyload.sensor.PyLoadAPI",
autospec=True,
) as mock_client,
):
client = mock_client.return_value
client.username = "username"
2024-06-23 04:22:13 +02:00
client.login.return_value = LoginResponse(
{
"_permanent": True,
"authenticated": True,
"id": 2,
"name": "username",
"role": 0,
"perms": 0,
"template": "default",
"_flashes": [["message", "Logged in successfully"]],
}
)
2024-06-23 04:22:13 +02:00
client.get_status.return_value = StatusServerResponse(
{
"pause": False,
"active": 1,
"queue": 6,
"total": 37,
"speed": 5405963.0,
"download": True,
"reconnect": False,
"captcha": False,
}
)
2024-06-23 04:22:13 +02:00
client.free_space.return_value = 99999999999
yield client