Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set terminals_available to False when not enabled #105

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions jupyter_server_terminals/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
(
Expand Down
13 changes: 13 additions & 0 deletions tests/test_disable_app.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tests/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading