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

Make trust handle use ensure_async #373

Merged
merged 3 commits into from
Jan 5, 2021
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
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