Add more Python tests (#6639)

pull/6640/head
Steven Silvester 3 years ago committed by GitHub
parent 581f98c38f
commit 778ecc5551
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,4 +1,9 @@
import os
import pytest
from tornado.httpclient import HTTPClientError
from notebook.app import JupyterNotebookApp, TreeHandler
@pytest.fixture
@ -21,11 +26,68 @@ async def test_notebook_handler(notebooks, jp_fetch):
html = r.body.decode()
assert "Jupyter Notebook" in html
r = await jp_fetch("/notebooks", nbpath)
assert r.code == 200
# Check that the lab template is loaded
html = r.body.decode()
assert "Jupyter Notebook" in html
async def test_tree_handler(notebooks, jp_fetch):
async def test_tree_handler(notebooks, notebookapp, jp_fetch):
app: JupyterNotebookApp = notebookapp
r = await jp_fetch("tree", "jlab_test_notebooks")
assert r.code == 200
# Check that the tree template is loaded
html = r.body.decode()
assert "- Tree</title>" in html
redirected_url = None
def redirect(self, url):
nonlocal redirected_url
redirected_url = url
TreeHandler.redirect = redirect
await jp_fetch("tree", "notebook1.ipynb")
assert redirected_url == "/a%40b/notebooks/notebook1.ipynb"
with open(os.path.join(app.serverapp.root_dir, "foo.txt"), "w") as fid:
fid.write("hello")
await jp_fetch("tree", "foo.txt")
assert redirected_url == "/a%40b/files/foo.txt"
with pytest.raises(HTTPClientError):
await jp_fetch("tree", "does_not_exist.ipynb")
async def test_console_handler(notebookapp, jp_fetch):
r = await jp_fetch("consoles", "foo")
assert r.code == 200
html = r.body.decode()
assert "- Console</title>" in html
async def test_terminals_handler(notebookapp, jp_fetch):
r = await jp_fetch("terminals", "foo")
assert r.code == 200
html = r.body.decode()
assert "- Terminal</title>" in html
async def test_edit_handler(notebooks, jp_fetch):
r = await jp_fetch("edit", "notebook1.ipynb")
assert r.code == 200
html = r.body.decode()
assert "- Edit</title>" in html
async def test_app(notebookapp):
app: JupyterNotebookApp = notebookapp
assert app.static_dir
assert app.templates_dir
assert app.app_settings_dir
assert app.schemas_dir
assert app.user_settings_dir
assert app.workspaces_dir

Loading…
Cancel
Save