diff --git a/IPython/html/services/contents/handlers.py b/IPython/html/services/contents/handlers.py index 3903aff..f91c662 100644 --- a/IPython/html/services/contents/handlers.py +++ b/IPython/html/services/contents/handlers.py @@ -158,23 +158,12 @@ class ContentsHandler(IPythonHandler): Save notebook at ``path/Name.ipynb``. Notebook structure is specified in `content` key of JSON request body. If content is not specified, create a new empty notebook. - PUT /api/contents/path/Name.ipynb - with JSON body:: - - { - "copy_from" : "[path/to/]OtherNotebook.ipynb" - } - - Copy OtherNotebook to Name """ model = self.get_json_body() if model: - copy_from = model.get('copy_from') - if copy_from: - if model.get('content'): - raise web.HTTPError(400, "Can't upload and copy at the same time.") - self._copy(copy_from, path) - elif self.contents_manager.file_exists(path): + if model.get('copy_from'): + raise web.HTTPError(400, "Cannot copy with PUT, only POST") + if self.contents_manager.file_exists(path): self._save(model, path) else: self._upload(model, path) diff --git a/IPython/html/services/contents/tests/test_contents_api.py b/IPython/html/services/contents/tests/test_contents_api.py index 1685dc9..698f471 100644 --- a/IPython/html/services/contents/tests/test_contents_api.py +++ b/IPython/html/services/contents/tests/test_contents_api.py @@ -55,7 +55,7 @@ class API(object): body = json.dumps({'ext': ext}) return self._req('POST', path, body) - def copy_untitled(self, copy_from, path='/'): + def copy(self, copy_from, path='/'): body = json.dumps({'copy_from':copy_from}) return self._req('POST', path, body) @@ -68,7 +68,7 @@ class API(object): def mkdir(self, path='/'): return self._req('PUT', path, json.dumps({'type': 'directory'})) - def copy(self, copy_from, path): + def copy_put(self, copy_from, path='/'): body = json.dumps({'copy_from':copy_from}) return self._req('PUT', path, body) @@ -352,25 +352,25 @@ class APITest(NotebookTestBase): data = resp.json() self.assertEqual(data['content']['nbformat'], 4) - def test_copy_untitled(self): - resp = self.api.copy_untitled(u'å b/ç d.ipynb', u'unicodé') + def test_copy(self): + resp = self.api.copy(u'å b/ç d.ipynb', u'unicodé') self._check_created(resp, u'unicodé/ç d-Copy0.ipynb') - resp = self.api.copy_untitled(u'å b/ç d.ipynb', u'å b') + resp = self.api.copy(u'å b/ç d.ipynb', u'å b') self._check_created(resp, u'å b/ç d-Copy0.ipynb') - def test_copy(self): - resp = self.api.copy(u'å b/ç d.ipynb', u'å b/cøpy.ipynb') - self._check_created(resp, u'å b/cøpy.ipynb') - def test_copy_path(self): - resp = self.api.copy(u'foo/a.ipynb', u'å b/cøpyfoo.ipynb') - self._check_created(resp, u'å b/cøpyfoo.ipynb') + resp = self.api.copy(u'foo/a.ipynb', u'å b') + self._check_created(resp, u'å b/a-Copy0.ipynb') + + def test_copy_put_400(self): + with assert_http_error(400): + resp = self.api.copy_put(u'å b/ç d.ipynb', u'å b/cøpy.ipynb') def test_copy_dir_400(self): # can't copy directories with assert_http_error(400): - resp = self.api.copy(u'å b', u'å c') + resp = self.api.copy(u'å b', u'foo') def test_delete(self): for d, name in self.dirs_nbs: