Skip to content

Commit

Permalink
Set terminals_available to False when not enabled (#105)
Browse files Browse the repository at this point in the history
* Set terminals_available False when not enabled

* Add some testing on fields

* Update comments
  • Loading branch information
Wh1isper authored Jan 22, 2024
1 parent 93a84aa commit d289632
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
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

0 comments on commit d289632

Please sign in to comment.