Show More
@@ -254,7 +254,7 b' class FileNotebookManager(NotebookManager):' | |||||
254 | except Exception as e: |
|
254 | except Exception as e: | |
255 | raise web.HTTPError(400, u'Unexpected error while saving notebook as script: %s %s' % (py_path, e)) |
|
255 | raise web.HTTPError(400, u'Unexpected error while saving notebook as script: %s %s' % (py_path, e)) | |
256 |
|
256 | |||
257 | model = self.get_notebook_model(name, path, content=False) |
|
257 | model = self.get_notebook_model(new_name, new_path, content=False) | |
258 | return model |
|
258 | return model | |
259 |
|
259 | |||
260 | def update_notebook_model(self, model, name, path=''): |
|
260 | def update_notebook_model(self, model, name, path=''): |
@@ -115,6 +115,14 b' class APITest(NotebookTestBase):' | |||||
115 | self.assertEqual(nbnames, {'a.ipynb', 'b.ipynb', |
|
115 | self.assertEqual(nbnames, {'a.ipynb', 'b.ipynb', | |
116 | 'name with spaces.ipynb', u'unicodΓ©.ipynb'}) |
|
116 | 'name with spaces.ipynb', u'unicodΓ©.ipynb'}) | |
117 |
|
117 | |||
|
118 | def assert_404(self, name, path): | |||
|
119 | try: | |||
|
120 | self.nb_api.read(name, path) | |||
|
121 | except requests.HTTPError as e: | |||
|
122 | self.assertEqual(e.response.status_code, 404) | |||
|
123 | else: | |||
|
124 | assert False, "Reading a non-existent notebook should fail" | |||
|
125 | ||||
118 | def test_get_contents(self): |
|
126 | def test_get_contents(self): | |
119 | for d, name in self.dirs_nbs: |
|
127 | for d, name in self.dirs_nbs: | |
120 | nb = self.nb_api.read('%s.ipynb' % name, d+'/').json() |
|
128 | nb = self.nb_api.read('%s.ipynb' % name, d+'/').json() | |
@@ -124,12 +132,7 b' class APITest(NotebookTestBase):' | |||||
124 | self.assertIsInstance(nb['content']['metadata'], dict) |
|
132 | self.assertIsInstance(nb['content']['metadata'], dict) | |
125 |
|
133 | |||
126 | # Name that doesn't exist - should be a 404 |
|
134 | # Name that doesn't exist - should be a 404 | |
127 | try: |
|
135 | self.assert_404('q.ipynb', 'foo') | |
128 | self.nb_api.read('q.ipynb', 'foo') |
|
|||
129 | except requests.HTTPError as e: |
|
|||
130 | self.assertEqual(e.response.status_code, 404) |
|
|||
131 | else: |
|
|||
132 | assert False, "Reading a non-existent notebook should fail" |
|
|||
133 |
|
136 | |||
134 | def _check_nb_created(self, resp, name, path): |
|
137 | def _check_nb_created(self, resp, name, path): | |
135 | self.assertEqual(resp.status_code, 201) |
|
138 | self.assertEqual(resp.status_code, 201) | |
@@ -198,3 +201,13 b' class APITest(NotebookTestBase):' | |||||
198 | newnb = read(f, format='ipynb') |
|
201 | newnb = read(f, format='ipynb') | |
199 | self.assertEqual(newnb.worksheets[0].cells[0].source, |
|
202 | self.assertEqual(newnb.worksheets[0].cells[0].source, | |
200 | 'Created by test') |
|
203 | 'Created by test') | |
|
204 | ||||
|
205 | # Save and rename | |||
|
206 | nbmodel= {'name': 'a2.ipynb', 'path':'foo/bar', 'content': nb} | |||
|
207 | resp = self.nb_api.save('a.ipynb', path='foo', body=jsonapi.dumps(nbmodel)) | |||
|
208 | saved = resp.json() | |||
|
209 | self.assertEqual(saved['name'], 'a2.ipynb') | |||
|
210 | self.assertEqual(saved['path'], 'foo/bar') | |||
|
211 | assert os.path.isfile(pjoin(self.notebook_dir.name,'foo','bar','a2.ipynb')) | |||
|
212 | assert not os.path.isfile(pjoin(self.notebook_dir.name, 'foo', 'a.ipynb')) | |||
|
213 | self.assert_404('a.ipynb', 'foo') No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now