Show More
@@ -68,6 +68,8 b' class TestNotebookManager(TestCase):' | |||||
68 | print "Directory already exists." |
|
68 | print "Directory already exists." | |
69 |
|
69 | |||
70 | def test_named_notebook_path(self): |
|
70 | def test_named_notebook_path(self): | |
|
71 | """the `named_notebook_path` method takes a URL path to | |||
|
72 | a notebook and returns a url path split into nb and path""" | |||
71 | nm = NotebookManager() |
|
73 | nm = NotebookManager() | |
72 |
|
74 | |||
73 | # doesn't end with ipynb, should just be path |
|
75 | # doesn't end with ipynb, should just be path | |
@@ -75,26 +77,38 b' class TestNotebookManager(TestCase):' | |||||
75 | self.assertEqual(name, None) |
|
77 | self.assertEqual(name, None) | |
76 | self.assertEqual(path, '/hello/') |
|
78 | self.assertEqual(path, '/hello/') | |
77 |
|
79 | |||
|
80 | # Root path returns just the root slash | |||
78 | name, path = nm.named_notebook_path('/') |
|
81 | name, path = nm.named_notebook_path('/') | |
79 | self.assertEqual(name, None) |
|
82 | self.assertEqual(name, None) | |
80 | self.assertEqual(path, '/') |
|
83 | self.assertEqual(path, '/') | |
81 |
|
84 | |||
82 | name, path = nm.named_notebook_path('hello.ipynb') |
|
85 | # get notebook, and return the path as '/' | |
83 | self.assertEqual(name, 'hello.ipynb') |
|
86 | name, path = nm.named_notebook_path('notebook.ipynb') | |
|
87 | self.assertEqual(name, 'notebook.ipynb') | |||
84 | self.assertEqual(path, '/') |
|
88 | self.assertEqual(path, '/') | |
85 |
|
89 | |||
86 | name, path = nm.named_notebook_path('/hello.ipynb') |
|
90 | # Test a notebook name with leading slash returns | |
87 | self.assertEqual(name, 'hello.ipynb') |
|
91 | # the same as above | |
|
92 | name, path = nm.named_notebook_path('/notebook.ipynb') | |||
|
93 | self.assertEqual(name, 'notebook.ipynb') | |||
88 | self.assertEqual(path, '/') |
|
94 | self.assertEqual(path, '/') | |
89 |
|
95 | |||
90 | name, path = nm.named_notebook_path('/this/is/a/path/hello.ipynb') |
|
96 | # Multiple path arguments splits the notebook name | |
91 | self.assertEqual(name, 'hello.ipynb') |
|
97 | # and returns path with leading and trailing '/' | |
|
98 | name, path = nm.named_notebook_path('/this/is/a/path/notebook.ipynb') | |||
|
99 | self.assertEqual(name, 'notebook.ipynb') | |||
92 | self.assertEqual(path, '/this/is/a/path/') |
|
100 | self.assertEqual(path, '/this/is/a/path/') | |
93 |
|
101 | |||
94 | name, path = nm.named_notebook_path('path/without/leading/slash/hello.ipynb') |
|
102 | # path without leading slash is returned with leading slash | |
95 | self.assertEqual(name, 'hello.ipynb') |
|
103 | name, path = nm.named_notebook_path('path/without/leading/slash/notebook.ipynb') | |
|
104 | self.assertEqual(name, 'notebook.ipynb') | |||
96 | self.assertEqual(path, '/path/without/leading/slash/') |
|
105 | self.assertEqual(path, '/path/without/leading/slash/') | |
97 |
|
106 | |||
|
107 | # path with spaces and no leading or trailing '/' | |||
|
108 | name, path = nm.named_notebook_path('foo / bar% path& to# @/ notebook name.ipynb') | |||
|
109 | self.assertEqual(name, ' notebook name.ipynb') | |||
|
110 | self.assertEqual(path, '/foo / bar% path& to# @/') | |||
|
111 | ||||
98 | def test_url_encode(self): |
|
112 | def test_url_encode(self): | |
99 | nm = NotebookManager() |
|
113 | nm = NotebookManager() | |
100 |
|
114 | |||
@@ -108,6 +122,10 b' class TestNotebookManager(TestCase):' | |||||
108 |
|
122 | |||
109 | path = nm.url_encode('/path with a/notebook and space.ipynb') |
|
123 | path = nm.url_encode('/path with a/notebook and space.ipynb') | |
110 | self.assertEqual(path, '/path%20with%20a/notebook%20and%20space.ipynb') |
|
124 | self.assertEqual(path, '/path%20with%20a/notebook%20and%20space.ipynb') | |
|
125 | ||||
|
126 | path = nm.url_encode('/ !@$#%^&* / test %^ notebook @#$ name.ipynb') | |||
|
127 | self.assertEqual(path, | |||
|
128 | '/%20%21%40%24%23%25%5E%26%2A%20/%20test%20%25%5E%20notebook%20%40%23%24%20name.ipynb') | |||
111 |
|
129 | |||
112 | def test_url_decode(self): |
|
130 | def test_url_decode(self): | |
113 | nm = NotebookManager() |
|
131 | nm = NotebookManager() | |
@@ -123,6 +141,10 b' class TestNotebookManager(TestCase):' | |||||
123 | path = nm.url_decode('/path%20with%20a/notebook%20and%20space.ipynb') |
|
141 | path = nm.url_decode('/path%20with%20a/notebook%20and%20space.ipynb') | |
124 | self.assertEqual(path, '/path with a/notebook and space.ipynb') |
|
142 | self.assertEqual(path, '/path with a/notebook and space.ipynb') | |
125 |
|
143 | |||
|
144 | path = nm.url_decode( | |||
|
145 | '/%20%21%40%24%23%25%5E%26%2A%20/%20test%20%25%5E%20notebook%20%40%23%24%20name.ipynb') | |||
|
146 | self.assertEqual(path, '/ !@$#%^&* / test %^ notebook @#$ name.ipynb') | |||
|
147 | ||||
126 | def test_create_notebook_model(self): |
|
148 | def test_create_notebook_model(self): | |
127 | with TemporaryDirectory() as td: |
|
149 | with TemporaryDirectory() as td: | |
128 | # Test in root directory |
|
150 | # Test in root directory |
General Comments 0
You need to be logged in to leave comments.
Login now