Skip to content

Commit 9b04bb4

Browse files
committed
Don't validate preferred_dir trait
1 parent 93d6f1a commit 9b04bb4

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

jupyter_server/services/contents/manager.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,6 @@ def emit(self, data):
8383
),
8484
)
8585

86-
@validate("preferred_dir")
87-
def _validate_preferred_dir(self, proposal):
88-
value = proposal["value"]
89-
try:
90-
dir_exists = self.dir_exists(value)
91-
except HTTPError as e:
92-
raise TraitError(e.log_message) from e
93-
if not dir_exists:
94-
raise TraitError(_i18n("Preferred directory not found: %r") % value)
95-
return value
96-
9786
allow_hidden = Bool(False, config=True, help="Allow access to hidden files")
9887

9988
notary = Instance(sign.NotebookNotary)

tests/test_serverapp.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import pytest
88
from jupyter_core.application import NoStart
9+
from tornado.web import HTTPError
910
from traitlets import TraitError
1011
from traitlets.tests.utils import check_help_all_output
1112

@@ -379,28 +380,30 @@ def test_invalid_preferred_dir_not_root_subdir(tmp_path, jp_configurable_servera
379380
jp_configurable_serverapp(root_dir=path, preferred_dir=not_subdir_path)
380381

381382

382-
def test_invalid_preferred_dir_not_root_subdir_set(tmp_path, jp_configurable_serverapp):
383+
async def test_invalid_preferred_dir_not_root_subdir_set(tmp_path, jp_configurable_serverapp):
383384
path = str(tmp_path / "subdir")
384385
os.makedirs(path, exist_ok=True)
385386
not_subdir_path = os.path.relpath(tmp_path, path)
386387

387388
app = jp_configurable_serverapp(root_dir=path)
388-
with pytest.raises(TraitError) as error:
389+
with pytest.raises(HTTPError) as error:
389390
app.contents_manager.preferred_dir = not_subdir_path
391+
await app.contents_manager.dir_exists(app.contents_manager.preferred_dir)
390392

391-
assert "is outside root contents directory" in str(error)
393+
assert "is outside root contents directory" in str(error.value)
392394

393395

394-
def test_absolute_preferred_dir_not_root_subdir_set(tmp_path, jp_configurable_serverapp):
396+
async def test_absolute_preferred_dir_not_root_subdir_set(tmp_path, jp_configurable_serverapp):
395397
path = str(tmp_path / "subdir")
396398
os.makedirs(path, exist_ok=True)
397399
not_subdir_path = str(tmp_path)
398400

399-
with pytest.raises(TraitError) as error:
401+
with pytest.raises(HTTPError) as error:
400402
app = jp_configurable_serverapp(root_dir=path)
401403
app.contents_manager.preferred_dir = not_subdir_path
404+
await app.contents_manager.dir_exists(app.contents_manager.preferred_dir)
402405

403406
if os.name == "nt":
404-
assert "is not a relative API path" in str(error)
407+
assert "is not a relative API path" in str(error.value)
405408
else:
406-
assert "Preferred directory not found" in str(error)
409+
assert "Preferred directory not found" in str(error.value)

0 commit comments

Comments
 (0)