kiwi/tests/services/community/test_mdns.py
pyr0ball c18bfec8f5
Some checks are pending
CI / Backend (Python) (push) Waiting to run
CI / Frontend (Vue) (push) Waiting to run
Mirror / mirror (push) Waiting to run
fix(lint): add ruff config, fix all lint errors for GitHub CI
- pyproject.toml: add [tool.ruff] config suppressing E402/W293 globally,
  F841/E741/E702 in tests, E741 in scripts
- inventory.py: split semicolon import (E702)
- recipes.py: fix logger -> log (F821 undefined name)
- shopping.py: rename l -> lnk in list comprehension (E741)
- format_conversion.py: noqa F841 on CUDA flag (used as future hook)
- backfill_keywords.py: rename done -> _done (F841)
- ingest_purplecarrot.py: drop == True comparison (E712)
- Auto-fix: I001 import sorting, F401 unused imports across all files
2026-07-06 02:49:02 -07:00

39 lines
1.6 KiB
Python

# tests/services/community/test_mdns.py
from unittest.mock import MagicMock, patch
from app.services.community.mdns import KiwiMDNS
def test_mdns_does_not_advertise_when_disabled():
"""When enabled=False, KiwiMDNS does not register any zeroconf service."""
with patch("app.services.community.mdns.Zeroconf") as mock_zc:
mdns = KiwiMDNS(enabled=False, port=8512, feed_url="http://localhost:8512/api/v1/community/local-feed")
mdns.start()
mock_zc.assert_not_called()
def test_mdns_advertises_when_enabled():
with patch("app.services.community.mdns.Zeroconf") as mock_zc_cls:
with patch("app.services.community.mdns.ServiceInfo") as mock_si:
mock_zc = MagicMock()
mock_zc_cls.return_value = mock_zc
mdns = KiwiMDNS(enabled=True, port=8512, feed_url="http://localhost:8512/api/v1/community/local-feed")
mdns.start()
mock_zc.register_service.assert_called_once()
def test_mdns_stop_unregisters_when_enabled():
with patch("app.services.community.mdns.Zeroconf") as mock_zc_cls:
with patch("app.services.community.mdns.ServiceInfo"):
mock_zc = MagicMock()
mock_zc_cls.return_value = mock_zc
mdns = KiwiMDNS(enabled=True, port=8512, feed_url="http://localhost:8512/api/v1/community/local-feed")
mdns.start()
mdns.stop()
mock_zc.unregister_service.assert_called_once()
mock_zc.close.assert_called_once()
def test_mdns_stop_is_noop_when_not_started():
mdns = KiwiMDNS(enabled=False, port=8512, feed_url="http://localhost/feed")
mdns.stop() # must not raise