Show More
@@ -11,7 +11,7 b' import requests' | |||
|
11 | 11 | |
|
12 | 12 | from IPython.html.utils import url_path_join |
|
13 | 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, writes | |
|
15 | 15 | from IPython.utils.data import uniq_stable |
|
16 | 16 | |
|
17 | 17 | class NBAPI(object): |
@@ -38,6 +38,9 b' class NBAPI(object):' | |||
|
38 | 38 | def create_untitled(self, path='/'): |
|
39 | 39 | return self._req('POST', path) |
|
40 | 40 | |
|
41 | def upload(self, name, body, path='/'): | |
|
42 | return self._req('POST', url_path_join(path, name), body) | |
|
43 | ||
|
41 | 44 | def delete(self, name, path='/'): |
|
42 | 45 | return self._req('DELETE', url_path_join(path, name)) |
|
43 | 46 | |
@@ -62,6 +65,7 b' class APITest(NotebookTestBase):' | |||
|
62 | 65 | |
|
63 | 66 | def setUp(self): |
|
64 | 67 | nbdir = self.notebook_dir.name |
|
68 | ||
|
65 | 69 | for d in self.dirs: |
|
66 | 70 | os.mkdir(pjoin(nbdir, d)) |
|
67 | 71 | |
@@ -121,6 +125,7 b' class APITest(NotebookTestBase):' | |||
|
121 | 125 | assert False, "Reading a non-existent notebook should fail" |
|
122 | 126 | |
|
123 | 127 | def _check_nb_created(self, resp, name, path): |
|
128 | self.assertEqual(resp.status_code, 201) | |
|
124 | 129 | self.assertEqual(resp.headers['Location'].split('/')[-1], name) |
|
125 | 130 | self.assertEqual(resp.json()['name'], name) |
|
126 | 131 | assert os.path.isfile(pjoin(self.notebook_dir.name, path, name)) |
@@ -137,6 +142,13 b' class APITest(NotebookTestBase):' | |||
|
137 | 142 | resp = self.nb_api.create_untitled(path='foo/bar') |
|
138 | 143 | self._check_nb_created(resp, 'Untitled0.ipynb', pjoin('foo', 'bar')) |
|
139 | 144 | |
|
145 | def test_upload(self): | |
|
146 | nb = new_notebook(name='Upload test') | |
|
147 | resp = self.nb_api.upload('Upload test.ipynb', path='foo', | |
|
148 | body=writes(nb, format='ipynb')) | |
|
149 | self._check_nb_created(resp, 'Upload test.ipynb', 'foo') | |
|
150 | ||
|
151 | ||
|
140 | 152 | def test_delete(self): |
|
141 | 153 | for d, name in self.dirs_nbs: |
|
142 | 154 | resp = self.nb_api.delete('%s.ipynb' % name, d) |
General Comments 0
You need to be logged in to leave comments.
Login now