Show More
@@ -11,7 +11,8 b' import requests' | |||||
11 |
|
11 | |||
12 | from IPython.html.utils import url_path_join |
|
12 | from IPython.html.utils import url_path_join | |
13 | from IPython.html.tests.launchnotebook import NotebookTestBase |
|
13 | from IPython.html.tests.launchnotebook import NotebookTestBase | |
14 |
from IPython.nbformat.current import new_notebook, write, |
|
14 | from IPython.nbformat.current import (new_notebook, write, read, new_worksheet, | |
|
15 | new_heading_cell, to_notebook_json) | |||
15 | from IPython.utils.data import uniq_stable |
|
16 | from IPython.utils.data import uniq_stable | |
16 |
|
17 | |||
17 | class NBAPI(object): |
|
18 | class NBAPI(object): | |
@@ -41,6 +42,9 b' class NBAPI(object):' | |||||
41 | def upload(self, name, body, path='/'): |
|
42 | def upload(self, name, body, path='/'): | |
42 | return self._req('POST', url_path_join(path, name), body) |
|
43 | return self._req('POST', url_path_join(path, name), body) | |
43 |
|
44 | |||
|
45 | def save(self, name, body, path='/'): | |||
|
46 | return self._req('PUT', url_path_join(path, name), body) | |||
|
47 | ||||
44 | def delete(self, name, path='/'): |
|
48 | def delete(self, name, path='/'): | |
45 | return self._req('DELETE', url_path_join(path, name)) |
|
49 | return self._req('DELETE', url_path_join(path, name)) | |
46 |
|
50 | |||
@@ -144,11 +148,11 b' class APITest(NotebookTestBase):' | |||||
144 |
|
148 | |||
145 | def test_upload(self): |
|
149 | def test_upload(self): | |
146 | nb = new_notebook(name='Upload test') |
|
150 | nb = new_notebook(name='Upload test') | |
|
151 | nbmodel = {'content': nb} | |||
147 | resp = self.nb_api.upload('Upload test.ipynb', path='foo', |
|
152 | resp = self.nb_api.upload('Upload test.ipynb', path='foo', | |
148 |
body= |
|
153 | body=jsonapi.dumps(nbmodel)) | |
149 | self._check_nb_created(resp, 'Upload test.ipynb', 'foo') |
|
154 | self._check_nb_created(resp, 'Upload test.ipynb', 'foo') | |
150 |
|
155 | |||
151 |
|
||||
152 | def test_delete(self): |
|
156 | def test_delete(self): | |
153 | for d, name in self.dirs_nbs: |
|
157 | for d, name in self.dirs_nbs: | |
154 | resp = self.nb_api.delete('%s.ipynb' % name, d) |
|
158 | resp = self.nb_api.delete('%s.ipynb' % name, d) | |
@@ -170,3 +174,20 b' class APITest(NotebookTestBase):' | |||||
170 | nbnames = set(n['name'] for n in nbs) |
|
174 | nbnames = set(n['name'] for n in nbs) | |
171 | self.assertIn('z.ipynb', nbnames) |
|
175 | self.assertIn('z.ipynb', nbnames) | |
172 | self.assertNotIn('a.ipynb', nbnames) |
|
176 | self.assertNotIn('a.ipynb', nbnames) | |
|
177 | ||||
|
178 | def test_save(self): | |||
|
179 | resp = self.nb_api.read('a.ipynb', 'foo') | |||
|
180 | nbcontent = jsonapi.loads(resp.text)['content'] | |||
|
181 | nb = to_notebook_json(nbcontent) | |||
|
182 | ws = new_worksheet() | |||
|
183 | nb.worksheets = [ws] | |||
|
184 | ws.cells.append(new_heading_cell('Created by test')) | |||
|
185 | ||||
|
186 | nbmodel= {'name': 'a.ipynb', 'path':'foo', 'content': nb} | |||
|
187 | resp = self.nb_api.save('a.ipynb', path='foo', body=jsonapi.dumps(nbmodel)) | |||
|
188 | ||||
|
189 | nbfile = pjoin(self.notebook_dir.name, 'foo', 'a.ipynb') | |||
|
190 | with open(nbfile, 'r') as f: | |||
|
191 | newnb = read(f, format='ipynb') | |||
|
192 | self.assertEqual(newnb.worksheets[0].cells[0].source, | |||
|
193 | 'Created by test') |
General Comments 0
You need to be logged in to leave comments.
Login now