async def test_close(self, mock_interaction_server: interaction_server_impl.InteractionServer): mock_runner = mock.AsyncMock() mock_event = mock.Mock() mock_interaction_server._is_closing = False mock_interaction_server._server = mock_runner mock_interaction_server._close_event = mock_event await mock_interaction_server.close() mock_runner.shutdown.assert_awaited_once() mock_runner.cleanup.assert_awaited_once() mock_event.set.assert_called_once() assert mock_interaction_server._is_closing is True
async def test_close_when_closing(self, mock_interaction_server: interaction_server_impl.InteractionServer): mock_runner = mock.AsyncMock() mock_event = mock.Mock() mock_interaction_server._server = mock_runner mock_interaction_server._close_event = mock_event mock_interaction_server._is_closing = True mock_interaction_server.join = mock.AsyncMock() await mock_interaction_server.close() mock_runner.shutdown.assert_not_called() mock_runner.cleanup.assert_not_called() mock_event.set.assert_not_called() mock_interaction_server.join.assert_awaited_once()
async def test_start(self, mock_interaction_server: interaction_server_impl.InteractionServer): mock_context = object() mock_socket = object() mock_interaction_server._is_closing = True stack = contextlib.ExitStack() stack.enter_context(mock.patch.object(aiohttp.web, "TCPSite", return_value=mock.AsyncMock())) stack.enter_context(mock.patch.object(aiohttp.web, "UnixSite", return_value=mock.AsyncMock())) stack.enter_context(mock.patch.object(aiohttp.web, "SockSite", return_value=mock.AsyncMock())) stack.enter_context(mock.patch.object(aiohttp.web_runner, "AppRunner", return_value=mock.AsyncMock())) stack.enter_context(mock.patch.object(aiohttp.web, "Application")) stack.enter_context(mock.patch.object(asyncio, "Event")) with stack: await mock_interaction_server.start( backlog=123123, enable_signal_handlers=False, host="hoototototo", port=123123123, path="hshshshshsh", reuse_address=True, reuse_port=False, socket=mock_socket, shutdown_timeout=3232.3232, ssl_context=mock_context, ) aiohttp.web.Application.assert_called_once_with() aiohttp.web.Application.return_value.add_routes.assert_called_once_with( [aiohttp.web.post("/", mock_interaction_server.aiohttp_hook)] ) aiohttp.web_runner.AppRunner.assert_called_once_with( aiohttp.web.Application.return_value, handle_signals=False, access_log=interaction_server_impl._LOGGER ) aiohttp.web_runner.AppRunner.return_value.setup.assert_awaited_once() aiohttp.web.TCPSite.assert_called_once_with( aiohttp.web_runner.AppRunner.return_value, "hoototototo", 123123123, shutdown_timeout=3232.3232, ssl_context=mock_context, backlog=123123, reuse_address=True, reuse_port=False, ) aiohttp.web.UnixSite.assert_called_once_with( aiohttp.web_runner.AppRunner.return_value, "hshshshshsh", shutdown_timeout=3232.3232, ssl_context=mock_context, backlog=123123, ) aiohttp.web.SockSite.assert_called_once_with( aiohttp.web_runner.AppRunner.return_value, mock_socket, shutdown_timeout=3232.3232, ssl_context=mock_context, backlog=123123, ) aiohttp.web.TCPSite.return_value.start.assert_awaited_once() aiohttp.web.UnixSite.return_value.start.assert_awaited_once() aiohttp.web.SockSite.return_value.start.assert_awaited_once() assert mock_interaction_server._close_event is asyncio.Event.return_value assert mock_interaction_server._is_closing is False