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