71803418e5
Shelly device management app with mDNS/subnet discovery, inventory, configuration, and mass operations for Gen1/Gen2+ devices. Includes .gitignore excluding runtime data (device DB, user config), AI conversation history, build artifacts, and common Python/OS patterns.
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
"""Discovery helpers: IPv6 URLs, probe port, mDNS task drain (unit-level)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from shelly_manager.core.urls import device_http_url, http_host_for_url
|
|
|
|
|
|
def test_http_host_ipv4_unchanged() -> None:
|
|
assert http_host_for_url("192.168.1.1") == "192.168.1.1"
|
|
|
|
|
|
def test_http_host_ipv6_brackets() -> None:
|
|
assert http_host_for_url("fe80::1") == "[fe80::1]"
|
|
assert http_host_for_url("fe80::1%en0") == "[fe80::1]"
|
|
|
|
|
|
def test_device_http_url_default_port() -> None:
|
|
assert device_http_url("192.168.1.5") == "http://192.168.1.5/"
|
|
|
|
|
|
def test_device_http_url_ipv6_and_port() -> None:
|
|
assert device_http_url("fe80::1", port=8080) == "http://[fe80::1]:8080/"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_probe_ip_passes_port_to_fetch() -> None:
|
|
from shelly_manager.api.client import probe_ip
|
|
|
|
with patch(
|
|
"shelly_manager.api.client.fetch_shelly_json",
|
|
new_callable=AsyncMock,
|
|
) as fetch:
|
|
fetch.return_value = {"type": "SHSW-21", "mac": "AA"}
|
|
session = MagicMock()
|
|
out = await probe_ip(session, "10.0.0.1", port=8080)
|
|
fetch.assert_called_once_with(session, "10.0.0.1", port=8080, timeout_sec=3.0)
|
|
assert out is not None
|
|
assert out[0] == 1
|