"""Tests for the connector registry.""" from __future__ import annotations import pytest from app.scouts.connectors.base import ItemRef from app.scouts.connectors.registry import ( get_connector, register_connector, _reset_for_tests, ) class _DummyConnector: source_type = "dummy" async def list_new(self, scout): return [] async def fetch_metadata(self, scout, ref): raise NotImplementedError async def fetch_content(self, scout, ref): raise NotImplementedError async def archive(self, scout, ref): raise NotImplementedError async def setup_watch(self, scout): raise NotImplementedError async def renew_watch(self, scout): raise NotImplementedError @pytest.fixture(autouse=True) def _clean_registry(): _reset_for_tests() yield _reset_for_tests() def test_register_and_get(): c = _DummyConnector() register_connector(c) assert get_connector("dummy") is c def test_unknown_source_raises(): with pytest.raises(KeyError): get_connector("nope") def test_double_register_replaces(): a = _DummyConnector() b = _DummyConnector() register_connector(a) register_connector(b) assert get_connector("dummy") is b