def test_set_file_type_to_refts(self): # here we are using a valid time series json file for setting it # to RefTimeSeries file type which includes metadata extraction self.refts_file_obj = open(self.refts_file, 'r') self._create_composite_resource(title="Untitled resource") self.assertEqual(self.composite_resource.files.all().count(), 1) res_file = self.composite_resource.files.first() # check that the resource file is associated with GenericLogicalFile self.assertEqual(res_file.has_logical_file, True) self.assertEqual(res_file.logical_file_type_name, "GenericLogicalFile") # check that there is one GenericLogicalFile object self.assertEqual(GenericLogicalFile.objects.count(), 1) # check that there is no RefTimeseriesLogicalFile object self.assertEqual(RefTimeseriesLogicalFile.objects.count(), 0) # set the json file to RefTimeseries file type RefTimeseriesLogicalFile.set_file_type(self.composite_resource, res_file.id, self.user) # test extracted ref time series file type metadata assert_ref_time_series_file_type_metadata(self) # test that the content of the json file is same is what we have # saved in json_file_content field of the file metadata object res_file = self.composite_resource.files.first() logical_file = res_file.logical_file self.assertEqual(logical_file.metadata.json_file_content, res_file.resource_file.read()) self.composite_resource.delete()
def test_refts_set_file_type_to_reftimeseries(self): # only do federation testing when REMOTE_USE_IRODS is True and irods docker containers # are set up properly if not super(RefTimeSeriesFileTypeMetaDataTest, self).is_federated_irods_available(): return # here we are using a valid ref time series for setting it # to RefTimeseries file type which includes metadata extraction fed_test_file_full_path = '/{zone}/home/{username}/{fname}'.format( zone=settings.HS_USER_IRODS_ZONE, username=self.user.username, fname=self.refts_file_name) res_upload_files = [] fed_res_path = hydroshare.utils.get_federated_zone_home_path(fed_test_file_full_path) res_title = 'Untitled resource' self.composite_resource = hydroshare.create_resource( resource_type='CompositeResource', owner=self.user, title=res_title, files=res_upload_files, source_names=[fed_test_file_full_path], fed_res_path=fed_res_path, move=False, metadata=[] ) # test resource is created on federated zone self.assertNotEqual(self.composite_resource.resource_federation_path, '') # set the logical file -which get sets as part of the post resource creation signal resource_post_create_actions(resource=self.composite_resource, user=self.user, metadata=self.composite_resource.metadata) self.assertEqual(self.composite_resource.files.all().count(), 1) res_file = self.composite_resource.files.first() # check that the resource file is associated with GenericLogicalFile self.assertEqual(res_file.has_logical_file, True) self.assertEqual(res_file.logical_file_type_name, "GenericLogicalFile") # check that there is one GenericLogicalFile object self.assertEqual(GenericLogicalFile.objects.count(), 1) fed_file_path = "data/contents/{}".format(self.refts_file_name) self.assertEqual(os.path.join('data', 'contents', res_file.short_path), fed_file_path) # set the tif file to RefTimeseries file type RefTimeseriesLogicalFile.set_file_type(self.composite_resource, res_file.id, self.user) # test that the content of the json file is same is what we have # saved in json_file_content field of the file metadata object res_file = self.composite_resource.files.first() logical_file = res_file.logical_file self.assertEqual(logical_file.metadata.json_file_content, res_file.fed_resource_file.read()) # test extracted ref time series file type metadata assert_ref_time_series_file_type_metadata(self) self.composite_resource.delete()
def test_refts_set_file_type_to_reftimeseries(self): super(RefTimeSeriesFileTypeMetaDataTest, self).assert_federated_irods_available() # here we are using a valid ref time series for setting it # to RefTimeseries file type which includes metadata extraction fed_test_file_full_path = '/{zone}/home/{username}/{fname}'.format( zone=settings.HS_USER_IRODS_ZONE, username=self.user.username, fname=self.refts_file_name) res_upload_files = [] fed_res_path = hydroshare.utils.get_federated_zone_home_path( fed_test_file_full_path) res_title = 'Untitled resource' self.composite_resource = hydroshare.create_resource( resource_type='CompositeResource', owner=self.user, title=res_title, files=res_upload_files, source_names=[fed_test_file_full_path], fed_res_path=fed_res_path, move=False, metadata=[], auto_aggregate=False) # test resource is created on federated zone self.assertNotEqual(self.composite_resource.resource_federation_path, '') self.assertEqual(self.composite_resource.files.all().count(), 1) res_file = self.composite_resource.files.first() # check that the resource file is not associated with any logical file self.assertEqual(res_file.has_logical_file, False) fed_file_path = "data/contents/{}".format(self.refts_file_name) self.assertEqual(os.path.join('data', 'contents', res_file.short_path), fed_file_path) # set the tif file to RefTimeseries file type RefTimeseriesLogicalFile.set_file_type(self.composite_resource, self.user, res_file.id) # test that the content of the json file is same is what we have # saved in json_file_content field of the file metadata object res_file = self.composite_resource.files.first() logical_file = res_file.logical_file self.assertEqual(logical_file.metadata.json_file_content, res_file.fed_resource_file.read()) # test extracted ref time series file type metadata assert_ref_time_series_file_type_metadata(self) self.composite_resource.delete()
def test_create_aggregation_2(self): # here we are using a valid time series json file for setting it # to RefTimeSeries file type which includes metadata extraction # this resource file is in a folder self.res_title = "Untitled resource" self.create_composite_resource() new_folder = 'refts_folder' ResourceFile.create_folder(self.composite_resource, new_folder) # add the the json file to the resource at the above folder self.add_file_to_resource(file_to_add=self.refts_file, upload_folder=new_folder) self.assertEqual(self.composite_resource.files.all().count(), 1) res_file = self.composite_resource.files.first() # test resource file is in a folder self.assertEqual(res_file.file_folder, new_folder) # check that the resource file is not associated with any logical file self.assertEqual(res_file.has_logical_file, False) # check that there is no RefTimeseriesLogicalFile object self.assertEqual(RefTimeseriesLogicalFile.objects.count(), 0) # set the json file to RefTimeseries file type RefTimeseriesLogicalFile.set_file_type(self.composite_resource, self.user, res_file.id) res_file = self.composite_resource.files.first() # check that there is one RefTimeseriesLogicalFile object self.assertEqual(RefTimeseriesLogicalFile.objects.count(), 1) # test resource file is in the same folder self.assertEqual(res_file.file_folder, new_folder) self.assertEqual(res_file.logical_file_type_name, self.logical_file_type_name) # test extracted ref time series file type metadata assert_ref_time_series_file_type_metadata(self) # test that the content of the json file is same is what we have # saved in json_file_content field of the file metadata object res_file = self.composite_resource.files.first() logical_file = res_file.logical_file self.assertEqual(logical_file.metadata.json_file_content, res_file.resource_file.read()) # test resource file is in a folder self.assertEqual(res_file.file_folder, new_folder) self.composite_resource.delete()
def test_refts_set_file_type_to_reftimeseries(self): super(RefTimeSeriesFileTypeMetaDataTest, self).assert_federated_irods_available() # here we are using a valid ref time series for setting it # to RefTimeseries file type which includes metadata extraction fed_test_file_full_path = '/{zone}/home/{username}/{fname}'.format( zone=settings.HS_USER_IRODS_ZONE, username=self.user.username, fname=self.refts_file_name) res_upload_files = [] fed_res_path = hydroshare.utils.get_federated_zone_home_path(fed_test_file_full_path) res_title = 'Untitled resource' self.composite_resource = hydroshare.create_resource( resource_type='CompositeResource', owner=self.user, title=res_title, files=res_upload_files, source_names=[fed_test_file_full_path], fed_res_path=fed_res_path, move=False, metadata=[], auto_aggregate=False ) # test resource is created on federated zone self.assertNotEqual(self.composite_resource.resource_federation_path, '') self.assertEqual(self.composite_resource.files.all().count(), 1) res_file = self.composite_resource.files.first() # check that the resource file is not associated with any logical file self.assertEqual(res_file.has_logical_file, False) fed_file_path = "data/contents/{}".format(self.refts_file_name) self.assertEqual(os.path.join('data', 'contents', res_file.short_path), fed_file_path) # set the tif file to RefTimeseries file type RefTimeseriesLogicalFile.set_file_type(self.composite_resource, self.user, res_file.id) # test that the content of the json file is same is what we have # saved in json_file_content field of the file metadata object res_file = self.composite_resource.files.first() logical_file = res_file.logical_file self.assertEqual(logical_file.metadata.json_file_content, res_file.fed_resource_file.read()) # test extracted ref time series file type metadata assert_ref_time_series_file_type_metadata(self) self.composite_resource.delete()