import os import pytest from tornado.httpclient import HTTPClientError from notebook.app import JupyterNotebookApp, NotebookHandler, TreeHandler @pytest.fixture def notebooks(jp_create_notebook, notebookapp): nbpaths = ( "notebook1.ipynb", "jlab_test_notebooks/notebook2.ipynb", "jlab_test_notebooks/level2/notebook3.ipynb", ) for nb in nbpaths: jp_create_notebook(nb) return nbpaths async def test_notebook_handler(notebooks, jp_fetch): for nbpath in notebooks: r = await jp_fetch("/", nbpath) assert r.code == 200 # Check that the lab template is loaded 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 redirected_url = None def redirect(self, url): nonlocal redirected_url redirected_url = url NotebookHandler.redirect = redirect await jp_fetch("notebooks", "jlab_test_notebooks") assert redirected_url == "/a%40b/tree/jlab_test_notebooks" 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 "