def tearDown(self): for r in self.resources_to_delete: resource.delete_resource(r) for g in self.groups_to_delete: g.delete() self.user.delete()
def handle(self, *args, **options): if len(options['resource_ids']) > 0: # an array of resource short_id to check. for rid in options['resource_ids']: try: BaseResource.objects.get(short_id=rid) delete_resource(rid) print("Resource with id {} DELETED from Django".format(rid)) except BaseResource.DoesNotExist: print("Resource with id {} NOT FOUND in Django".format(rid))
def handle(self, *args, **options): if len(options['resource_ids'] ) > 0: # an array of resource short_id to check. for rid in options['resource_ids']: try: BaseResource.objects.get(short_id=rid) delete_resource(rid) print( "Resource with id {} DELETED from Django".format(rid)) except BaseResource.DoesNotExist: print( "Resource with id {} NOT FOUND in Django".format(rid))
def test_delete_resource(self): new_res = resource.create_resource( 'GenericResource', self.user, 'My Test Resource' ) # there should be one resource at this point self.assertEquals(GenericResource.objects.all().count(), 1, msg="Number of resources not equal to 1") # delete the resource - this is the api we are testing resource.delete_resource(new_res.short_id) # there should be no resource at this point self.assertEquals(GenericResource.objects.all().count(), 0, msg="Number of resources not equal to 0")
def test_delete_resource(self): new_res = resource.create_resource( 'GenericResource', self.user, 'My Test Resource' ) # there should be one resource at this point self.assertEqual(GenericResource.objects.all().count(), 1, msg="Number of resources not equal to 1") # delete the resource - this is the api we are testing resource.delete_resource(new_res.short_id) # there should be no resource at this point self.assertEqual(GenericResource.objects.all().count(), 0, msg="Number of resources not equal to 0")
def test_delete_resource(self): new_res = resource.create_resource('GenericResource', self.user, 'My Test Resource') self.pid = new_res.short_id # get the resource by pid try: resource.get_resource(self.pid) except Http404: self.fail('just created resource doesnt exist for some reason') # delete the resource resource.delete_resource(self.pid) # try to get the resource again try: resource.get_resource(self.pid), Http404 except Http404: pass else: self.fail('resource continues to persist')
def test_delete_resource(self): new_res = resource.create_resource( 'GenericResource', self.user, 'My Test Resource' ) self.pid = new_res.short_id # get the resource by pid try: resource.get_resource(self.pid) except Http404: self.fail('just created resource doesnt exist for some reason') # delete the resource resource.delete_resource(self.pid) # try to get the resource again try: resource.get_resource(self.pid), Http404 except Http404: pass else: self.fail('resource continues to persist')
def test_resource_operations_in_user_zone(self): # only do federation testing when REMOTE_USE_IRODS is True and irods docker containers # are set up properly if not super(TestUserZoneIRODSFederation, self).is_federated_irods_available(): return # test resource creation and "move" option in federated user zone fed_test_file_full_path = '/{zone}/home/testuser/{fname}'.format( zone=settings.HS_USER_IRODS_ZONE, fname=self.file_to_be_deleted) res = resource.create_resource( resource_type='GenericResource', owner=self.user, title='My Test Generic Resource in User Zone', source_names=[fed_test_file_full_path], move=True) self.assertEqual(res.files.all().count(), 1, msg="Number of content files is not equal to 1") fed_path = '/{zone}/home/{user}'.format( zone=settings.HS_USER_IRODS_ZONE, user=settings.HS_LOCAL_PROXY_USER_IN_FED_ZONE) user_path = '/{zone}/home/testuser/'.format( zone=settings.HS_USER_IRODS_ZONE) self.assertEqual(res.resource_federation_path, fed_path) # test original file in user test zone is removed after resource creation # since True is used for move when creating the resource self.assertFalse( self.irods_storage.exists(user_path + self.file_to_be_deleted)) # test resource file deletion res.files.all().delete() self.assertEqual(res.files.all().count(), 0, msg="Number of content files is not equal to 0") # test add multiple files and 'copy' option in federated user zone fed_test_file1_full_path = '/{zone}/home/testuser/{fname}'.format( zone=settings.HS_USER_IRODS_ZONE, fname=self.file_one) fed_test_file2_full_path = '/{zone}/home/testuser/{fname}'.format( zone=settings.HS_USER_IRODS_ZONE, fname=self.file_two) hydroshare.add_resource_files( res.short_id, source_names=[fed_test_file1_full_path, fed_test_file2_full_path], move=False) # test resource has two files self.assertEqual(res.files.all().count(), 2, msg="Number of content files is not equal to 2") file_list = [] for f in res.files.all(): file_list.append(f.storage_path.split('/')[-1]) self.assertTrue( self.file_one in file_list, msg='file 1 has not been added in the resource in user zone') self.assertTrue( self.file_two in file_list, msg='file 2 has not been added in the resource in user zone') # test original two files in user test zone still exist after adding them to the resource # since False is used for move when creating the resource self.assertTrue(self.irods_storage.exists(user_path + self.file_one)) self.assertTrue(self.irods_storage.exists(user_path + self.file_two)) # test resource deletion resource.delete_resource(res.short_id) self.assertEquals(BaseResource.objects.all().count(), 0, msg='Number of resources not equal to 0') # test create new version resource in user zone fed_test_file1_full_path = '/{zone}/home/testuser/{fname}'.format( zone=settings.HS_USER_IRODS_ZONE, fname=self.file_one) ori_res = resource.create_resource( resource_type='GenericResource', owner=self.user, title='My Original Generic Resource in User Zone', source_names=[fed_test_file1_full_path], move=False) # make sure ori_res is created in federated user zone fed_path = '/{zone}/home/{user}'.format( zone=settings.HS_USER_IRODS_ZONE, user=settings.HS_LOCAL_PROXY_USER_IN_FED_ZONE) self.assertEqual(ori_res.resource_federation_path, fed_path) self.assertEqual(ori_res.files.all().count(), 1, msg="Number of content files is not equal to 1") new_res = hydroshare.create_empty_resource(ori_res.short_id, self.user) new_res = hydroshare.create_new_version_resource( ori_res, new_res, self.user) # only need to test file-related attributes # ensure new versioned resource is created in the same federation zone as original resource self.assertEqual(ori_res.resource_federation_path, new_res.resource_federation_path) # ensure new versioned resource has the same number of content files as original resource self.assertEqual(ori_res.files.all().count(), new_res.files.all().count()) # delete resources to clean up resource.delete_resource(new_res.short_id) resource.delete_resource(ori_res.short_id) # test copy resource in user zone fed_test_file1_full_path = '/{zone}/home/testuser/{fname}'.format( zone=settings.HS_USER_IRODS_ZONE, fname=self.file_one) ori_res = resource.create_resource( resource_type='GenericResource', owner=self.user, title='My Original Generic Resource in User Zone', source_names=[fed_test_file1_full_path], move=False) # make sure ori_res is created in federated user zone fed_path = '/{zone}/home/{user}'.format( zone=settings.HS_USER_IRODS_ZONE, user=settings.HS_LOCAL_PROXY_USER_IN_FED_ZONE) self.assertEqual(ori_res.resource_federation_path, fed_path) self.assertEqual(ori_res.files.all().count(), 1, msg="Number of content files is not equal to 1") new_res = hydroshare.create_empty_resource(ori_res.short_id, self.user, action='copy') new_res = hydroshare.copy_resource(ori_res, new_res) # only need to test file-related attributes # ensure new copied resource is created in the same federation zone as original resource self.assertEqual(ori_res.resource_federation_path, new_res.resource_federation_path) # ensure new copied resource has the same number of content files as original resource self.assertEqual(ori_res.files.all().count(), new_res.files.all().count()) # delete resources to clean up resource.delete_resource(new_res.short_id) resource.delete_resource(ori_res.short_id) # test folder operations in user zone fed_file1_full_path = '/{zone}/home/testuser/{fname}'.format( zone=settings.HS_USER_IRODS_ZONE, fname=self.file_one) fed_file2_full_path = '/{zone}/home/testuser/{fname}'.format( zone=settings.HS_USER_IRODS_ZONE, fname=self.file_two) fed_file3_full_path = '/{zone}/home/testuser/{fname}'.format( zone=settings.HS_USER_IRODS_ZONE, fname=self.file_three) self.res = resource.create_resource( resource_type='GenericResource', owner=self.user, title='My Original Generic Resource in User Zone', source_names=[ fed_file1_full_path, fed_file2_full_path, fed_file3_full_path ], move=False) # make sure self.res is created in federated user zone fed_path = '/{zone}/home/{user}'.format( zone=settings.HS_USER_IRODS_ZONE, user=settings.HS_LOCAL_PROXY_USER_IN_FED_ZONE) self.assertEqual(self.res.resource_federation_path, fed_path) # resource should has only three files at this point self.assertEqual(self.res.files.all().count(), 3, msg="resource file count didn't match") self.file_name_list = [self.file_one, self.file_two, self.file_three] super(TestUserZoneIRODSFederation, self).resource_file_oprs() # delete resources to clean up resource.delete_resource(self.res.short_id) # test adding files from federated user zone to an empty resource # created in hydroshare zone res = resource.create_resource( resource_type='GenericResource', owner=self.user, title='My Test Generic Resource in HydroShare Zone') self.assertEqual(res.files.all().count(), 0, msg="Number of content files is not equal to 0") fed_test_file1_full_path = '/{zone}/home/testuser/{fname}'.format( zone=settings.HS_USER_IRODS_ZONE, fname=self.file_one) hydroshare.add_resource_files(res.short_id, source_names=[fed_test_file1_full_path], move=False) # test resource has one file self.assertEqual(res.files.all().count(), 1, msg="Number of content files is not equal to 1") file_list = [] for f in res.files.all(): file_list.append(os.path.basename(f.storage_path)) self.assertTrue( self.file_one in file_list, msg='file 1 has not been added in the resource in hydroshare zone') # test original file in user test zone still exist after adding it to the resource # since 'copy' is used for fed_copy_or_move when adding the file to the resource self.assertTrue(self.irods_storage.exists(user_path + self.file_one)) # test replication of this resource to user zone hydroshare.replicate_resource_bag_to_user_zone(self.user, res.short_id) self.assertTrue(self.irods_storage.exists(user_path + res.short_id + '.zip'), msg='replicated resource bag is not in the user zone') # test resource deletion resource.delete_resource(res.short_id) self.assertEquals(BaseResource.objects.all().count(), 0, msg='Number of resources not equal to 0') # test to make sure original file still exist after resource deletion self.assertTrue(self.irods_storage.exists(user_path + self.file_one))
def tearDown(self): resource.delete_resource(self.pid) self.group.delete() self.user.delete()
def tearDown(self): for r in self.resources_to_delete: resource.delete_resource(r) self.user.delete()
def test_get_resources_by_type(self): # This tests the ability to filter resources by type # Note: print statements are for debugging assertion failures only print '**********************\n' * 5 print '******* STDOUT *******' print '**********************\n' * 5 group, _ = Group.objects.get_or_create(name='Hydroshare Author') print 'Created Group : '+str(group) # create a user user = users.create_account( '*****@*****.**', username='******', first_name='some_first_name', last_name='some_last_name', superuser=False, groups=[group]) # get the user's id userid = User.objects.get(username=user).pk print 'UserID : '+ str(userid) group = users.create_group('MyGroup',members=[user],owners=[user]) print 'Assigned User To Group' # create a generic resource new_res = resource.create_resource( 'GenericResource',user,'My Test GenericResource Resource') pid = new_res.short_id print 'Created GenericResource, PID : '+str(pid) # create a raster resource new_res = resource.create_resource( 'RefTimeSeries',user,'My Test RefTimeSeries Resource') pid = new_res.short_id print 'Created RefTimeSeries 1, PID : '+str(pid) # create a raster resource new_res = resource.create_resource( 'RefTimeSeries',user,'My Test RefTimeSeries Resource2') pid = new_res.short_id print 'Created RefTimeSeries 2, PID : '+str(pid) # create a rhyssys resource new_res = resource.create_resource( 'InstResource',user,'My Test InstResource Resource') pid = new_res.short_id print 'Created InstResource, PID : '+str(pid) res_types_all = hydroshare.get_resource_list(user=user) print '\nQuery All Resources: ' print 'Resource Type \t:\t Number of Resources Found' print '------------- \t:\t -------------------------' for k,v in res_types_all.iteritems(): print k.__name__+ '\t:\t '+ str(len(res_types_all[k])) res_names = [r.__name__ for r in res_types_all] self.assertTrue('GenericResource' in res_names) self.assertTrue('RefTimeSeries' in res_names) self.assertTrue('InstResource' in res_names) res_types_one = hydroshare.get_resource_list( user=user,types=['GenericResource']) print '\nQuery One Resource: ' print 'Resource Type \t:\t Number of Resources Found' print '------------- \t:\t -------------------------' for k,v in res_types_one.iteritems(): print k.__name__+ '\t:\t '+ str(len(res_types_one[k])) res_names = [r.__name__ for r in res_types_one] self.assertTrue('GenericResource' in res_names) self.assertTrue('RefTimeSeries' not in res_names) self.assertTrue('InstResource' not in res_names) res_types_multiple = hydroshare.get_resource_list( user=user,types=['GenericResource','RefTimeSeries']) print '\nQuery Multiple Resources: ' print 'Resource Type \t:\t Number of Resources Found' print '------------- \t:\t -------------------------' for k,v in res_types_multiple.iteritems(): print k.__name__+ '\t:\t '+ str(len(res_types_multiple[k])) res_names = [r.__name__ for r in res_types_multiple] self.assertTrue('GenericResource' in res_names) self.assertTrue('RefTimeSeries' in res_names) self.assertTrue('InstResource' not in res_names) # delete the resource resource.delete_resource(pid)