diff --git a/jupyter_server_terminals/app.py b/jupyter_server_terminals/app.py index 8ccbc4f..e10a5b4 100644 --- a/jupyter_server_terminals/app.py +++ b/jupyter_server_terminals/app.py @@ -37,6 +37,7 @@ class TerminalsExtensionApp(ExtensionApp): def initialize_settings(self) -> None: """Initialize settings.""" if not self.serverapp or not self.serverapp.terminals_enabled: + self.settings.update({"terminals_available": False}) return self.initialize_configurables() self.settings.update( @@ -73,8 +74,15 @@ def initialize_configurables(self) -> None: def initialize_handlers(self) -> None: """Initialize handlers.""" - if not self.serverapp or not self.serverapp.terminals_enabled: - # Checking self.terminals_available instead breaks enabling terminals + if not self.serverapp: + # Already set `terminals_available` as `False` in `initialize_settings` + return + + if not self.serverapp.terminals_enabled: + # webapp settings for backwards compat (used by nbclassic), #12 + self.serverapp.web_app.settings["terminals_available"] = self.settings[ + "terminals_available" + ] return self.handlers.append( ( diff --git a/tests/test_disable_app.py b/tests/test_disable_app.py new file mode 100644 index 0000000..6538602 --- /dev/null +++ b/tests/test_disable_app.py @@ -0,0 +1,13 @@ +import pytest +from traitlets.config.loader import Config + + +@pytest.fixture() +def jp_server_config(): + return Config({"ServerApp": {"terminals_enabled": False}}) + + +async def test_not_enabled(jp_configurable_serverapp): + assert jp_configurable_serverapp().terminals_enabled is False + assert jp_configurable_serverapp().web_app.settings["terminals_available"] is False + assert "terminal_manager" not in jp_configurable_serverapp().web_app.settings diff --git a/tests/test_terminal.py b/tests/test_terminal.py index 6516eb7..ef96907 100644 --- a/tests/test_terminal.py +++ b/tests/test_terminal.py @@ -236,6 +236,12 @@ async def test_terminal_create_with_bad_cwd(jp_fetch, jp_ws_fetch): assert non_existing_path not in message_stdout +async def test_app_config(jp_configurable_serverapp): + assert jp_configurable_serverapp().terminals_enabled is True + assert jp_configurable_serverapp().web_app.settings["terminals_available"] is True + assert jp_configurable_serverapp().web_app.settings["terminal_manager"] + + async def test_culling_config(jp_configurable_serverapp): terminal_mgr_config = jp_configurable_serverapp().config.ServerApp.TerminalManager assert terminal_mgr_config.cull_inactive_timeout == CULL_TIMEOUT