fix bug in test_contentmanager

This commit is contained in:
Zachary Sailer 2013-08-21 12:02:46 -07:00 committed by MinRK
parent 136a19e5eb
commit 5f1b7727d8
3 changed files with 24 additions and 24 deletions

View File

@ -91,7 +91,7 @@ class FileNotebookManager(NotebookManager):
notebooks.append(model)
return notebooks
def change_notebook(self, data, notebook_name, notebook_path=None):
def change_notebook(self, data, notebook_name, notebook_path='/'):
"""Changes notebook"""
changes = data.keys()
response = 200
@ -170,7 +170,7 @@ class FileNotebookManager(NotebookManager):
raise web.HTTPError(400, msg, reason=msg)
return last_modified, nb
def read_notebook_object(self, notebook_name, notebook_path=None):
def read_notebook_object(self, notebook_name, notebook_path='/'):
"""Get the Notebook representation of a notebook by notebook_name."""
path = self.get_os_path(notebook_name, notebook_path)
if not os.path.isfile(path):
@ -184,7 +184,7 @@ class FileNotebookManager(NotebookManager):
nb.metadata.name = os.path.splitext(os.path.basename(path))[0]
return last_modified, nb
def write_notebook_object(self, nb, notebook_name=None, notebook_path=None, new_name= None):
def write_notebook_object(self, nb, notebook_name=None, notebook_path='/', new_name= None):
"""Save an existing notebook object by notebook_name."""
if new_name == None:
try:
@ -266,7 +266,7 @@ class FileNotebookManager(NotebookManager):
self.log.debug("unlinking notebook %s", nb_path)
os.unlink(nb_path)
def increment_filename(self, basename, notebook_path=None):
def increment_filename(self, basename, notebook_path='/'):
"""Return a non-used filename of the form basename<int>.
This searches through the filenames (basename0, basename1, ...)
@ -285,7 +285,7 @@ class FileNotebookManager(NotebookManager):
# Checkpoint-related utilities
def get_checkpoint_path_by_name(self, name, checkpoint_id, notebook_path=None):
def get_checkpoint_path_by_name(self, name, checkpoint_id, notebook_path='/'):
"""Return a full path to a notebook checkpoint, given its name and checkpoint id."""
filename = u"{name}-{checkpoint_id}{ext}".format(
name=name,
@ -298,12 +298,12 @@ class FileNotebookManager(NotebookManager):
path = os.path.join(notebook_path, self.checkpoint_dir, filename)
return path
def get_checkpoint_path(self, notebook_name, checkpoint_id, notebook_path=None):
def get_checkpoint_path(self, notebook_name, checkpoint_id, notebook_path='/'):
"""find the path to a checkpoint"""
name = notebook_name
return self.get_checkpoint_path_by_name(name, checkpoint_id, notebook_path)
def get_checkpoint_info(self, notebook_name, checkpoint_id, notebook_path=None):
def get_checkpoint_info(self, notebook_name, checkpoint_id, notebook_path='/'):
"""construct the info dict for a given checkpoint"""
path = self.get_checkpoint_path(notebook_name, checkpoint_id, notebook_path)
stats = os.stat(path)
@ -317,7 +317,7 @@ class FileNotebookManager(NotebookManager):
# public checkpoint API
def create_checkpoint(self, notebook_name, notebook_path=None):
def create_checkpoint(self, notebook_name, notebook_path='/'):
"""Create a checkpoint from the current state of a notebook"""
nb_path = self.get_os_path(notebook_name, notebook_path)
# only the one checkpoint ID:
@ -331,7 +331,7 @@ class FileNotebookManager(NotebookManager):
# return the checkpoint info
return self.get_checkpoint_info(notebook_name, checkpoint_id, notebook_path)
def list_checkpoints(self, notebook_name, notebook_path=None):
def list_checkpoints(self, notebook_name, notebook_path='/'):
"""list the checkpoints for a given notebook
This notebook manager currently only supports one checkpoint per notebook.
@ -344,7 +344,7 @@ class FileNotebookManager(NotebookManager):
return [self.get_checkpoint_info(notebook_name, checkpoint_id, notebook_path)]
def restore_checkpoint(self, notebook_name, checkpoint_id, notebook_path=None):
def restore_checkpoint(self, notebook_name, checkpoint_id, notebook_path='/'):
"""restore a notebook to a checkpointed state"""
self.log.info("restoring Notebook %s from checkpoint %s", notebook_name, checkpoint_id)
nb_path = self.get_os_path(notebook_name, notebook_path)
@ -359,7 +359,7 @@ class FileNotebookManager(NotebookManager):
shutil.copy2(cp_path, nb_path)
self.log.debug("copying %s -> %s", cp_path, nb_path)
def delete_checkpoint(self, notebook_name, checkpoint_id, notebook_path=None):
def delete_checkpoint(self, notebook_name, checkpoint_id, notebook_path='/'):
"""delete a notebook's checkpoint"""
path = self.get_checkpoint_path(notebook_name, checkpoint_id, notebook_path)
if not os.path.isfile(path):

View File

@ -48,9 +48,9 @@ class NotebookRootHandler(IPythonHandler):
format = self.get_argument('format', default='json')
name = self.get_argument('name', default=None)
if body:
fname = nbm.save_new_notebook(body, notebook_path=None, name=name, format=format)
fname = nbm.save_new_notebook(body, notebook_path='/', name=name, format=format)
else:
fname = nbm.new_notebook(notebook_path=None)
fname = nbm.new_notebook(notebook_path='/')
self.set_header('Location', nbm.notebook_dir + fname)
model = nbm.notebook_model(fname)
self.set_header('Location', '{0}api/notebooks/{1}'.format(self.base_project_url, notebook_name))

View File

@ -129,7 +129,7 @@ class NotebookManager(LoggingConfigurable):
"""
raise NotImplementedError('must be implemented in a subclass')
def notebook_model(self, notebook_name, notebook_path=None, content=True):
def notebook_model(self, notebook_name, notebook_path='/', content=True):
""" Creates the standard notebook model """
last_modified, contents = self.read_notebook_object(notebook_name, notebook_path)
model = {"name": notebook_name,
@ -139,7 +139,7 @@ class NotebookManager(LoggingConfigurable):
model['content'] = contents
return model
def get_notebook(self, notebook_name, notebook_path=None, format=u'json'):
def get_notebook(self, notebook_name, notebook_path='/', format=u'json'):
"""Get the representation of a notebook in format by notebook_name."""
format = unicode(format)
if format not in self.allowed_formats:
@ -154,11 +154,11 @@ class NotebookManager(LoggingConfigurable):
name = nb.metadata.get('name', 'notebook')
return last_mod, representation, name
def read_notebook_object(self, notebook_name, notebook_path=None):
def read_notebook_object(self, notebook_name, notebook_path='/'):
"""Get the object representation of a notebook by notebook_id."""
raise NotImplementedError('must be implemented in a subclass')
def save_new_notebook(self, data, notebook_path=None, name=None, format=u'json'):
def save_new_notebook(self, data, notebook_path='/', name=None, format=u'json'):
"""Save a new notebook and return its name.
If a name is passed in, it overrides any values in the notebook data
@ -182,7 +182,7 @@ class NotebookManager(LoggingConfigurable):
notebook_name = self.write_notebook_object(nb, notebook_path=notebook_path)
return notebook_name
def save_notebook(self, data, notebook_path=None, name=None, new_name=None, format=u'json'):
def save_notebook(self, data, notebook_path='/', name=None, new_name=None, format=u'json'):
"""Save an existing notebook by notebook_name."""
if format not in self.allowed_formats:
raise web.HTTPError(415, u'Invalid notebook format: %s' % format)
@ -196,7 +196,7 @@ class NotebookManager(LoggingConfigurable):
nb.metadata.name = name
self.write_notebook_object(nb, name, notebook_path, new_name)
def write_notebook_object(self, nb, notebook_name=None, notebook_path=None, new_name=None):
def write_notebook_object(self, nb, notebook_name=None, notebook_path='/', new_name=None):
"""Write a notebook object and return its notebook_name.
If notebook_name is None, this method should create a new notebook_name.
@ -226,7 +226,7 @@ class NotebookManager(LoggingConfigurable):
notebook_name = self.write_notebook_object(nb, notebook_path=notebook_path)
return notebook_name
def copy_notebook(self, name, path=None):
def copy_notebook(self, name, path='/'):
"""Copy an existing notebook and return its new notebook_name."""
last_mod, nb = self.read_notebook_object(name, path)
name = nb.metadata.name + '-Copy'
@ -237,22 +237,22 @@ class NotebookManager(LoggingConfigurable):
# Checkpoint-related
def create_checkpoint(self, notebook_name, notebook_path=None):
def create_checkpoint(self, notebook_name, notebook_path='/'):
"""Create a checkpoint of the current state of a notebook
Returns a checkpoint_id for the new checkpoint.
"""
raise NotImplementedError("must be implemented in a subclass")
def list_checkpoints(self, notebook_name, notebook_path=None):
def list_checkpoints(self, notebook_name, notebook_path='/'):
"""Return a list of checkpoints for a given notebook"""
return []
def restore_checkpoint(self, notebook_name, checkpoint_id, notebook_path=None):
def restore_checkpoint(self, notebook_name, checkpoint_id, notebook_path='/'):
"""Restore a notebook from one of its checkpoints"""
raise NotImplementedError("must be implemented in a subclass")
def delete_checkpoint(self, notebook_name, checkpoint_id, notebook_path=None):
def delete_checkpoint(self, notebook_name, checkpoint_id, notebook_path='/'):
"""delete a checkpoint for a notebook"""
raise NotImplementedError("must be implemented in a subclass")