def test_set_resource_owner(self): # create a user to be used for creating the resource user_creator = hydroshare.create_account( '*****@*****.**', username='******', first_name='Creator_FirstName', last_name='Creator_LastName', superuser=False, groups=[] ) # create a user to be set as the resource owner user_owner = hydroshare.create_account( '*****@*****.**', username='******', first_name='Pabitra', last_name='Dash', superuser=False, groups=[] ) # create a user who is not a resource owner user_non_owner = hydroshare.create_account( '*****@*****.**', username='******', first_name='Pabitra', last_name='Dash', superuser=False, groups=[] ) # create a resource without any owner resource = GenericResource.objects.create( user=user_creator, title='My resource', creator=user_creator, last_changed_by=user_creator, doi='doi1000100010001' ) # set the resource owner - this is the api we are testing hydroshare.set_resource_owner(resource.short_id, user_owner) # test that the user we set as the owner of the resource is one of the resource owners self.assertTrue(resource.owners.filter(pk=user_owner.pk).exists(), msg='user_owner not one of the owners of this resource') self.assertFalse(resource.owners.filter(pk=user_non_owner.pk).exists(), msg='user_non_owner is one of the owners of this resource') # test that there is only one resource owner at this point self.assertEqual( 1, resource.owners.all().count(), msg="More than one resource owners found." )
def test_set_resource_owner(self): # create a user to be used for creating the resource user_creator = hydroshare.create_account( '*****@*****.**', username='******', first_name='Creator_FirstName', last_name='Creator_LastName', superuser=False, groups=[]) # create a user to be set as the resource owner user_owner = hydroshare.create_account('*****@*****.**', username='******', first_name='Pabitra', last_name='Dash', superuser=False, groups=[]) # create a user who is not a resource owner user_non_owner = hydroshare.create_account('*****@*****.**', username='******', first_name='Pabitra', last_name='Dash', superuser=False, groups=[]) # create a resource without any owner resource = GenericResource.objects.create(user=user_creator, title='My resource', creator=user_creator, last_changed_by=user_creator, doi='doi1000100010001') # set the resource owner - this is the api we are testing hydroshare.set_resource_owner(resource.short_id, user_owner) # test that the user we set as the owner of the resource is one of the resource owners self.assertTrue( resource.owners.filter(pk=user_owner.pk).exists(), msg='user_owner not one of the owners of this resource') self.assertFalse( resource.owners.filter(pk=user_non_owner.pk).exists(), msg='user_non_owner is one of the owners of this resource') # test that there is only one resource owner at this point self.assertEqual(1, resource.owners.all().count(), msg="More than one resource owners found.")
def set_resource_owner(self, request, pk): res, _, _ = authorize(request, pk, full=True, superuser=True) params = SetResourceOwner.SetResourceOwnerForm(request.REQUEST) if params.is_valid(): r = params.cleaned_data tgt = user_from_id(r['user']) return HttpResponse(hydroshare.set_resource_owner(pk=res, user=tgt), content_type='text/plain') else: raise exceptions.ValidationError("invalid input parameters")
def set_resource_owner(self, request, pk): res, _, _ = authorize(request, pk, full=True, superuser=True) params = utils.create_form(SetResourceOwner.SetResourceOwnerForm, self.request) if params.is_valid(): r = params.cleaned_data tgt = user_from_id(r['user']) return HttpResponse(hydroshare.set_resource_owner(pk=res, user=tgt), content_type='text/plain', status='201') else: raise exceptions.ValidationError("invalid input parameters")