2024-06-13 22:52:19 +02:00
|
|
|
"""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(
|
2024-06-13 22:52:19 +02:00
|
|
|
{
|
|
|
|
"_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(
|
2024-06-13 22:52:19 +02:00
|
|
|
{
|
|
|
|
"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
|
|
|
|
2024-06-21 15:57:36 +02:00
|
|
|
client.free_space.return_value = 99999999999
|
2024-06-13 22:52:19 +02:00
|
|
|
yield client
|