Show More
@@ -158,23 +158,12 b' class ContentsHandler(IPythonHandler):' | |||||
158 | Save notebook at ``path/Name.ipynb``. Notebook structure is specified |
|
158 | Save notebook at ``path/Name.ipynb``. Notebook structure is specified | |
159 | in `content` key of JSON request body. If content is not specified, |
|
159 | in `content` key of JSON request body. If content is not specified, | |
160 | create a new empty notebook. |
|
160 | create a new empty notebook. | |
161 | PUT /api/contents/path/Name.ipynb |
|
|||
162 | with JSON body:: |
|
|||
163 |
|
||||
164 | { |
|
|||
165 | "copy_from" : "[path/to/]OtherNotebook.ipynb" |
|
|||
166 | } |
|
|||
167 |
|
||||
168 | Copy OtherNotebook to Name |
|
|||
169 | """ |
|
161 | """ | |
170 | model = self.get_json_body() |
|
162 | model = self.get_json_body() | |
171 | if model: |
|
163 | if model: | |
172 |
|
|
164 | if model.get('copy_from'): | |
173 | if copy_from: |
|
165 | raise web.HTTPError(400, "Cannot copy with PUT, only POST") | |
174 | if model.get('content'): |
|
166 | if self.contents_manager.file_exists(path): | |
175 | raise web.HTTPError(400, "Can't upload and copy at the same time.") |
|
|||
176 | self._copy(copy_from, path) |
|
|||
177 | elif self.contents_manager.file_exists(path): |
|
|||
178 | self._save(model, path) |
|
167 | self._save(model, path) | |
179 | else: |
|
168 | else: | |
180 | self._upload(model, path) |
|
169 | self._upload(model, path) |
@@ -55,7 +55,7 b' class API(object):' | |||||
55 | body = json.dumps({'ext': ext}) |
|
55 | body = json.dumps({'ext': ext}) | |
56 | return self._req('POST', path, body) |
|
56 | return self._req('POST', path, body) | |
57 |
|
57 | |||
58 |
def copy |
|
58 | def copy(self, copy_from, path='/'): | |
59 | body = json.dumps({'copy_from':copy_from}) |
|
59 | body = json.dumps({'copy_from':copy_from}) | |
60 | return self._req('POST', path, body) |
|
60 | return self._req('POST', path, body) | |
61 |
|
61 | |||
@@ -68,7 +68,7 b' class API(object):' | |||||
68 | def mkdir(self, path='/'): |
|
68 | def mkdir(self, path='/'): | |
69 | return self._req('PUT', path, json.dumps({'type': 'directory'})) |
|
69 | return self._req('PUT', path, json.dumps({'type': 'directory'})) | |
70 |
|
70 | |||
71 | def copy(self, copy_from, path): |
|
71 | def copy_put(self, copy_from, path='/'): | |
72 | body = json.dumps({'copy_from':copy_from}) |
|
72 | body = json.dumps({'copy_from':copy_from}) | |
73 | return self._req('PUT', path, body) |
|
73 | return self._req('PUT', path, body) | |
74 |
|
74 | |||
@@ -352,25 +352,25 b' class APITest(NotebookTestBase):' | |||||
352 | data = resp.json() |
|
352 | data = resp.json() | |
353 | self.assertEqual(data['content']['nbformat'], 4) |
|
353 | self.assertEqual(data['content']['nbformat'], 4) | |
354 |
|
354 | |||
355 |
def test_copy |
|
355 | def test_copy(self): | |
356 |
resp = self.api.copy |
|
356 | resp = self.api.copy(u'å b/ç d.ipynb', u'unicodé') | |
357 | self._check_created(resp, u'unicodé/ç d-Copy0.ipynb') |
|
357 | self._check_created(resp, u'unicodé/ç d-Copy0.ipynb') | |
358 |
|
358 | |||
359 |
resp = self.api.copy |
|
359 | resp = self.api.copy(u'å b/ç d.ipynb', u'å b') | |
360 | self._check_created(resp, u'å b/ç d-Copy0.ipynb') |
|
360 | self._check_created(resp, u'å b/ç d-Copy0.ipynb') | |
361 |
|
361 | |||
362 | def test_copy(self): |
|
|||
363 | resp = self.api.copy(u'å b/ç d.ipynb', u'å b/cøpy.ipynb') |
|
|||
364 | self._check_created(resp, u'å b/cøpy.ipynb') |
|
|||
365 |
|
||||
366 | def test_copy_path(self): |
|
362 | def test_copy_path(self): | |
367 |
resp = self.api.copy(u'foo/a.ipynb', u'å b |
|
363 | resp = self.api.copy(u'foo/a.ipynb', u'å b') | |
368 |
self._check_created(resp, u'å b/ |
|
364 | self._check_created(resp, u'å b/a-Copy0.ipynb') | |
|
365 | ||||
|
366 | def test_copy_put_400(self): | |||
|
367 | with assert_http_error(400): | |||
|
368 | resp = self.api.copy_put(u'å b/ç d.ipynb', u'å b/cøpy.ipynb') | |||
369 |
|
369 | |||
370 | def test_copy_dir_400(self): |
|
370 | def test_copy_dir_400(self): | |
371 | # can't copy directories |
|
371 | # can't copy directories | |
372 | with assert_http_error(400): |
|
372 | with assert_http_error(400): | |
373 |
resp = self.api.copy(u'å b', u' |
|
373 | resp = self.api.copy(u'å b', u'foo') | |
374 |
|
374 | |||
375 | def test_delete(self): |
|
375 | def test_delete(self): | |
376 | for d, name in self.dirs_nbs: |
|
376 | for d, name in self.dirs_nbs: |
General Comments 0
You need to be logged in to leave comments.
Login now