Files
shelly-ui/tests/test_discovery_scan.py
jonas 71803418e5 Initial commit: Shelly Manager with Textual CLI, Streamlit UI, and comprehensive .gitignore
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.
2026-03-23 21:51:59 +01:00

36 lines
999 B
Python

"""Subnet scan with mocked /shelly responses."""
from __future__ import annotations
from unittest.mock import AsyncMock, patch
import aiohttp
import pytest
@pytest.mark.asyncio
async def test_scan_subnet_finds_shelly() -> None:
async def fetch_impl(
session: aiohttp.ClientSession,
ip: str,
port: int = 80,
timeout_sec: float = 2.0,
):
if ip == "192.168.1.5":
return {"type": "SHSW-21", "mac": "AABBCCDDEEFF", "fw": "1.0"}
return None
with patch(
"shelly_manager.core.discovery.fetch_shelly_json",
new_callable=AsyncMock,
side_effect=fetch_impl,
):
async with aiohttp.ClientSession() as session:
from shelly_manager.core.discovery import scan_subnet_http
results = await scan_subnet_http(session, "192.168.1.0/29", concurrency=8)
ips = {r[0] for r in results}
assert "192.168.1.5" in ips
assert any("AABB" in r[1].get("mac", "") for r in results)