mirror of
https://github.com/jupyter/notebook.git
synced 2025-02-05 12:19:58 +08:00
Added test for permanent delete
This commit is contained in:
parent
a307af9b35
commit
081dcd5774
@ -493,15 +493,6 @@ class FileContentsManager(FileManagerMixin, ContentsManager):
|
||||
raise web.HTTPError(404, u'File or directory does not exist: %s' % os_path)
|
||||
|
||||
if self.delete_to_trash:
|
||||
if os.path.isdir(os_path):
|
||||
listing = os.listdir(os_path)
|
||||
# Don't send non-empty directories to trash.
|
||||
# A directory containing only leftover checkpoints is
|
||||
# considered empty.
|
||||
cp_dir = getattr(self.checkpoints, 'checkpoint_dir', None)
|
||||
for entry in listing:
|
||||
if entry != cp_dir:
|
||||
raise web.HTTPError(400, u'Directory %s not empty' % os_path)
|
||||
self.log.debug("Sending %s to trash", os_path)
|
||||
# Looking at the code in send2trash, I don't think the errors it
|
||||
# raises let us distinguish permission errors from other errors in
|
||||
@ -510,6 +501,14 @@ class FileContentsManager(FileManagerMixin, ContentsManager):
|
||||
return
|
||||
|
||||
if os.path.isdir(os_path):
|
||||
listing = os.listdir(os_path)
|
||||
# Don't permanently delete non-empty directories.
|
||||
# A directory containing only leftover checkpoints is
|
||||
# considered empty.
|
||||
cp_dir = getattr(self.checkpoints, 'checkpoint_dir', None)
|
||||
for entry in listing:
|
||||
if entry != cp_dir:
|
||||
raise web.HTTPError(400, u'Directory %s not empty' % os_path)
|
||||
self.log.debug("Removing directory %s", os_path)
|
||||
with self.perm_to_403():
|
||||
shutil.rmtree(os_path)
|
||||
|
@ -185,6 +185,8 @@ class APITest(NotebookTestBase):
|
||||
"""Delete a directory at api_path, removing any contents."""
|
||||
os_path = self.to_os_path(api_path)
|
||||
shutil.rmtree(os_path, ignore_errors=True)
|
||||
with assert_http_error(400):
|
||||
shutil.rmtree(u'å b')
|
||||
|
||||
def delete_file(self, api_path):
|
||||
"""Delete a file at the given path if it exists."""
|
||||
@ -518,15 +520,13 @@ class APITest(NotebookTestBase):
|
||||
for name in sorted(self.dirs + ['/'], key=len, reverse=True):
|
||||
listing = self.api.list(name).json()['content']
|
||||
for model in listing:
|
||||
if os.path.exists(model['path']):
|
||||
self.api.delete(model['path'])
|
||||
self.api.delete(model['path'])
|
||||
listing = self.api.list('/').json()['content']
|
||||
self.assertEqual(listing, [])
|
||||
|
||||
def test_delete_non_empty_dir(self):
|
||||
"""delete non-empty dir raises 400"""
|
||||
with assert_http_error(400):
|
||||
self.api.delete(u'å b')
|
||||
"""deleting non-empty dir is allowed"""
|
||||
self.api.delete(u'å b')
|
||||
|
||||
def test_rename(self):
|
||||
resp = self.api.rename('foo/a.ipynb', 'foo/z.ipynb')
|
||||
|
Loading…
Reference in New Issue
Block a user