File: test_tree_handler.py

package info (click to toggle)
jupyter-notebook 4.2.3-4~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 7,804 kB
  • sloc: python: 8,698; makefile: 240; sh: 74
file content (32 lines) | stat: -rw-r--r-- 1,021 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""Test the /tree handlers"""
import os
import io
from notebook.utils import url_path_join
from nbformat import write
from nbformat.v4 import new_notebook

import requests

from notebook.tests.launchnotebook import NotebookTestBase

class TreeTest(NotebookTestBase):
    def setUp(self):
        nbdir = self.notebook_dir.name
        d = os.path.join(nbdir, 'foo')
        os.mkdir(d)

        with io.open(os.path.join(d, 'bar.ipynb'), 'w', encoding='utf-8') as f:
            nb = new_notebook()
            write(nb, f, version=4)

        with io.open(os.path.join(d, 'baz.txt'), 'w', encoding='utf-8') as f:
            f.write(u'flamingo')

        self.base_url()

    def test_redirect(self):
        r = requests.get(url_path_join(self.base_url(), 'tree/foo/bar.ipynb'))
        self.assertEqual(r.url, self.base_url() + 'notebooks/foo/bar.ipynb')

        r = requests.get(url_path_join(self.base_url(), 'tree/foo/baz.txt'))
        self.assertEqual(r.url, url_path_join(self.base_url(), 'files/foo/baz.txt'))