Skip to content

Commit 60c66b6

Browse files
authored
Merge pull request jupyter-server#373 from jupyter-server/ensure-trust-async
Make trust handle use ensure_async
2 parents 00a6e25 + ee6c909 commit 60c66b6

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

jupyter_server/services/contents/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class TrustNotebooksHandler(JupyterHandler):
294294
@web.authenticated
295295
async def post(self,path=''):
296296
cm = self.contents_manager
297-
await cm.trust_notebook(path)
297+
await ensure_async(cm.trust_notebook(path))
298298
self.set_status(201)
299299
self.finish()
300300
#-----------------------------------------------------------------------------

tests/services/contents/test_api.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ def contents_dir(tmp_path, jp_serverapp):
5454
@pytest.fixture
5555
def contents(contents_dir):
5656
# Create files in temporary directory
57+
paths = {
58+
'notebooks': [],
59+
'textfiles': [],
60+
'blobs': [],
61+
}
5762
for d, name in dirs:
5863
p = contents_dir / d
5964
p.mkdir(parents=True, exist_ok=True)
@@ -62,16 +67,21 @@ def contents(contents_dir):
6267
nb = writes(new_notebook(), version=4)
6368
nbname = p.joinpath('{}.ipynb'.format(name))
6469
nbname.write_text(nb, encoding='utf-8')
70+
paths['notebooks'].append(nbname.relative_to(contents_dir))
6571

6672
# Create a text file
6773
txt = '{} text file'.format(name)
6874
txtname = p.joinpath('{}.txt'.format(name))
6975
txtname.write_text(txt, encoding='utf-8')
76+
paths['textfiles'].append(txtname.relative_to(contents_dir))
7077

7178
# Create a random blob
7279
blob = name.encode('utf-8') + b'\xFF'
7380
blobname = p.joinpath('{}.blob'.format(name))
7481
blobname.write_bytes(blob)
82+
paths['blobs'].append(blobname.relative_to(contents_dir))
83+
paths['all'] = list(paths.values())
84+
return paths
7585

7686

7787
@pytest.fixture
@@ -845,3 +855,14 @@ async def test_file_checkpoints(jp_fetch, contents):
845855
)
846856
cps = json.loads(r.body.decode())
847857
assert cps == []
858+
859+
860+
async def test_trust(jp_fetch, contents):
861+
# It should be able to trust a notebook that exists
862+
for path in contents['notebooks']:
863+
r = await jp_fetch(
864+
'api', 'contents', str(path), 'trust',
865+
method='POST',
866+
allow_nonstandard_methods=True
867+
)
868+
assert r.code == 201

0 commit comments

Comments
 (0)