Skip to content

Commit

Permalink
Merge pull request #373 from jupyter-server/ensure-trust-async
Browse files Browse the repository at this point in the history
Make trust handle use ensure_async
  • Loading branch information
kevin-bates authored Jan 5, 2021
2 parents 00a6e25 + ee6c909 commit 60c66b6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jupyter_server/services/contents/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class TrustNotebooksHandler(JupyterHandler):
@web.authenticated
async def post(self,path=''):
cm = self.contents_manager
await cm.trust_notebook(path)
await ensure_async(cm.trust_notebook(path))
self.set_status(201)
self.finish()
#-----------------------------------------------------------------------------
Expand Down
21 changes: 21 additions & 0 deletions tests/services/contents/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def contents_dir(tmp_path, jp_serverapp):
@pytest.fixture
def contents(contents_dir):
# Create files in temporary directory
paths = {
'notebooks': [],
'textfiles': [],
'blobs': [],
}
for d, name in dirs:
p = contents_dir / d
p.mkdir(parents=True, exist_ok=True)
Expand All @@ -62,16 +67,21 @@ def contents(contents_dir):
nb = writes(new_notebook(), version=4)
nbname = p.joinpath('{}.ipynb'.format(name))
nbname.write_text(nb, encoding='utf-8')
paths['notebooks'].append(nbname.relative_to(contents_dir))

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

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


@pytest.fixture
Expand Down Expand Up @@ -845,3 +855,14 @@ async def test_file_checkpoints(jp_fetch, contents):
)
cps = json.loads(r.body.decode())
assert cps == []


async def test_trust(jp_fetch, contents):
# It should be able to trust a notebook that exists
for path in contents['notebooks']:
r = await jp_fetch(
'api', 'contents', str(path), 'trust',
method='POST',
allow_nonstandard_methods=True
)
assert r.code == 201

0 comments on commit 60c66b6

Please sign in to comment.