Skip to content

Commit 778ecc5

Browse files
authored
Add more Python tests (#6639)
1 parent 581f98c commit 778ecc5

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

tests/test_app.py

+63-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
import os
2+
13
import pytest
4+
from tornado.httpclient import HTTPClientError
5+
6+
from notebook.app import JupyterNotebookApp, TreeHandler
27

38

49
@pytest.fixture
@@ -21,11 +26,68 @@ async def test_notebook_handler(notebooks, jp_fetch):
2126
html = r.body.decode()
2227
assert "Jupyter Notebook" in html
2328

29+
r = await jp_fetch("/notebooks", nbpath)
30+
assert r.code == 200
31+
# Check that the lab template is loaded
32+
html = r.body.decode()
33+
assert "Jupyter Notebook" in html
34+
2435

25-
async def test_tree_handler(notebooks, jp_fetch):
36+
async def test_tree_handler(notebooks, notebookapp, jp_fetch):
37+
app: JupyterNotebookApp = notebookapp
2638
r = await jp_fetch("tree", "jlab_test_notebooks")
2739
assert r.code == 200
2840

2941
# Check that the tree template is loaded
3042
html = r.body.decode()
3143
assert "- Tree</title>" in html
44+
45+
redirected_url = None
46+
47+
def redirect(self, url):
48+
nonlocal redirected_url
49+
redirected_url = url
50+
51+
TreeHandler.redirect = redirect
52+
await jp_fetch("tree", "notebook1.ipynb")
53+
assert redirected_url == "/a%40b/notebooks/notebook1.ipynb"
54+
55+
with open(os.path.join(app.serverapp.root_dir, "foo.txt"), "w") as fid:
56+
fid.write("hello")
57+
58+
await jp_fetch("tree", "foo.txt")
59+
assert redirected_url == "/a%40b/files/foo.txt"
60+
61+
with pytest.raises(HTTPClientError):
62+
await jp_fetch("tree", "does_not_exist.ipynb")
63+
64+
65+
async def test_console_handler(notebookapp, jp_fetch):
66+
r = await jp_fetch("consoles", "foo")
67+
assert r.code == 200
68+
html = r.body.decode()
69+
assert "- Console</title>" in html
70+
71+
72+
async def test_terminals_handler(notebookapp, jp_fetch):
73+
r = await jp_fetch("terminals", "foo")
74+
assert r.code == 200
75+
html = r.body.decode()
76+
assert "- Terminal</title>" in html
77+
78+
79+
async def test_edit_handler(notebooks, jp_fetch):
80+
r = await jp_fetch("edit", "notebook1.ipynb")
81+
assert r.code == 200
82+
html = r.body.decode()
83+
assert "- Edit</title>" in html
84+
85+
86+
async def test_app(notebookapp):
87+
app: JupyterNotebookApp = notebookapp
88+
assert app.static_dir
89+
assert app.templates_dir
90+
assert app.app_settings_dir
91+
assert app.schemas_dir
92+
assert app.user_settings_dir
93+
assert app.workspaces_dir

0 commit comments

Comments
 (0)