Show More
@@ -158,23 +158,12 b' class ContentsHandler(IPythonHandler):' | |||
|
158 | 158 | Save notebook at ``path/Name.ipynb``. Notebook structure is specified |
|
159 | 159 | in `content` key of JSON request body. If content is not specified, |
|
160 | 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 | 162 | model = self.get_json_body() |
|
171 | 163 | if model: |
|
172 |
|
|
|
173 | if copy_from: | |
|
174 | if model.get('content'): | |
|
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): | |
|
164 | if model.get('copy_from'): | |
|
165 | raise web.HTTPError(400, "Cannot copy with PUT, only POST") | |
|
166 | if self.contents_manager.file_exists(path): | |
|
178 | 167 | self._save(model, path) |
|
179 | 168 | else: |
|
180 | 169 | self._upload(model, path) |
@@ -55,7 +55,7 b' class API(object):' | |||
|
55 | 55 | body = json.dumps({'ext': ext}) |
|
56 | 56 | return self._req('POST', path, body) |
|
57 | 57 | |
|
58 |
def copy |
|
|
58 | def copy(self, copy_from, path='/'): | |
|
59 | 59 | body = json.dumps({'copy_from':copy_from}) |
|
60 | 60 | return self._req('POST', path, body) |
|
61 | 61 | |
@@ -68,7 +68,7 b' class API(object):' | |||
|
68 | 68 | def mkdir(self, path='/'): |
|
69 | 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 | 72 | body = json.dumps({'copy_from':copy_from}) |
|
73 | 73 | return self._req('PUT', path, body) |
|
74 | 74 | |
@@ -352,25 +352,25 b' class APITest(NotebookTestBase):' | |||
|
352 | 352 | data = resp.json() |
|
353 | 353 | self.assertEqual(data['content']['nbformat'], 4) |
|
354 | 354 | |
|
355 |
def test_copy |
|
|
356 |
resp = self.api.copy |
|
|
355 | def test_copy(self): | |
|
356 | resp = self.api.copy(u'å b/ç d.ipynb', u'unicodé') | |
|
357 | 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 | 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 | 362 | def test_copy_path(self): |
|
367 |
resp = self.api.copy(u'foo/a.ipynb', u'å b |
|
|
368 |
self._check_created(resp, u'å b/ |
|
|
363 | resp = self.api.copy(u'foo/a.ipynb', 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 | 370 | def test_copy_dir_400(self): |
|
371 | 371 | # can't copy directories |
|
372 | 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 | 375 | def test_delete(self): |
|
376 | 376 | for d, name in self.dirs_nbs: |
General Comments 0
You need to be logged in to leave comments.
Login now