def readserverstaticfile(self, coded_path): """ Retrieve file from Local storage, having a File System Path. """ try: with open(url2path(coded_path), "rb") as f: return f.read() except Exception, excep: self.logger.error("Could not retrieve file from path:" + str(coded_path)) self.logger.exception(excep)
def readserverstaticfile(self, coded_path): """ Retrieve file from Local storage, having a File System Path. """ try: with open(url2path(coded_path), "rb") as f: return f.read() except Exception as excep: self.logger.error("Could not retrieve file from path:" + str(coded_path)) self.logger.exception(excep)
def readserverstaticfile(self, coded_path): """ Retrieve file from Local storage, having a File System Path. """ try: my_file = open(url2path(coded_path), "rb") result = my_file.read() my_file.close() return result except Exception, excep: self.logger.error("Could not retrieve file from path:" + str(coded_path)) self.logger.exception(excep)
def test_export_import_figures(self, user_factory, project_factory): """ Test that ResultFigure instances are correctly restores after an export+import project """ # Prepare data user = user_factory() project = project_factory(user, "TestImportExportFigures") zip_path = os.path.join(os.path.dirname(tvb_data.__file__), 'connectivity', 'paupau.zip') TestFactory.import_zip_connectivity(user, project, zip_path) figure_service = FigureService() figure_service.store_result_figure(project, user, "png", IMG_DATA, "bla") figure_service.store_result_figure(project, user, "png", IMG_DATA, "bla") figures = list( figure_service.retrieve_result_figures(project, user)[0].values())[0] assert 2 == len(figures) # export, delete and the import project self.zip_path = ExportManager().export_project(project) assert self.zip_path is not None, "Exported file is none" self.project_service.remove_project(project.id) self.import_service.import_project_structure(self.zip_path, user.id) # Check that state is as before export: one operation, one DT, 2 figures retrieved_project = self.project_service.retrieve_projects_for_user( user.id)[0][0] count_operations = dao.get_filtered_operations(retrieved_project.id, None, is_count=True) assert 1 == count_operations count_datatypes = dao.count_datatypes(retrieved_project.id, DataType) assert 1 == count_datatypes figures = list( figure_service.retrieve_result_figures(retrieved_project, user)[0].values())[0] assert 2 == len(figures) assert "bla" in figures[0].name assert "bla" in figures[1].name image_path = utils.url2path(figures[0].file_path) img_data = Image.open(image_path).load() assert img_data is not None
def test_store_and_retrieve_image(self): self.store_test_png() figures = self.retrieve_images() assert 1 == len(figures) image_path = utils.url2path(figures[0].file_path) self.assertCanReadImage(image_path)
def test_store_and_retrieve_image(self): self.store_test_png() figures = self.retrieve_images() self.assertEqual(1, len(figures)) image_path = utils.url2path(figures[0].file_path) self.assertCanReadImage(image_path)