def __init__(self, server: Server) -> None: self.server = server self.klippy: Klippy = server.lookup_component("klippy_connection") self.websockets: Dict[int, WebSocket] = {} self.rpc = JsonRPC() self.closed_event: Optional[asyncio.Event] = None self.rpc.register_method("server.websocket.id", self._handle_id_request) self.rpc.register_method("server.connection.identify", self._handle_identify)
async def test_notification(self, base_server: Server): base_server.register_notification("test:test_event") fut = base_server.event_loop.create_future() wsm = base_server.lookup_component("websockets") wsm.websockets[1] = MockWebsocket(fut) base_server.send_event("test:test_event", "test") ret = await fut expected = { 'jsonrpc': "2.0", 'method': "notify_test_event", 'params': ["test"] } assert expected == ret
def test_http_servers(self, server: Server): app = server.lookup_component("application") assert (app.http_server is not None and app.secure_server is not None)
def test_lookup_components(self, full_server: Server): comps = [] for comp_name in CORE_COMPONENTS: comps.append(full_server.lookup_component(comp_name, None)) assert None not in comps
def test_lookup_component(self, base_server: Server): comp = base_server.lookup_component('klippy_apis') assert isinstance(comp, KlippyAPI)
def test_lookup_failed_with_default(self, base_server: Server): comp = base_server.lookup_component("invalid_component", None) assert comp is None
def test_lookup_failed(self, base_server: Server): with pytest.raises(ServerError): base_server.lookup_component("invalid_component")