Show More
@@ -153,6 +153,8 b' class FileNotebookManager(NotebookManager):' | |||||
153 | nbpath = self.get_os_path(name, path=path) |
|
153 | nbpath = self.get_os_path(name, path=path) | |
154 | return os.path.isfile(nbpath) |
|
154 | return os.path.isfile(nbpath) | |
155 |
|
155 | |||
|
156 | # TODO: Remove this after we create the contents web service and directories are | |||
|
157 | # no longer listed by the notebook web service. | |||
156 | def list_dirs(self, path): |
|
158 | def list_dirs(self, path): | |
157 | """List the directories for a given API style path.""" |
|
159 | """List the directories for a given API style path.""" | |
158 | path = path.strip('/') |
|
160 | path = path.strip('/') | |
@@ -167,6 +169,8 b' class FileNotebookManager(NotebookManager):' | |||||
167 | dirs = sorted(dirs, key=lambda item: item['name']) |
|
169 | dirs = sorted(dirs, key=lambda item: item['name']) | |
168 | return dirs |
|
170 | return dirs | |
169 |
|
171 | |||
|
172 | # TODO: Remove this after we create the contents web service and directories are | |||
|
173 | # no longer listed by the notebook web service. | |||
170 | def get_dir_model(self, name, path=''): |
|
174 | def get_dir_model(self, name, path=''): | |
171 | """Get the directory model given a directory name and its API style path""" |
|
175 | """Get the directory model given a directory name and its API style path""" | |
172 | path = path.strip('/') |
|
176 | path = path.strip('/') |
@@ -15,6 +15,7 b' from IPython.html.utils import url_path_join' | |||||
15 | from ..filenbmanager import FileNotebookManager |
|
15 | from ..filenbmanager import FileNotebookManager | |
16 | from ..nbmanager import NotebookManager |
|
16 | from ..nbmanager import NotebookManager | |
17 |
|
17 | |||
|
18 | ||||
18 | class TestFileNotebookManager(TestCase): |
|
19 | class TestFileNotebookManager(TestCase): | |
19 |
|
20 | |||
20 | def test_nb_dir(self): |
|
21 | def test_nb_dir(self): |
@@ -21,6 +21,12 b' from IPython.utils import py3compat' | |||||
21 | from IPython.utils.data import uniq_stable |
|
21 | from IPython.utils.data import uniq_stable | |
22 |
|
22 | |||
23 |
|
23 | |||
|
24 | # TODO: Remove this after we create the contents web service and directories are | |||
|
25 | # no longer listed by the notebook web service. | |||
|
26 | def notebooks_only(nb_list): | |||
|
27 | return [nb for nb in nb_list if 'type' not in nb] | |||
|
28 | ||||
|
29 | ||||
24 | class NBAPI(object): |
|
30 | class NBAPI(object): | |
25 | """Wrapper for notebook API calls.""" |
|
31 | """Wrapper for notebook API calls.""" | |
26 | def __init__(self, base_url): |
|
32 | def __init__(self, base_url): | |
@@ -125,25 +131,25 b' class APITest(NotebookTestBase):' | |||||
125 | os.unlink(pjoin(nbdir, 'inroot.ipynb')) |
|
131 | os.unlink(pjoin(nbdir, 'inroot.ipynb')) | |
126 |
|
132 | |||
127 | def test_list_notebooks(self): |
|
133 | def test_list_notebooks(self): | |
128 | nbs = self.nb_api.list().json() |
|
134 | nbs = notebooks_only(self.nb_api.list().json()) | |
129 | self.assertEqual(len(nbs), 1) |
|
135 | self.assertEqual(len(nbs), 1) | |
130 | self.assertEqual(nbs[0]['name'], 'inroot.ipynb') |
|
136 | self.assertEqual(nbs[0]['name'], 'inroot.ipynb') | |
131 |
|
137 | |||
132 | nbs = self.nb_api.list('/Directory with spaces in/').json() |
|
138 | nbs = notebooks_only(self.nb_api.list('/Directory with spaces in/').json()) | |
133 | self.assertEqual(len(nbs), 1) |
|
139 | self.assertEqual(len(nbs), 1) | |
134 | self.assertEqual(nbs[0]['name'], 'inspace.ipynb') |
|
140 | self.assertEqual(nbs[0]['name'], 'inspace.ipynb') | |
135 |
|
141 | |||
136 | nbs = self.nb_api.list(u'/unicodé/').json() |
|
142 | nbs = notebooks_only(self.nb_api.list(u'/unicodé/').json()) | |
137 | self.assertEqual(len(nbs), 1) |
|
143 | self.assertEqual(len(nbs), 1) | |
138 | self.assertEqual(nbs[0]['name'], 'innonascii.ipynb') |
|
144 | self.assertEqual(nbs[0]['name'], 'innonascii.ipynb') | |
139 | self.assertEqual(nbs[0]['path'], u'unicodé') |
|
145 | self.assertEqual(nbs[0]['path'], u'unicodé') | |
140 |
|
146 | |||
141 | nbs = self.nb_api.list('/foo/bar/').json() |
|
147 | nbs = notebooks_only(self.nb_api.list('/foo/bar/').json()) | |
142 | self.assertEqual(len(nbs), 1) |
|
148 | self.assertEqual(len(nbs), 1) | |
143 | self.assertEqual(nbs[0]['name'], 'baz.ipynb') |
|
149 | self.assertEqual(nbs[0]['name'], 'baz.ipynb') | |
144 | self.assertEqual(nbs[0]['path'], 'foo/bar') |
|
150 | self.assertEqual(nbs[0]['path'], 'foo/bar') | |
145 |
|
151 | |||
146 | nbs = self.nb_api.list('foo').json() |
|
152 | nbs = notebooks_only(self.nb_api.list('foo').json()) | |
147 | self.assertEqual(len(nbs), 4) |
|
153 | self.assertEqual(len(nbs), 4) | |
148 | nbnames = { normalize('NFC', n['name']) for n in nbs } |
|
154 | nbnames = { normalize('NFC', n['name']) for n in nbs } | |
149 | expected = [ u'a.ipynb', u'b.ipynb', u'name with spaces.ipynb', u'unicodé.ipynb'] |
|
155 | expected = [ u'a.ipynb', u'b.ipynb', u'name with spaces.ipynb', u'unicodé.ipynb'] | |
@@ -231,7 +237,7 b' class APITest(NotebookTestBase):' | |||||
231 | self.assertEqual(resp.status_code, 204) |
|
237 | self.assertEqual(resp.status_code, 204) | |
232 |
|
238 | |||
233 | for d in self.dirs + ['/']: |
|
239 | for d in self.dirs + ['/']: | |
234 | nbs = self.nb_api.list(d).json() |
|
240 | nbs = notebooks_only(self.nb_api.list(d).json()) | |
235 | self.assertEqual(len(nbs), 0) |
|
241 | self.assertEqual(len(nbs), 0) | |
236 |
|
242 | |||
237 | def test_rename(self): |
|
243 | def test_rename(self): | |
@@ -240,7 +246,7 b' class APITest(NotebookTestBase):' | |||||
240 | self.assertEqual(resp.json()['name'], 'z.ipynb') |
|
246 | self.assertEqual(resp.json()['name'], 'z.ipynb') | |
241 | assert os.path.isfile(pjoin(self.notebook_dir.name, 'foo', 'z.ipynb')) |
|
247 | assert os.path.isfile(pjoin(self.notebook_dir.name, 'foo', 'z.ipynb')) | |
242 |
|
248 | |||
243 | nbs = self.nb_api.list('foo').json() |
|
249 | nbs = notebooks_only(self.nb_api.list('foo').json()) | |
244 | nbnames = set(n['name'] for n in nbs) |
|
250 | nbnames = set(n['name'] for n in nbs) | |
245 | self.assertIn('z.ipynb', nbnames) |
|
251 | self.assertIn('z.ipynb', nbnames) | |
246 | self.assertNotIn('a.ipynb', nbnames) |
|
252 | self.assertNotIn('a.ipynb', nbnames) |
General Comments 0
You need to be logged in to leave comments.
Login now