1
+ import os
2
+
1
3
import pytest
4
+ from tornado .httpclient import HTTPClientError
5
+
6
+ from notebook .app import JupyterNotebookApp , TreeHandler
2
7
3
8
4
9
@pytest .fixture
@@ -21,11 +26,68 @@ async def test_notebook_handler(notebooks, jp_fetch):
21
26
html = r .body .decode ()
22
27
assert "Jupyter Notebook" in html
23
28
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
+
24
35
25
- async def test_tree_handler (notebooks , jp_fetch ):
36
+ async def test_tree_handler (notebooks , notebookapp , jp_fetch ):
37
+ app : JupyterNotebookApp = notebookapp
26
38
r = await jp_fetch ("tree" , "jlab_test_notebooks" )
27
39
assert r .code == 200
28
40
29
41
# Check that the tree template is loaded
30
42
html = r .body .decode ()
31
43
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