def test_remove_project_node(self): """ Test removing of a node from a project. """ inserted_project, gid, op = TestFactory.create_value_wrapper(self.test_user) project_to_link = model_project.Project("Link", self.test_user.id, "descript") project_to_link = dao.store_entity(project_to_link) exact_data = dao.get_datatype_by_gid(gid) assert exact_data is not None, "Initialization problem!" link = dao.store_entity(model_datatype.Links(exact_data.id, project_to_link.id)) vw_h5_path = h5.path_for_stored_index(exact_data) assert os.path.exists(vw_h5_path) if dao.get_system_user() is None: dao.store_entity(model_operation.User(TvbProfile.current.web.admin.SYSTEM_USER_NAME, TvbProfile.current.web.admin.SYSTEM_USER_NAME, None, None, True, None)) self.project_service._remove_project_node_files(inserted_project.id, gid, [link]) assert not os.path.exists(vw_h5_path) exact_data = dao.get_datatype_by_gid(gid) assert exact_data is not None, "Data should still be in DB, because of links" vw_h5_path_new = h5.path_for_stored_index(exact_data) assert os.path.exists(vw_h5_path_new) assert vw_h5_path_new != vw_h5_path self.project_service._remove_project_node_files(project_to_link.id, gid, []) assert dao.get_datatype_by_gid(gid) is None
def test_remove_project_node(self, test_adapter_factory): """ Test removing of a node from a project. """ inserted_project, gid, gid_op = self._create_value_wrapper( self.test_user) project_to_link = model_project.Project("Link", self.test_user.id, "descript") project_to_link = dao.store_entity(project_to_link) exact_data = dao.get_datatype_by_gid(gid) dao.store_entity( model_datatype.Links(exact_data.id, project_to_link.id)) assert dao.get_datatype_by_gid( gid) is not None, "Initialization problem!" operation_id = dao.get_generic_entity(model_operation.Operation, gid_op, 'gid')[0].id op_folder = self.structure_helper.get_project_folder( "test_proj", str(operation_id)) assert os.path.exists(op_folder) sub_files = os.listdir(op_folder) assert 2 == len(sub_files) ### Validate that no more files are created than needed. if (dao.get_system_user() is None): dao.store_entity( model_operation.User( TvbProfile.current.web.admin.SYSTEM_USER_NAME, TvbProfile.current.web.admin.SYSTEM_USER_NAME, None, None, True, None)) self.project_service._remove_project_node_files( inserted_project.id, gid) sub_files = os.listdir(op_folder) assert 1 == len(sub_files) ### operation.xml file should still be there op_folder = self.structure_helper.get_project_folder( "Link", str(operation_id + 1)) sub_files = os.listdir(op_folder) assert 2 == len(sub_files) assert dao.get_datatype_by_gid( gid) is not None, "Data should still be in DB, because of links" self.project_service._remove_project_node_files( project_to_link.id, gid) assert dao.get_datatype_by_gid(gid) is None sub_files = os.listdir(op_folder) assert 1 == len(sub_files)
def test_write_project_metadata(self): """ Write XML for test-project. """ self.files_helper.write_project_metadata(self.test_project) expected_file = self.files_helper.get_project_meta_file_path(self.PROJECT_NAME) assert os.path.exists(expected_file) project_meta = XMLReader(expected_file).read_metadata() loaded_project = model_project.Project(None, None) loaded_project.from_dict(project_meta, self.test_user.id) assert self.test_project.name == loaded_project.name assert self.test_project.description == loaded_project.description assert self.test_project.gid == loaded_project.gid expected_dict = self.test_project.to_dict()[1] del expected_dict['last_updated'] found_dict = loaded_project.to_dict()[1] del found_dict['last_updated'] self._dictContainsSubset(expected_dict, found_dict) self._dictContainsSubset(found_dict, expected_dict)