def test_open(self): """Open a project.""" manager = project.ProjectManager(self.mktemp()) prj = manager.get_project(NAME) prj.create() prj.open(Factory(), Settings(self.mktemp()))
def test_save_after_delete(self): manager = project.ProjectManager(self.mktemp()) prj = manager.get_project(NAME) prj.create() prj.delete() prj.save(Factory()) self.assertTrue(prj.exists())
def test_restore_last_project(self): """Restore last used project.""" manager = project.ProjectManager(self.mktemp()) prj = manager.get_project(NAME) prj.create() settings = Settings(self.mktemp()) settings.set("current_project", NAME) self.assertEqual(manager.restore_last(Factory(), settings), prj)
def test_save_as(self): """Create a copy of the project with a different name.""" NEW_PROJET_NAME = "copy" manager = project.ProjectManager(self.mktemp()) prj = manager.get_project(NAME) prj.create() new = prj.save_as(NEW_PROJET_NAME, Factory()) self.assertTrue(FilePath(new.path).exists()) self.assertNotEqual(prj.path, new.path)
def test_save(self): """Save a project.""" class ProjectCmp: def __init__(self, prj): self.data = prj._project.getContent() def __eq__(self, other): return not self.__ne__(other) def __ne__(self, other): return self.data != ProjectCmp(other).data manager = project.ProjectManager(self.mktemp()) prj = manager.get_project(NAME) prj.create() cmparator = ProjectCmp(prj) factory = Factory() factory.new_brick("vm", "test") prj.save(factory) self.assertNotEqual(cmparator, prj)
def test_save_description(self): """Save the description when the project is saved.""" DESCRIPTION = "hello world" manager = project.ProjectManager(self.mktemp()) prj = manager.get_project(NAME) prj.set_description(DESCRIPTION) readme = FilePath(prj.path).child("README") self.assertFalse(readme.exists()) prj.save(Factory()) self.assertEqual(readme.getContent(), DESCRIPTION)
def test_restore_last_project_not_exists(self): """ If the last project does not exists, don't create a new one with the same name but use a default name. """ settings = Settings(self.mktemp()) settings.set("current_project", NAME) manager = project.ProjectManager(self.mktemp()) prj = manager.get_project(NAME) self.assertFalse(prj.exists()) prj = manager.restore_last(Factory(), settings) self.assertEqual(prj.name, settings.DEFAULT_PROJECT + "_0")
def test_open_project_set_virtualbricks_home(self): """ Every time a project is opened, settings.VIRTUALBRICKS_HOME is set to the project's path. """ manager = project.ProjectManager(self.mktemp()) settings = Settings(self.mktemp()) prj = manager.get_project(NAME) prj.create() self.assertEqual(settings.VIRTUALBRICKS_HOME, settings.DEFAULT_HOME) prj.open(Factory(), settings) self.assertEqual(prj.path, settings.VIRTUALBRICKS_HOME) self.assertNotEqual(settings.VIRTUALBRICKS_HOME, settings.DEFAULT_HOME)
def test_open_project_does_not_exists(self): """Try to open a project that does not exists.""" manager = project.ProjectManager(self.mktemp()) prj = manager.get_project(NAME) self.assertRaises(errors.ProjectNotExistsError, prj.open, Factory())