def setUp(self): super(T04CreateGroup, self).setUp() global_reset() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.admin = hydroshare.create_account( '*****@*****.**', username='******', first_name='administrator', last_name='couch', superuser=True, groups=[] ) self.cat = hydroshare.create_account( '*****@*****.**', username='******', first_name='not a dog', last_name='last_name_cat', superuser=False, groups=[] ) self.dog = hydroshare.create_account( '*****@*****.**', username='******', first_name='a little arfer', last_name='last_name_dog', superuser=False, groups=[] )
def setUp(self): super(T01BasicFunction, self).setUp() global_reset() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.cat = hydroshare.create_account( '*****@*****.**', username='******', first_name='f_cat', last_name='l_cat', superuser=False, groups=[] ) self.dog = hydroshare.create_account( '*****@*****.**', username='******', first_name='f_dog', last_name='l_dog', superuser=False, groups=[] ) self.scratching = hydroshare.create_resource(resource_type='GenericResource', owner=self.cat, title='Test Resource', metadata=[],) self.bones = hydroshare.create_resource(resource_type='GenericResource', owner=self.dog, title='all about dog bones', metadata=[],)
def setUp(self): # create two users self.user1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Creator_FirstName', last_name='Creator_LastName', superuser=False, groups=[] ) self.user2 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Creator2_FirstName', last_name='Creator2_LastName', superuser=False, groups=[] ) # create a group self.group = hydroshare.create_group( 'Test group', members=[], owners=[self.user1] ) # create a resource self.res = hydroshare.create_resource( 'GenericResource', self.user1, 'Test Resource', #edit_groups=[self.group], edit_users=[self.user1, self.user2] )
def setUp(self): super(T15CreateGroup, self).setUp() global_reset() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.admin = hydroshare.create_account( '*****@*****.**', username='******', first_name='administrator', last_name='couch', superuser=True, groups=[] ) self.cat = hydroshare.create_account( '*****@*****.**', username='******', first_name='not a dog', last_name='last_name_cat', superuser=False, groups=[] ) self.dog = hydroshare.create_account( '*****@*****.**', username='******', first_name='a little arfer', last_name='last_name_dog', superuser=False, groups=[] ) self.meowers = self.cat.uaccess.create_group( title='meowers', description='We are the meowers group')
def setUp(self): super(TestUtils, self).setUp() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.user = hydroshare.create_account( '*****@*****.**', username='******', first_name='Creator_FirstName', last_name='Creator_LastName', superuser=False, groups=[] ) self.user2 = hydroshare.create_account( '*****@*****.**', username='******', first_name='user2_FirstName', last_name='user2_LastName', superuser=False, groups=[] ) self.res = hydroshare.create_resource( 'GenericResource', self.user, 'test resource', ) self.res.doi = 'doi1000100010001' self.res.save()
def setUp(self): super(TestGroup, self).setUp() patcher_email_send_call = patch('hs_core.views.send_action_to_take_email') patcher_email_send_call.start() self.addCleanup(patcher_email_send_call.stop) self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.username = '******' self.password = '******' self.john = hydroshare.create_account( '*****@*****.**', username=self.username, first_name='John', last_name='Clarson', superuser=False, password=self.password, groups=[] ) self.mike = hydroshare.create_account( '*****@*****.**', username='******', first_name='Mike', last_name='Jensen', superuser=False, groups=[] ) # create a resource for sharing with group self.resource = hydroshare.create_resource(resource_type='GenericResource', owner=self.john, title='Test Resource', metadata=[] )
def setUp(self): super(TestSetDownloadAgreement, self).setUp() self.hs_group, _ = Group.objects.get_or_create(name='Hydroshare Author') # create a user self.user_owner = hydroshare.create_account( '*****@*****.**', username='******', first_name='some_first_name_owner', last_name='some_last_name_owner', superuser=False, groups=[self.hs_group] ) self.user_non_owner = hydroshare.create_account( '*****@*****.**', username='******', first_name='some_first_name_non_owner', last_name='some_last_name_non_owner', superuser=False, groups=[self.hs_group] ) self.res = resource.create_resource( 'GenericResource', self.user_owner, 'My Test Resource' )
def setUp(self): super(TestExplicitGroupAccess, self).setUp() self.hs_group, _ = Group.objects.get_or_create( name='Hydroshare Author') self.grp_creator_user = hydroshare.create_account( '*****@*****.**', username='******', first_name='Group', last_name='Creator', superuser=False, groups=[] ) self.user_A = hydroshare.create_account( '*****@*****.**', username='******', first_name='UserA', last_name='Last Name A', superuser=False, groups=[] ) self.user_B = hydroshare.create_account( '*****@*****.**', username='******', first_name='UserB', last_name='Last Name B', superuser=False, groups=[] ) # grp_creator_user owns group_test group self.group_test = self.grp_creator_user.uaccess\ .create_group(title='Test Group', description="This group is all about testing")
def setUp(self): super(TestChangeQuotaHolder, self).setUp() self.hs_group, _ = Group.objects.get_or_create(name='Hydroshare Author') # create two users self.user1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='owner1_first_name', last_name='owner1_last_name', superuser=False, groups=[self.hs_group] ) self.user2 = hydroshare.create_account( '*****@*****.**', username='******', first_name='owner2_first_name', last_name='owner2_last_name', superuser=False, groups=[self.hs_group] ) self.res = hydroshare.create_resource( resource_type='GenericResource', owner=self.user1, title='My Test Resource' ) # test to make sure one owner can transfer quota holder to another owner self.user1.uaccess.share_resource_with_user(self.res, self.user2, PrivilegeCodes.OWNER)
def setUp(self): super(TestGetUserData, self).setUp() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.username = '******' self.password = '******' self.john = hydroshare.create_account( '*****@*****.**', username=self.username, first_name='John', last_name='Clarson', superuser=False, password=self.password, groups=[] ) self.mike = hydroshare.create_account( '*****@*****.**', username='******', first_name='Mike', last_name='Jensen', superuser=False, groups=[] ) self.factory = RequestFactory()
def setUp(self): super(TestNewVersionResource, self).setUp() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') # create a user who is the owner of the resource to be versioned self.owner = hydroshare.create_account( '*****@*****.**', username='******', first_name='owner_firstname', last_name='owner_lastname', superuser=False, groups=[] ) # create a user who is NOT the owner of the resource to be versioned self.nonowner = hydroshare.create_account( '*****@*****.**', username='******', first_name='nonowner_firstname', last_name='nonowner_lastname', superuser=False, groups=[] ) # create a generic resource self.res_generic = hydroshare.create_resource( resource_type='GenericResource', owner=self.owner, title='Test Generic Resource' ) test_file1 = open('test1.txt', 'w') test_file1.write("Test text file in test1.txt") test_file1.close() test_file2 = open('test2.txt', 'w') test_file2.write("Test text file in test2.txt") test_file2.close() self.test_file1 = open('test1.txt', 'r') self.test_file2 = open('test2.txt', 'r') hydroshare.add_resource_files(self.res_generic.short_id, self.test_file1, self.test_file2) # create a raster resource that represents a specific resource type raster_file = 'hs_core/tests/data/cea.tif' temp_dir = tempfile.mkdtemp() temp_raster_file = os.path.join(temp_dir, 'cea.tif') shutil.copy(raster_file, temp_raster_file) self.raster_obj = open(temp_raster_file, 'r') files = [UploadedFile(file=self.raster_obj, name='cea.tif')] self.res_raster = hydroshare.create_resource( resource_type='RasterResource', owner=self.owner, title='Test Raster Resource', files=files, metadata=[] ) # call the post creation process here for the metadata to be # extracted utils.resource_post_create_actions(resource=self.res_raster, user=self.owner, metadata=[])
def test_create_group(self): user1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Jefferson', last_name='Heard', superuser=False, groups=[] ) user2 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Jefferson', last_name='Heard', superuser=False, groups=[] ) a_group = hydroshare.create_group( 'A Group', members=[user1, user2], owners=[user1]) # test attempt to add a duplicate user self.assertRaises( IntegrityError, lambda: hydroshare.create_group('A Group') ) # test that the group is the same in the database self.assertEqual( a_group, Group.objects.get(name='A Group') ) self.assertIn( user1, [a for a in hydroshare.list_group_members(a_group)], msg='user1 not listed in the group membership list' ) self.assertIn( user2, [a for a in hydroshare.list_group_members(a_group)], msg='user2 not listed in the group membership list' ) self.assertIn( user1, [a for a in GroupOwnership.objects.filter(group=a_group)], msg='user1 not listed in the group ownership list' ) self.assertNotIn( user1, [a for a in GroupOwnership.objects.filter(group=a_group)], msg='user2 listed in the group ownership list' )
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_create_account(self): a_group = hydroshare.create_group('A Group') # create a user with everything put in fully_specified_user = hydroshare.create_account( '*****@*****.**', username='******', first_name='Jefferson', last_name='Heard', superuser=False, groups=[a_group] ) user_without_username = hydroshare.create_account( '*****@*****.**', first_name='Jefferson', last_name='Heard', superuser=False, groups=[a_group] ) self.assertEqual( fully_specified_user.username, 'jeff', msg='Username got overwritten' ) self.assertEqual( User.objects.get(username='******'), fully_specified_user ) self.assertEqual( User.objects.get(username='******'), user_without_username ) # test attempt to add a duplicate user self.assertRaises( IntegrityError, lambda: hydroshare.create_account( '*****@*****.**', username='******', first_name='Jefferson', last_name='Heard', superuser=False, groups=[a_group] ) ) self.assertIn( fully_specified_user, [a for a in hydroshare.list_group_members(a_group)], msg='user not listed in the group membership list' )
def setUp(self): super(UnitTests, self).setUp() global_reset() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.alva = hydroshare.create_account( '*****@*****.**', username='******', first_name='alva', last_name='couch', superuser=False, groups=[] ) self.george = hydroshare.create_account( '*****@*****.**', username='******', first_name='george', last_name='miller', superuser=False, groups=[] ) self.john = hydroshare.create_account( '*****@*****.**', username='******', first_name='john', last_name='miller', superuser=False, groups=[] ) self.admin = hydroshare.create_account( '*****@*****.**', username='******', first_name='first_name_admin', last_name='last_name_admin', superuser=True, groups=[] ) # george creates a entity 'bikes' self.bikes = hydroshare.create_resource( resource_type='GenericResource', owner=self.george, title='Bikes', metadata=[], ) # george creates a entity 'bikers' self.bikers = self.george.uaccess.create_group('Bikers', 'Of the human powered kind') # george creates a community 'rebels' self.rebels = self.george.uaccess.create_community('Rebels', 'Random rebels')
def setUp(self): super(T11ExplicitGet, self).setUp() global_reset() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.A_user = hydroshare.create_account( '*****@*****.**', username='******', first_name='A First', last_name='A Last', superuser=False, groups=[] ) self.B_user = hydroshare.create_account( '*****@*****.**', username='******', first_name='B First', last_name='B Last', superuser=False, groups=[] ) self.C_user = hydroshare.create_account( '*****@*****.**', username='******', first_name='C First', last_name='C Last', superuser=False, groups=[] ) self.r1_resource = hydroshare.create_resource( resource_type='GenericResource', owner=self.A_user, title='R1', metadata=[],) self.r2_resource = hydroshare.create_resource( resource_type='GenericResource', owner=self.A_user, title='R2', metadata=[],) self.r3_resource = hydroshare.create_resource( resource_type='GenericResource', owner=self.A_user, title='R3', metadata=[],) self.A_group = self.A_user.uaccess\ .create_group(title='Test Group A', description="This group is all about testing") self.B_group = self.B_user.uaccess\ .create_group(title='Test Group B', description="This group is all about testing") self.C_group = self.C_user.uaccess\ .create_group(title='Test Group C', description="This group is all about testing")
def setUp(self): super(UnitTests, self).setUp() global_reset() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.alva = hydroshare.create_account( '*****@*****.**', username='******', first_name='alva', last_name='couch', superuser=False, groups=[] ) self.george = hydroshare.create_account( '*****@*****.**', username='******', first_name='george', last_name='miller', superuser=False, groups=[] ) self.john = hydroshare.create_account( '*****@*****.**', username='******', first_name='john', last_name='miller', superuser=False, groups=[] ) self.admin = hydroshare.create_account( '*****@*****.**', username='******', first_name='first_name_admin', last_name='last_name_admin', superuser=True, groups=[] ) # george creates a resource 'bikes' self.bikes = hydroshare.create_resource( resource_type='GenericResource', owner=self.george, title='Bikes', metadata=[], ) # george creates a group 'bikers' self.bikers = self.george.uaccess.create_group( title='Bikers', description="We rae the bikers")
def test_create_group_no_member_two_owners(self): user_owner_1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Owner_1_FirstName', last_name='Owner_1_LastName', superuser=False, groups=[] ) user_owner_2 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Owner_2_FirstName', last_name='Owner_2_LastName', superuser=False, groups=[] ) # test we have only no group ownerships at this point self.assertEqual(GroupOwnership.objects.all().count(), 0) # test creating a group with 2 owners group_name = 'Test Group with 2 owners' test_group = hydroshare.create_group(group_name, owners=[user_owner_1, user_owner_2]) # test the group has the matching name self.assertEqual(test_group.name, group_name) # test we have only 2 group ownerships at this point self.assertEqual(GroupOwnership.objects.all().count(), 2) # test we have only 2 group ownerships for the group we created group_ownerships = GroupOwnership.objects.filter(group=test_group) self.assertEqual(len(group_ownerships), 2) # test each of the 2 group ownership has the same group self.assertEqual(group_ownerships[0].group, test_group) self.assertEqual(group_ownerships[1].group, test_group) # test we have the 2 owners in the 2 group ownerships self.assertIn(user_owner_1, [grp_ownership.owner for grp_ownership in group_ownerships], msg= '%s is not one of the group owner.' % user_owner_1 ) self.assertIn(user_owner_2, [grp_ownership.owner for grp_ownership in group_ownerships], msg= '%s is not one of the group owner.' % user_owner_2 )
def setUp(self): super(T05ShareResource, self).setUp() global_reset() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.admin = hydroshare.create_account( '*****@*****.**', username='******', first_name='administrator', last_name='couch', superuser=True, groups=[] ) self.cat = hydroshare.create_account( '*****@*****.**', username='******', first_name='not a dog', last_name='last_name_cat', superuser=False, groups=[] ) self.dog = hydroshare.create_account( '*****@*****.**', username='******', first_name='a little arfer', last_name='last_name_dog', superuser=False, groups=[] ) # use this as non owner self.mouse = hydroshare.create_account( '*****@*****.**', username='******', first_name='first_name_mouse', last_name='last_name_mouse', superuser=False, groups=[] ) self.holes = hydroshare.create_resource( resource_type='GenericResource', owner=self.cat, title='all about dog holes', metadata=[], ) self.meowers = self.cat.uaccess.create_group( title='some random meowers', description="some random group")
def test_update_group_to_add_owners(self): user_owner_1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Owner_1_FirstName', last_name='Owner_1_LastName', superuser=False, groups=[] ) user_owner_2 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Owner_2_FirstName', last_name='Owner_2_LastName', superuser=False, groups=[] ) group_name = 'Test Group' test_group = hydroshare.create_group(group_name) # test we have only no group ownerships at this point self.assertEqual(GroupOwnership.objects.all().count(), 0) # this is the api call we are testing hydroshare.update_group(test_group, owners=[user_owner_1, user_owner_2]) # test we have two group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 2) # test the group ownership has the correct group group_ownerships = GroupOwnership.objects.filter(group=test_group) # test each of the 2 group ownership has the same group self.assertEqual(group_ownerships[0].group, test_group) self.assertEqual(group_ownerships[1].group, test_group) # test we have the 2 owners in the 2 group ownerships self.assertIn(user_owner_1, [grp_ownership.owner for grp_ownership in group_ownerships], msg= '%s is not one of the group owner.' % user_owner_1 ) self.assertIn(user_owner_2, [grp_ownership.owner for grp_ownership in group_ownerships], msg= '%s is not one of the group owner.' % user_owner_2 )
def setUp(self): try: #self.user = User.objects.create_user('user1', email='*****@*****.**') self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.user = hydroshare.create_account( '*****@*****.**', username='******', first_name='Creator_FirstName', last_name='Creator_LastName', superuser=False, groups=[self.group] ) # create dublin core elements self.dublin_metadata = [] except: self.tearDown() self.user = User.objects.create_user('user1', email='*****@*****.**') #self.group, _ = Group.objects.get_or_create(name='group1') self.res, created = GenericResource.objects.get_or_create( user=self.user, title='resource', creator=self.user, last_changed_by=self.user, doi='doi1000100010001' ) if created: self.res.owners.add(self.user)
def setUp(self): super(TestModelProgramMetaData, self).setUp() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.user = hydroshare.create_account( '*****@*****.**', username='******', first_name='Creator_FirstName', last_name='Creator_LastName', superuser=False, groups=[self.group] ) self.resModelProgram = hydroshare.create_resource( resource_type='ModelProgramResource', owner=self.user, title='Test Model Program Resource' ) self.temp_dir = tempfile.mkdtemp() self.file_name = "MP.txt" temp_text_file = os.path.join(self.temp_dir, self.file_name) text_file = open(temp_text_file, 'w') text_file.write("Model Program resource files") text_file.close() self.text_file_obj = open(temp_text_file, 'r') self.file_name_2 = "MP.csv" temp_text_file_2 = os.path.join(self.temp_dir, self.file_name_2) text_file = open(temp_text_file_2, 'w') text_file.write("Model,Program,resource,file") text_file.close() self.text_file_obj_2 = open(temp_text_file_2, 'r')
def setUp(self): self.serializer = Serializer() self.logger = logging.getLogger(__name__) self.api_client = Client() self.username = '******' self.password = '******' self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') # create a user to be used for creating the resource self.user_creator = hydroshare.create_account( '*****@*****.**', username=self.username, first_name='Creator_FirstName', last_name='Creator_LastName', superuser=False, password=self.password, groups=[self.group] ) self.api_client.login(username=self.username, password=self.password) # create a resource self.resource = hydroshare.create_resource( resource_type='ToolResource', title='My resource', owner=self.user_creator, )
def setUp(self): super(TestReplicateBagToUserZone, self).setUp() super(TestReplicateBagToUserZone, self).assert_federated_irods_available() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.username = '******' self.password = '******' self.user = hydroshare.create_account( '*****@*****.**', username=self.username, first_name='John', last_name='Clarson', superuser=False, password=self.password, groups=[] ) # create corresponding irods account in user zone super(TestReplicateBagToUserZone, self).create_irods_user_in_user_zone() self.gen_res = hydroshare.create_resource( resource_type='GenericResource', owner=self.user, title='Generic Resource Key/Value Metadata Testing' ) self.factory = RequestFactory()
def setUp(self): self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.user = hydroshare.create_account( '*****@*****.**', username='******', first_name='Creator_FirstName', last_name='Creator_LastName', superuser=False, groups=[self.group] ) self.refts_res = hydroshare.create_resource( resource_type='RefTimeSeries', owner=self.user, title='Test RefTS resource') resource.create_metadata_element(self.refts_res.short_id, 'QualityControlLevel', value='test quality level') resource.create_metadata_element(self.refts_res.short_id, 'ReferenceURL', value='www.example.com', type='REST') resource.create_metadata_element(self.refts_res.short_id, 'Method', value='test method') resource.create_metadata_element( self.refts_res.short_id, 'Variable', name='test variable name', code='test code', data_type='test data type', sample_medium='test sample medium') resource.create_metadata_element( self.refts_res.short_id, 'Site', name='test site name', code='test site code', latitude=150.15, longitude=150.15)
def setUp(self): super(TestRasterMetaData, self).setUp() super(TestRasterMetaData, self).assert_federated_irods_available() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.user = hydroshare.create_account( '*****@*****.**', username='******', first_name='Creator_FirstName', last_name='Creator_LastName', superuser=False, groups=[self.group] ) super(TestRasterMetaData, self).create_irods_user_in_user_zone() self.raster_tif_file_name = 'raster_tif_valid.tif' self.raster_tif_file = 'hs_geo_raster_resource/tests/{}'.format(self.raster_tif_file_name) # transfer this valid tif file to user zone space for testing # only need to test that tif file stored in iRODS user zone space can be used to create a # raster resource with metadata automatically extracted. Other relevant tests are # adding a tif file to an existing resource, deleting a file in a raster resource from # iRODS user zone, and deleting a resource stored in iRODS user zone. Other detailed tests # don't need to be retested for irods user zone space scenario since as long as the tif # file in iRODS user zone space can be read with metadata extracted correctly, other # functionalities are done with the same common functions regardless of where the tif file # comes from, either from local disk or from a federated user zone irods_target_path = '/' + settings.HS_USER_IRODS_ZONE + '/home/' + self.user.username + '/' file_list_dict = {self.raster_tif_file: irods_target_path + self.raster_tif_file_name} super(TestRasterMetaData, self).save_files_to_user_zone(file_list_dict)
def setUp(self): self.logger = logging.getLogger(__name__) self.api_client = Client() self.username = '******' self.password = '******' self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') # create a user to be used for creating the resource self.user = hydroshare.create_account( '*****@*****.**', username=self.username, first_name='Creator_FirstName', last_name='Creator_LastName', superuser=False, password=self.password, groups=[self.group] ) self.url_to_get_his_urls = "/hsapi/_internal/get-his-urls/" self.url_to_search_sites = "/hsapi/_internal/search-sites/" self.url_to_search_variables = "/hsapi/_internal/search-variables/" self.url_to_time_series_from_service = "/hsapi/_internal/time-series-from-service/" self.url_to_create_ref_time_series = "/hsapi/_internal/create-ref-time-series/" self.url_to_download_resource_files = "/hsapi/_internal/{0}/download-refts-bag/"
def setUp(self): self.serializer = Serializer() self.logger = logging.getLogger(__name__) self.api_client = Client() self.username = '******' self.password = '******' self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') # create a user to be used for creating the resource self.user_creator = hydroshare.create_account( '*****@*****.**', username=self.username, first_name='Creator_FirstName', last_name='Creator_LastName', superuser=False, password=self.password, groups=[self.group] ) self.api_client.login(username=self.username, password=self.password) # create a resource self.resource = hydroshare.create_resource( resource_type='ToolResource', title='My resource', owner=self.user_creator, ) self.url1 = 'www.one.com' self.url2 = 'www.two.com' self.res1 = 'res_type1' self.res2 = 'res_type2' self.desc1 = 'description1' self.desc2 = 'description2' self.fee1 = Decimal('1') self.fee2 = Decimal('2') self.version1 = '1' self.version2 = '2' hydroshare.resource.create_metadata_element(self.resource.short_id, 'RequestUrlBase', value=self.url1 ) hydroshare.resource.create_metadata_element(self.resource.short_id, 'ToolResourceType', tool_res_type=self.res1 ) hydroshare.resource.create_metadata_element(self.resource.short_id, 'Fee', description=self.desc1, value=self.fee1 ) hydroshare.resource.create_metadata_element(self.resource.short_id, 'ToolVersion', value=self.version1 )
def setUp(self): super(TestCreateResource, self).setUp() self.tmp_dir = tempfile.mkdtemp() self.hs_group, _ = Group.objects.get_or_create(name='Hydroshare Author') # create a user self.user = hydroshare.create_account( '*****@*****.**', username='******', first_name='some_first_name', last_name='some_last_name', superuser=False, groups=[self.hs_group] ) # create files file_one = os.path.join(self.tmp_dir, "test1.txt") open(file_one, "w").close() # open files for read and upload self.file_one = open(file_one, "r") self.res = resource.create_resource( 'GenericResource', self.user, 'My Test Resource', files=(self.file_one,) )
def setUp(self): super(TestTickets, self).setUp() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.user = hydroshare.create_account( '*****@*****.**', username='******', first_name='Creator_FirstName', last_name='Creator_LastName', superuser=False, groups=[] ) self.res = hydroshare.create_resource( 'GenericResource', self.user, 'test resource', ) # create a file self.test_file_name1 = 'file1.txt' self.file_name_list = [self.test_file_name1, ] # put predictable contents into the file test_file = open(self.test_file_name1, 'w') test_file.write("Test text file in file1.txt") test_file.close() self.test_file_1 = open(self.test_file_name1, 'r') # add one file to the resource: necessary so data/contents is created. hydroshare.add_resource_files(self.res.short_id, self.test_file_1)
def setUp(self): self.logger = logging.getLogger(__name__) self.api_client = Client() self.username = '******' self.password = '******' self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') # create a user to be used for creating the resource self.user = hydroshare.create_account('*****@*****.**', username=self.username, first_name='Creator_FirstName', last_name='Creator_LastName', superuser=False, password=self.password, groups=[self.group]) self.url_to_get_his_urls = "/hsapi/_internal/get-his-urls/" self.url_to_search_sites = "/hsapi/_internal/search-sites/" self.url_to_search_variables = "/hsapi/_internal/search-variables/" self.url_to_time_series_from_service = "/hsapi/_internal/time-series-from-service/" self.url_to_create_ref_time_series = "/hsapi/_internal/create-ref-time-series/" self.url_to_download_resource_files = "/hsapi/_internal/{0}/download-refts-bag/"
def setUp(self): super(GenericFileTypeMetaDataTest, self).setUp() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.user = hydroshare.create_account('*****@*****.**', username='******', first_name='Creator_FirstName', last_name='Creator_LastName', superuser=False, groups=[self.group]) self.composite_resource = hydroshare.create_resource( resource_type='CompositeResource', owner=self.user, title='Test Generic File Metadata') self.temp_dir = tempfile.mkdtemp() self.generic_file_name = 'generic_file.txt' self.raster_zip_file_name = 'logan_vrt_small.zip' self.generic_file = 'hs_file_types/tests/{}'.format( self.generic_file_name) target_temp_generic_file = os.path.join(self.temp_dir, self.generic_file_name) shutil.copy(self.generic_file, target_temp_generic_file) self.generic_file_obj = open(target_temp_generic_file, 'r')
def setUp(self): super(TestGeoFeature, self).setUp() super(TestGeoFeature, self).assert_federated_irods_available() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.user = hydroshare.create_account('*****@*****.**', username='******', first_name='Zhiyu', last_name='Li', superuser=False, groups=[self.group]) super(TestGeoFeature, self).create_irods_user_in_user_zone() self.allowance = 0.00001 # transfer this valid zip file to user zone space for testing. # only need to test that file stored in iRODS user zone space can be used to create # a geo-feature resource with metadata automatically extracted. Other relevant tests are # adding a file to an existing resource, deleting a file in a resource from # iRODS user zone, and deleting a resource stored in iRODS user zone. Other detailed tests # don't need to be retested for irods user zone space scenario since as long as the # file in iRODS user zone space can be read with metadata extracted correctly, other # functionalities are done with the same common functions regardless of where the # file comes from, either from local disk or from a federated user zone irods_target_path = '/' + settings.HS_USER_IRODS_ZONE + '/home/' + self.user.username + '/' self.valid_file_name = 'states_required_files.zip' self.valid_file = 'hs_geographic_feature_resource/tests/{}'.format( self.valid_file_name) self.valid_file_name2 = 'gis.osm_adminareas_v06_all_files.zip' self.valid_file2 = 'hs_geographic_feature_resource/tests/{}'.format( self.valid_file_name2) file_list_dict = {} file_list_dict[ self.valid_file] = irods_target_path + self.valid_file_name file_list_dict[ self.valid_file2] = irods_target_path + self.valid_file_name2 super(TestGeoFeature, self).save_files_to_user_zone(file_list_dict)
def setUp(self): super(RefTimeseriesFileTypeMetaDataTest, self).setUp() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.user = hydroshare.create_account( '*****@*****.**', username='******', first_name='Creator_FirstName', last_name='Creator_LastName', superuser=False, groups=[self.group] ) self.composite_resource = hydroshare.create_resource( resource_type='CompositeResource', owner=self.user, title='Test Ref Time Series File Type Metadata' ) self.temp_dir = tempfile.mkdtemp() self.refts_file_name = 'multi_sites_formatted_version1.0.json.refts' self.refts_file = 'hs_file_types/tests/{}'.format(self.refts_file_name) target_temp_refts_file = os.path.join(self.temp_dir, self.refts_file_name) shutil.copy(self.refts_file, target_temp_refts_file)
def setUp(self): super(StaticLiveServerTestCase, self).setUp() self.driver = None self.user_password = "******" if not User.objects.filter(email='*****@*****.**'): group, _ = Group.objects.get_or_create( name='Hydroshare Author') # Model level permissions are required for some actions bc of legacy Mezzanine # Also relies on the magic "Hydroshare Author" group hs_perms = Permission.objects.filter( content_type__app_label__startswith="hs_") group.permissions.add(*list(hs_perms)) self.user = hydroshare.create_account( '*****@*****.**', username='******', first_name='User_FirstName', last_name='User_LastName', password=self.user_password, groups=[group]) self.user.save() else: self.user = User.objects.get(email='*****@*****.**')
def test_resolve_doi(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 resource new_resource = hydroshare.create_resource('GenericResource', user_creator, 'My Test Resource') # test that the api call resolve_doi() returns the short_id of the resource when we pass the # resource doi in this api call self.assertEqual(new_resource.short_id, hydroshare.resolve_doi(new_resource.doi)) # test the exception 'ObjectDoesNotExit' is raised when we make the api call # passing a random doi ( e.g., '123') that does not exist self.assertRaises(ObjectDoesNotExist, lambda: hydroshare.resolve_doi("123"))
def test_comment_on_resource(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=[]) user_commenter_1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Commenter_1_FirstName', last_name='Commenter_1_LastName', superuser=False, groups=[]) user_commenter_2 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Commenter_2_FirstName', last_name='Commenter_2_LastName', superuser=False, groups=[]) user_commenter_3 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Commenter_3_FirstName', last_name='Commenter_3_LastName', superuser=False, groups=[]) # create a resource new_resource = hydroshare.create_resource('GenericResource', user_creator, 'My Test Resource') new_resource_2 = hydroshare.create_resource('GenericResource', user_creator, 'My Test Resource 2') # test at this point we have no comments comments_count = ThreadedComment.objects.all().count() self.assertEqual(comments_count, 0) comment_text = "comment by commenter_1" # this is the api we are testing comment = hydroshare.comment_on_resource(new_resource.short_id, comment_text, user=user_commenter_1) # test at this point we have one comment comments_count = ThreadedComment.objects.all().count() self.assertEqual(comments_count, 1) self.assertEqual(comment.content_object, new_resource) self.assertEqual(comment.user, user_commenter_1) self.assertEqual(comment.comment, comment_text) # test this the lead comment self.assertEqual(comment.replied_to, None) # let the commenter-2 reply to the comment by commenter-1 comment_text = "reply comment by commenter_2" # this is the api we are testing reply_comment = hydroshare.comment_on_resource(new_resource.short_id, comment_text, user=user_commenter_2, in_reply_to=comment.id) # test at this point we have 2 comment comments_count = ThreadedComment.objects.all().count() self.assertEqual(comments_count, 2) self.assertEqual(reply_comment.content_object, new_resource) self.assertEqual(reply_comment.user, user_commenter_2) self.assertEqual(reply_comment.comment, comment_text) self.assertEqual(reply_comment.replied_to, comment) self.assertTrue(reply_comment.submit_date > comment.submit_date, True) # test this the lead comment self.assertEqual(comment.replied_to, None) # test that we can reply to the same comment twice comment_text = "reply comment by commenter_3" reply_comment = hydroshare.comment_on_resource(new_resource.short_id, comment_text, user=user_commenter_3, in_reply_to=comment.id) # test at this point we have 3 comment comments_count = ThreadedComment.objects.all().count() self.assertEqual(comments_count, 3) self.assertEqual(reply_comment.content_object, new_resource) self.assertEqual(reply_comment.user, user_commenter_3) self.assertEqual(reply_comment.comment, comment_text) self.assertEqual(reply_comment.replied_to, comment) self.assertTrue(reply_comment.submit_date > comment.submit_date, True) # test this the lead comment self.assertEqual(comment.replied_to, None) # test that the same user can comment on the same resource more than once comment_text = "another comment by commenter_1" comment = hydroshare.comment_on_resource(new_resource.short_id, comment_text, user=user_commenter_1) # test at this point we have 4 comment comments_count = ThreadedComment.objects.all().count() self.assertEqual(comments_count, 4) self.assertEqual(comment.content_object, new_resource) self.assertEqual(comment.user, user_commenter_1) self.assertEqual(comment.comment, comment_text) # test this the lead comment self.assertEqual(comment.replied_to, None) # test that one can't reply to his/her own comment comment_text = "reply to my own comment by commenter_1" self.assertRaises( ValueError, lambda: hydroshare.comment_on_resource(new_resource.short_id, comment_text, user=user_commenter_1, in_reply_to=comment.id)) # test that reply_to comment must exists for the given resource otherwise it raises value error self.assertRaises( ValueError, lambda: hydroshare.comment_on_resource(new_resource_2.short_id, comment_text, user=user_commenter_2, in_reply_to=comment.id))
def setUp(self): super(TestRasterMetaData, self).setUp() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.user = hydroshare.create_account('*****@*****.**', username='******', first_name='Creator_FirstName', last_name='Creator_LastName', superuser=False, groups=[self.group]) self.resRaster = hydroshare.create_resource( resource_type='RasterResource', owner=self.user, title='My Test Raster Resource') self.temp_dir = tempfile.mkdtemp() self.raster_tif_file_name = 'raster_tif_valid.tif' self.raster_tif_file = 'hs_geo_raster_resource/tests/{}'.format( self.raster_tif_file_name) target_temp_raster_tif_file = os.path.join(self.temp_dir, self.raster_tif_file_name) shutil.copy(self.raster_tif_file, target_temp_raster_tif_file) self.raster_tif_file_obj = open(target_temp_raster_tif_file, 'r') self.raster_bearcr_tif_file_name = 'BearCk.tif' self.raster_bearcr_tif_file = 'hs_geo_raster_resource/tests/{}'.format( self.raster_bearcr_tif_file_name) target_temp_raster_bearcr_tif_file = os.path.join( self.temp_dir, self.raster_bearcr_tif_file_name) shutil.copy(self.raster_bearcr_tif_file, target_temp_raster_bearcr_tif_file) self.raster_bearcr_tif_file_obj = open( target_temp_raster_bearcr_tif_file, 'r') self.raster_honduras_tif_file_name = 'Honduras.tif' self.raster_honduras_tif_file = 'hs_geo_raster_resource/tests/{}'.format( self.raster_honduras_tif_file_name) target_temp_raster_honduras_tif_file = os.path.join( self.temp_dir, self.raster_honduras_tif_file_name) shutil.copy(self.raster_honduras_tif_file, target_temp_raster_honduras_tif_file) self.raster_honduras_tif_file_obj = open( target_temp_raster_honduras_tif_file, 'r') self.raster_mawhefel_tif_file_name = 'mawhefel.tif' self.raster_mawhefel_tif_file = 'hs_geo_raster_resource/tests/{}'.format( self.raster_mawhefel_tif_file_name) target_temp_raster_mawhefel_tif_file = os.path.join( self.temp_dir, self.raster_mawhefel_tif_file_name) shutil.copy(self.raster_mawhefel_tif_file, target_temp_raster_mawhefel_tif_file) self.raster_mawhefel_tif_file_obj = open( target_temp_raster_mawhefel_tif_file, 'r') self.raster_lidardem_tif_file_name = 'lidarDem.tif' self.raster_lidardem_tif_file = 'hs_geo_raster_resource/tests/{}'.format( self.raster_lidardem_tif_file_name) target_temp_raster_lidardem_tif_file = os.path.join( self.temp_dir, self.raster_lidardem_tif_file_name) shutil.copy(self.raster_lidardem_tif_file, target_temp_raster_lidardem_tif_file) self.raster_lidardem_tif_file_obj = open( target_temp_raster_lidardem_tif_file, 'r') self.raster_htelevation_tif_file_name = 'HT_Elevation.tif' self.raster_htelevation_tif_file = 'hs_geo_raster_resource/tests/{}'.format( self.raster_htelevation_tif_file_name) target_temp_raster_htelevation_tif_file = os.path.join( self.temp_dir, self.raster_htelevation_tif_file_name) shutil.copy(self.raster_htelevation_tif_file, target_temp_raster_htelevation_tif_file) self.raster_htelevation_tif_file_obj = open( target_temp_raster_htelevation_tif_file, 'r') self.raster_bad_tif_file_name = 'raster_tif_invalid.tif' self.raster_bad_tif_file = 'hs_geo_raster_resource/tests/{}'.format( self.raster_bad_tif_file_name) target_temp_raster_bad_tif_file = os.path.join( self.temp_dir, self.raster_bad_tif_file_name) shutil.copy(self.raster_bad_tif_file, target_temp_raster_bad_tif_file) self.raster_bad_tif_file_obj = open(target_temp_raster_bad_tif_file, 'r') self.raster_zip_file_name = 'raster_zip_valid.zip' self.raster_zip_file = 'hs_geo_raster_resource/tests/{}'.format( self.raster_zip_file_name) target_temp_raster_zip_file = os.path.join(self.temp_dir, self.raster_zip_file_name) shutil.copy(self.raster_zip_file, target_temp_raster_zip_file) self.raster_zip_file_obj = open(target_temp_raster_zip_file, 'r') self.raster_bad_zip_file_name = 'raster_zip_invalid.zip' self.raster_bad_zip_file = 'hs_geo_raster_resource/tests/{}'.format( self.raster_bad_zip_file_name) target_temp_raster_bad_zip_file = os.path.join( self.temp_dir, self.raster_bad_zip_file_name) shutil.copy(self.raster_bad_zip_file, target_temp_raster_bad_zip_file) self.raster_bad_zip_file_obj = open(target_temp_raster_bad_zip_file, 'r') temp_text_file = os.path.join(self.temp_dir, 'raster_text.txt') text_file = open(temp_text_file, 'w') text_file.write("Raster records") self.text_file_obj = open(temp_text_file, 'r')
def test_endorse_resource(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=[]) user_rater_1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Rater_1_FirstName', last_name='Rater_1_LastName', superuser=False, groups=[]) user_rater_2 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Rater_2_FirstName', last_name='Rater_2_LastName', superuser=False, groups=[]) # create a resource new_resource = hydroshare.create_resource('GenericResource', user_creator, 'My Test Resource') # this is the api call we are testing rating = hydroshare.endorse_resource(new_resource.short_id, user_rater_1) self.assertEqual(rating.content_object, new_resource) self.assertEqual(rating.user, user_rater_1) self.assertEqual(rating.value, 1) # test that we have only one rating object for the given resource and given rater ratings = Rating.objects.filter(object_pk=new_resource.id, user=user_rater_1) self.assertEqual(len(ratings), 1) # test that a specific user can rate/endorse a resource only once rating = hydroshare.endorse_resource(new_resource.short_id, user_rater_1) self.assertEqual(rating.value, 1) ratings = Rating.objects.filter(object_pk=new_resource.id, user=user_rater_1) self.assertEqual(len(ratings), 1) self.assertEqual(ratings[0].value, 1) # test that a 2nd user can rate the same resource rating = hydroshare.endorse_resource(new_resource.short_id, user_rater_2) self.assertEqual(rating.content_object, new_resource) self.assertEqual(rating.user, user_rater_2) self.assertEqual(rating.value, 1) # test that we have two rating object for the given resource ratings = Rating.objects.filter(object_pk=new_resource.id) self.assertEqual(len(ratings), 2) # test removing endorsement # this is the api call we are testing hydroshare.endorse_resource(new_resource.short_id, user_rater_1, endorse=False) # test that we have no rating object for the given resource and given rater ratings = Rating.objects.filter(object_pk=new_resource.id, user=user_rater_1) self.assertEqual(len(ratings), 0)
def test_create_group_two_members_two_owners(self): user_member_1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Member_1_FirstName', last_name='Member_1_LastName', superuser=False, groups=[]) user_member_2 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Member_2_FirstName', last_name='Member_2_LastName', superuser=False, groups=[]) user_owner_1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Owner_1_FirstName', last_name='Owner_1_LastName', superuser=False, groups=[]) user_owner_2 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Owner_2_FirstName', last_name='Owner_2_LastName', superuser=False, groups=[]) # test we have only no group ownerships at this point self.assertEqual(GroupOwnership.objects.all().count(), 0) # test creating a group with 2 members and 2 owners group_name = 'Test Group with 2 members and 2 owners' test_group = hydroshare.create_group( group_name, members=[user_member_1, user_member_2], owners=[user_owner_1, user_owner_2]) # test the group has the matching name self.assertEqual(test_group.name, group_name) # test at this point the group has only 2 members group_members = User.objects.filter(groups=test_group) self.assertEqual(len(group_members), 2) # test that they are the same 2 members we used in creating the group self.assertIn(user_member_1, group_members, msg='%s is not one of the group member.' % user_member_1) self.assertIn(user_member_2, group_members, msg='%s is not one of the group member.' % user_member_2) # test we have only 2 group ownerships at this point self.assertEqual(GroupOwnership.objects.all().count(), 2) # test we have only 2 group ownerships for the group we created group_ownerships = GroupOwnership.objects.filter(group=test_group) self.assertEqual(len(group_ownerships), 2) # test each of the 2 group ownership has the same group self.assertEqual(group_ownerships[0].group, test_group) self.assertEqual(group_ownerships[1].group, test_group) # test we have the 2 owners in the 2 group ownerships self.assertIn( user_owner_1, [grp_ownership.owner for grp_ownership in group_ownerships], msg='%s is not one of the group owner.' % user_owner_1) self.assertIn( user_owner_2, [grp_ownership.owner for grp_ownership in group_ownerships], msg='%s is not one of the group owner.' % user_owner_2)
def test_get_revisions(self): url = 'hsapi/revisions/{0}/'.format(self.res.short_id) resp = self.api_client.get(url) res_revisions = self.deserialize(resp) self.assertValidJSONResponse(resp) self.assertEqual(len(res_revisions), 1) self.assertEqual(hydroshare.get_revisions(self.res.short_id), res_revisions) resource_changed_by = hydroshare.create_account( '*****@*****.**', username='******', first_name='User1_FirstName', last_name='User1_LastName') hydroshare.utils.resource_modified(self.res, resource_changed_by) resp = self.api_client.get(url) res_revisions = self.deserialize(resp) self.assertValidJSONResponse(resp) self.assertEqual(len(res_revisions), 2) self.assertEqual(hydroshare.get_revisions(self.res.short_id), res_revisions) # test that each revision has a different time stamp self.assertNotEqual(res_revisions[0].timestamp, res_revisions[1].timestamp) # test that each resource revision has the same resource id for bags in res_revisions: self.assertEqual(self.res.id, bags.object_id) # add a file to the resource to generate another revision of the resource # create a file original_file_name = 'original.txt' original_file = open(original_file_name, 'w') original_file.write("original text") original_file.close() original_file = open(original_file_name, 'r') # add the file to the resource hydroshare.add_resource_files(self.res.short_id, original_file) resp = self.api_client.get(url) res_revisions = self.deserialize(resp) self.assertValidJSONResponse(resp) # test that we now have 3 revisions self.assertEqual(len(res_revisions), 3) self.assertEqual(hydroshare.get_revisions(self.res.short_id), res_revisions) # test that each revision has a different time stamp self.assertNotEqual(res_revisions[0].timestamp, res_revisions[1].timestamp) self.assertNotEqual(res_revisions[0].timestamp, res_revisions[2].timestamp) self.assertNotEqual(res_revisions[1].timestamp, res_revisions[2].timestamp) # delete the file in the resource to create another revision of the resource hydroshare.delete_resource_file(self.res.short_id, original_file_name) resp = self.api_client.get(url) res_revisions = self.deserialize(resp) self.assertValidJSONResponse(resp) self.assertEqual(hydroshare.get_revisions(self.res.short_id), res_revisions) # test that we now have 4 revisions self.assertEqual(len(res_revisions), 4)
def setUp(self): super(TestCollection, self).setUp() self.api_client = Client() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.user1 = create_account('*****@*****.**', username='******', password='******', first_name='myfirstname1', last_name='mylastname1', superuser=False, groups=[self.group]) self.resCollection = create_resource( resource_type='CollectionResource', owner=self.user1, title='My Collection', keywords=['kw1', 'kw2'], metadata=[{ "rights": { "statement": "mystatement", "url": "http://www.google.com" } }, { "description": { "abstract": "myabstract" } }]) self.res_1_user_1 = create_resource(resource_type='CompositeResource', owner=self.user1, title='Gen 1') self.res_2_user_1 = create_resource(resource_type='CompositeResource', owner=self.user1, title='Gen 2') self.user2 = create_account('*****@*****.**', username='******', password='******', first_name='myfirstname2', last_name='mylastname2', superuser=False, groups=[self.group]) test_file1 = open('test1.txt', 'w') test_file1.write("Test text file in test1.txt") test_file1.close() test_file1 = open('test1.txt', 'rb') files = [UploadedFile(file=test_file1, name='test1.txt')] metadata_dict = [{'description': {'abstract': 'My test abstract'}}] self.res_1_user_2 = create_resource(resource_type='CompositeResource', owner=self.user2, title='Gen 4', keywords=['kw1', 'kw2'], files=files, metadata=metadata_dict) self.res_2_user_2 = create_resource(resource_type='CompositeResource', owner=self.user2, title='Gen 3')
def setUp(self): super(TestCommunities, self).setUp() global_reset() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.admin = hydroshare.create_account('*****@*****.**', username='******', first_name='administrator', last_name='couch', superuser=True, groups=[]) self.cat = hydroshare.create_account('*****@*****.**', username='******', first_name='not a dog', last_name='last_name_cat', superuser=False, groups=[]) self.cat2 = hydroshare.create_account('*****@*****.**', username='******', first_name='not a dog', last_name='last_name_cat2', superuser=False, groups=[]) self.dog = hydroshare.create_account('*****@*****.**', username='******', first_name='a little arfer', last_name='last_name_dog', superuser=False, groups=[]) self.dog2 = hydroshare.create_account('*****@*****.**', username='******', first_name='a little arfer', last_name='last_name_dog2', superuser=False, groups=[]) self.bat = hydroshare.create_account('*****@*****.**', username='******', first_name='a little batty', last_name='last_name_bat', superuser=False, groups=[]) self.bat2 = hydroshare.create_account('*****@*****.**', username='******', first_name='the ultimate bat', last_name='last_name_bat2', superuser=False, groups=[]) # user 'dog' create a new group called 'dogs' self.dogs = self.dog.uaccess.create_group( title='dogs', description="This is the dogs group", purpose="Our purpose to collaborate on barking.") self.dog.uaccess.share_group_with_user(self.dogs, self.dog2, PrivilegeCodes.VIEW) # user 'cat' creates a new group called 'cats' self.cats = self.cat.uaccess.create_group( title='cats', description="This is the cats group", purpose="Our purpose to collaborate on begging.") self.cat.uaccess.share_group_with_user(self.cats, self.cat2, PrivilegeCodes.VIEW) # user 'bat' creates a new group called 'bats' self.bats = self.bat.uaccess.create_group( title='bats', description="This is the bats group", purpose="Our purpose is to collaborate on guano.") self.bat.uaccess.share_group_with_user(self.bats, self.bat2, PrivilegeCodes.VIEW) # create a cross-over share that allows dog to share with cats. self.cat.uaccess.share_group_with_user(self.cats, self.dog, PrivilegeCodes.OWNER) # create a cross-over share that allows dog to share with bats. self.bat.uaccess.share_group_with_user(self.bats, self.dog, PrivilegeCodes.OWNER) self.holes = hydroshare.create_resource( resource_type='GenericResource', owner=self.dog, title='all about dog holes', metadata=[], ) self.dog.uaccess.share_resource_with_group(self.holes, self.dogs, PrivilegeCodes.VIEW) self.squirrels = hydroshare.create_resource( resource_type='GenericResource', owner=self.dog, title='a list of squirrels to pester', metadata=[], ) self.dog.uaccess.share_resource_with_group(self.squirrels, self.dogs, PrivilegeCodes.CHANGE) self.posts = hydroshare.create_resource( resource_type='GenericResource', owner=self.cat, title='all about scratching posts', metadata=[], ) self.cat.uaccess.share_resource_with_group(self.posts, self.cats, PrivilegeCodes.VIEW) self.claus = hydroshare.create_resource( resource_type='GenericResource', owner=self.cat, title='bad jokes about claws', metadata=[], ) self.cat.uaccess.share_resource_with_group(self.claus, self.cats, PrivilegeCodes.CHANGE) self.wings = hydroshare.create_resource( resource_type='GenericResource', owner=self.bat, title='things with wings', metadata=[], ) self.bat.uaccess.share_resource_with_group(self.wings, self.bats, PrivilegeCodes.VIEW) self.perches = hydroshare.create_resource( resource_type='GenericResource', owner=self.bat, title='where to perch', metadata=[], ) self.bat.uaccess.share_resource_with_group(self.perches, self.bats, PrivilegeCodes.CHANGE) # two communities to use self.pets = self.dog.uaccess.create_community( 'all kinds of pets', 'collaboration on how to be a better pet.') self.pests = self.bat.uaccess.create_community( 'all kinds of pests', 'collaboration on how to be a more effective pest.')
def setUp(self): super(GroupMembershipRequest, self).setUp() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.admin = hydroshare.create_account('*****@*****.**', username='******', first_name='administrator', last_name='dash', superuser=True, groups=[]) self.john_group_owner = hydroshare.create_account('*****@*****.**', username='******', first_name='John', last_name='Harvey', superuser=False, groups=[]) self.mike_group_owner = hydroshare.create_account('*****@*****.**', username='******', first_name='Mike', last_name='Holley', superuser=False, groups=[]) self.jen_group_editor = hydroshare.create_account('*****@*****.**', username='******', first_name='Jen', last_name='Larson', superuser=False, groups=[]) self.kim_group_viewer = hydroshare.create_account('*****@*****.**', username='******', first_name='Kim', last_name='Jordan', superuser=False, groups=[]) self.lisa_group_member = hydroshare.create_account('*****@*****.**', username='******', first_name='Lisa', last_name='Larson', superuser=False, groups=[]) self.kelly_group_member = hydroshare.create_account('*****@*****.**', username='******', first_name='Kelly', last_name='Miller', superuser=False, groups=[]) self.modeling_group = self.john_group_owner.uaccess.create_group( title='USU Modeling Group', description="We are the cool modeling group", purpose="Our purpose to collaborate on hydrologic modeling") self.metadata_group = self.mike_group_owner.uaccess.create_group( title='USU Metadata Group', description="We are the cool metadata group", purpose="Our purpose to collaborate on metadata") self.john_group_owner.uaccess.share_group_with_user( self.modeling_group, self.mike_group_owner, PrivilegeCodes.OWNER) self.john_group_owner.uaccess.share_group_with_user( self.modeling_group, self.jen_group_editor, PrivilegeCodes.CHANGE) self.john_group_owner.uaccess.share_group_with_user( self.modeling_group, self.kim_group_viewer, PrivilegeCodes.VIEW)
def setUp(self): super(T13Delete, self).setUp() global_reset() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.admin = hydroshare.create_account( '*****@*****.**', username='******', first_name='administrator', last_name='couch', superuser=True, groups=[] ) self.cat = hydroshare.create_account( '*****@*****.**', username='******', first_name='not a dog', last_name='last_name_cat', superuser=False, groups=[] ) self.dog = hydroshare.create_account( '*****@*****.**', username='******', first_name='a little arfer', last_name='last_name_dog', superuser=False, groups=[] ) self.bat = hydroshare.create_account( '*****@*****.**', username='******', first_name='not a man', last_name='last_name_bat', superuser=False, groups=[] ) self.nobody = hydroshare.create_account( '*****@*****.**', username='******', first_name='no one in particular', last_name='last_name_nobody', superuser=False, groups=[] ) self.wombat = hydroshare.create_account( '*****@*****.**', username='******', first_name='some random ombat', last_name='last_name_wombat', superuser=False, groups=[] ) self.verdi = hydroshare.create_resource( resource_type='GenericResource', owner=self.dog, title='Guiseppe Verdi', metadata=[], ) self.operas = self.dog.uaccess.create_group( title="operas", description="We are the operas") self.dog.uaccess.share_resource_with_user( self.verdi, self.cat, PrivilegeCodes.CHANGE) self.dog.uaccess.share_resource_with_group( self.verdi, self.operas, PrivilegeCodes.CHANGE) self.singers = self.dog.uaccess.create_group( title='singers', description="We are the singers") self.dog.uaccess.share_group_with_user( self.singers, self.cat, PrivilegeCodes.CHANGE)
def setUp(self): super(TestCollection, self).setUp() self.api_client = Client() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.user1 = create_account( '*****@*****.**', username='******', password='******', first_name='myfirstname1', last_name='mylastname1', superuser=False, groups=[self.group] ) self.resCollection = create_resource( resource_type='CollectionResource', owner=self.user1, title='My Collection', keywords=['kw1', 'kw2'], metadata=[{"rights": {"statement": "mystatement", "url": "http://www.google.com"}}, {"description": {"abstract": "myabstract"}} ] ) self.resCollection_with_missing_metadata = create_resource( resource_type='CollectionResource', owner=self.user1, title='My Collection with missing required metadata' ) self.resGen1 = create_resource( resource_type='GenericResource', owner=self.user1, title='Gen 1' ) self.resGen2 = create_resource( resource_type='GenericResource', owner=self.user1, title='Gen 2' ) self.resGen3 = create_resource( resource_type='GenericResource', owner=self.user1, title='Gen 3' ) self.resGen4 = create_resource( resource_type='GenericResource', owner=self.user1, title='Gen 4' ) self.resTimeSeries = create_resource( resource_type='TimeSeriesResource', owner=self.user1, title='Test Time Series Resource' ) self.resNetCDF = create_resource( resource_type='NetcdfResource', owner=self.user1, title='Test NetCDF Resource' ) self.resGeoFeature = create_resource( resource_type='GeographicFeatureResource', owner=self.user1, title='Test Geographic Feature (shapefiles)' ) self.resModelInstance = create_resource( resource_type='ModelInstanceResource', owner=self.user1, title='Test Model Instance Resource') self.user2 = create_account( '*****@*****.**', username='******', password='******', first_name='myfirstname2', last_name='mylastname2', superuser=False, groups=[self.group] ) self.resGen5 = create_resource( resource_type='GenericResource', owner=self.user2, title='Gen 4' ) base_url = "/hsapi/_internal/{0}" self.url_to_update_collection = base_url + "/update-collection/" self.url_to_collection_member_permission = base_url + "/collection-member-permission/{1}/" self.url_to_set_resource_flag = base_url + "/set-resource-flag/" self.url_to_delete_resource = base_url + "/delete-resource/" self.url_to_update_collection_for_deleted_resources = \ base_url + "/update-collection-for-deleted-resources/" self.url_to_calculate_collection_coverages = \ "/hsapi/_internal/calculate-collection-coverages/{0}/"
def setUp(self): super(T09GroupSharing, self).setUp() global_reset() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.admin = hydroshare.create_account( '*****@*****.**', username='******', first_name='administrator', last_name='couch', superuser=True, groups=[] ) self.cat = hydroshare.create_account( '*****@*****.**', username='******', first_name='not a dog', last_name='last_name_cat', superuser=False, groups=[] ) self.dog = hydroshare.create_account( '*****@*****.**', username='******', first_name='a little arfer', last_name='last_name_dog', superuser=False, groups=[] ) self.bat = hydroshare.create_account( '*****@*****.**', username='******', first_name='not a man', last_name='last_name_bat', superuser=False, groups=[] ) self.nobody = hydroshare.create_account( '*****@*****.**', username='******', first_name='no one in particular', last_name='last_name_nobody', superuser=False, groups=[] ) self.scratching = hydroshare.create_resource( resource_type='GenericResource', owner=self.dog, title='all about sofas as scrathing posts', metadata=[], ) # dog owns felines group self.felines = self.dog.uaccess.create_group( title='felines', description="We are the felines") self.dog.uaccess.share_group_with_user( self.felines, self.cat, PrivilegeCodes.VIEW) # poetic justice
def test_update_resource_file(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 resource without any owner resource = GenericResource.objects.create( user=user_creator, title='My resource', creator=user_creator, last_changed_by=user_creator, doi='doi1000100010001' ) # resource should not have any files at this point self.assertEqual(resource.files.all().count(), 0, msg="resource file count didn't match") # create a file original_file_name = 'original.txt' original_file = open(original_file_name, 'w') original_file.write("original text") original_file.close() original_file = open(original_file_name, 'r') # add the file to the resource added_files = hydroshare.add_resource_files(resource.short_id, original_file) # resource should have only one file at this point self.assertEqual(len(added_files), 1) self.assertEqual(resource.files.all().count(), 1, msg="resource file count didn't match") self.assertIn( original_file_name, [os.path.basename(f.resource_file.name) for f in resource.files.all()], msg= '%s is not one of the resource files.' % original_file_name ) # create a file that will be used to update the original file -1st update new_file_name = 'update.txt' # file has a different name from the file that we will be updating new_file = open(new_file_name, 'w') new_file_data = 'data in new file' new_file.write(new_file_data) new_file.close() new_file = open(new_file_name, 'r') # this is the api call we are testing rf = hydroshare.update_resource_file(resource.short_id, original_file_name, new_file) # test if the file name matches self.assertEqual(os.path.basename(rf.resource_file.name), new_file_name, msg="resource file name didn't match") # since we are updating a file the number of files in the resource needs to be still 1 self.assertEqual(resource.files.all().count(), 1, msg="resource file count didn't match") # test if the content of the file matches resource_file = hydroshare.get_resource_file(resource.short_id, new_file_name) self.assertEqual(resource_file.read(), new_file_data, msg="resource file content didn't match") # reset the original resource file name for 2nd time resource file update original_file_name = new_file_name # create a file that will be used to update the resource file - 2nd update new_file_name = 'update.txt' # file has the same name as the file that we will be updating new_file = open(new_file_name, 'w') new_file_data = 'data in new file' new_file.write(new_file_data) new_file.close() new_file = open(new_file_name, 'r') # this is the api call we are testing rf = hydroshare.update_resource_file(resource.short_id, original_file_name, new_file) # test if the file name matches self.assertEqual(os.path.basename(rf.resource_file.name), new_file_name, msg="{0} != {1}".format(os.path.basename(rf.resource_file.name), new_file_name)) # exception ObjectDoesNotExist should be raised if resource does not have a file # for the given file name (file_not_in_resource.txt) to update self.assertRaises( ObjectDoesNotExist, lambda: hydroshare.update_resource_file(resource.short_id, 'file_not_in_resource.txt', new_file) )
def test_endorse_comment(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=[]) user_commenter_1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Commenter_1_FirstName', last_name='Commenter_1_LastName', superuser=False, groups=[]) user_rater_1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Rater_1_FirstName', last_name='Rater_1_LastName', superuser=False, groups=[]) user_rater_2 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Rater_2_FirstName', last_name='Rater_2_LastName', superuser=False, groups=[]) # create a resource new_resource = hydroshare.create_resource('GenericResource', user_creator, 'My Test Resource') resource_2 = hydroshare.create_resource('GenericResource', user_creator, 'My 2nd Test Resource') # first comment on resource comment_text = "comment by commenter_1" comment = hydroshare.comment_on_resource(new_resource.short_id, comment_text, user=user_commenter_1) # at this point there should not be any ratings for this new comment ratings = Rating.objects.filter(object_pk=comment.id) self.assertEqual(len(ratings), 0) # rate the comment - this is the api call we are testing rating = hydroshare.endorse_comment(comment.id, new_resource.short_id, user_rater_1) self.assertEqual(rating.content_object, comment) self.assertEqual(rating.user, user_rater_1) # test that the rating value is 1 (+1) self.assertEqual(rating.value, 1) # at this point there should be one ratings for this comment ratings = Rating.objects.filter(object_pk=comment.id) # test that the rating value is 1 (+1) self.assertEqual(len(ratings), 1) # test the user can't rate the same comment twice - no new rating object is created rating = hydroshare.endorse_comment(comment.id, new_resource.short_id, user_rater_1) self.assertEqual(rating.content_object, comment) self.assertEqual(rating.user, user_rater_1) # test that the rating value is 1 (+1) self.assertEqual(rating.value, 1) # at this point there should be one ratings for this comment ratings = Rating.objects.filter(object_pk=comment.id) self.assertEqual(len(ratings), 1) # test that the rating value is 1 (+1) self.assertEqual(ratings[0].value, 1) # rate the same comment by another user- this is the api call we are testing rating = hydroshare.endorse_comment(comment.id, new_resource.short_id, user_rater_2) self.assertEqual(rating.content_object, comment) self.assertEqual(rating.user, user_rater_2) # test that the rating value is 1 (+1) self.assertEqual(rating.value, 1) # at this point there should be two ratings for this comment ratings = Rating.objects.filter(object_pk=comment.id) self.assertEqual(len(ratings), 2) # test that the rating value is 1 (+1) for each of these ratings self.assertEqual(ratings[0].value, 1) self.assertEqual(ratings[1].value, 1) # test removing a rating from a comment hydroshare.endorse_comment(comment.id, new_resource.short_id, user_rater_2, endorse=False) # at this point there should be one ratings for this comment ratings = Rating.objects.filter(object_pk=comment.id) self.assertEqual(len(ratings), 1) # test that the rating value is 1 (+1) self.assertEqual(ratings[0].value, 1) # there should not be any ratings by user_rater_2 for this comment ratings = Rating.objects.filter(object_pk=comment.id, user=user_rater_2) self.assertEqual(len(ratings), 0) # test that ValueError exception raised if the comment does not exist for the specified resource self.assertRaises( ValueError, lambda: hydroshare.endorse_comment( comment.id, resource_2.short_id, user_rater_2))
def test_get_revisions(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=[] ) resource_changed_by = hydroshare.create_account( '*****@*****.**', username='******', first_name='Pabitra', last_name='Dash', superuser=False, groups=[] ) # create a resource resource = hydroshare.create_resource('GenericResource', user_creator, 'My resource') # test that we have only one revision at this point - this is the api call we are testing res_revisions = hydroshare.get_revisions(resource.short_id) self.assertEqual(len(res_revisions), 1) # set the resource last changed by a different user - to a create another revision of the resource hydroshare.utils.resource_modified(resource, resource_changed_by) res_revisions = hydroshare.get_revisions(resource.short_id) # test that we now have 2 revisions self.assertEqual(len(res_revisions), 2) # test that each revision has a different time stamp self.assertNotEqual(res_revisions[0].timestamp, res_revisions[1].timestamp) # test that each resource revision has the same resource id for bags in res_revisions: self.assertEqual(resource.id, bags.object_id) # add a file to the resource to generate another revision of the resource # create a file original_file_name = 'original.txt' original_file = open(original_file_name, 'w') original_file.write("original text") original_file.close() original_file = open(original_file_name, 'r') # add the file to the resource hydroshare.add_resource_files(resource.short_id, original_file) res_revisions = hydroshare.get_revisions(resource.short_id) # test that we now have 3 revisions self.assertEqual(len(res_revisions), 3) # test that each revision has a different time stamp self.assertNotEqual(res_revisions[0].timestamp, res_revisions[1].timestamp) self.assertNotEqual(res_revisions[0].timestamp, res_revisions[2].timestamp) self.assertNotEqual(res_revisions[1].timestamp, res_revisions[2].timestamp) # delete the file in the resource to create another revision of the resource hydroshare.delete_resource_file(resource.short_id, original_file_name) res_revisions = hydroshare.get_revisions(resource.short_id) # test that we now have 4 revisions self.assertEqual(len(res_revisions), 4)
def setUp(self): super(T01PublicGroups, self).setUp() global_reset() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.admin = hydroshare.create_account('*****@*****.**', username='******', first_name='administrator', last_name='couch', superuser=True, groups=[]) self.cat = hydroshare.create_account('*****@*****.**', username='******', first_name='not a dog', last_name='last_name_cat', superuser=False, groups=[]) self.cats = self.cat.uaccess.create_group( title='cats', description="We are the cats") self.posts = hydroshare.create_resource( resource_type='GenericResource', owner=self.cat, title='all about scratching posts', metadata=[], ) self.cat.uaccess.share_resource_with_group(self.posts, self.cats, PrivilegeCodes.VIEW) self.dog = hydroshare.create_account('*****@*****.**', username='******', first_name='not a cat', last_name='last_name_dog', superuser=False, groups=[]) self.dogs = self.dog.uaccess.create_group( title='dogs', description="We are the dogs") self.bones = hydroshare.create_resource( resource_type='GenericResource', owner=self.dog, title='all about bones', metadata=[], ) self.dog.uaccess.share_resource_with_group(self.bones, self.dogs, PrivilegeCodes.VIEW) self.pets = self.dog.uaccess.create_community( 'all kinds of pets', 'collaboration on how to be a better pet.') # Make cats and dogs part of community pets self.dog.uaccess.share_community_with_group(self.pets, self.dogs, PrivilegeCodes.VIEW) self.cat.uaccess.share_group_with_user(self.cats, self.dog, PrivilegeCodes.OWNER) self.dog.uaccess.share_community_with_group(self.pets, self.cats, PrivilegeCodes.VIEW) self.cat.uaccess.unshare_group_with_user(self.cats, self.dog)
def setUp(self): super(TestCopyResource, self).setUp() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') # create a user who is the owner of the resource to be copied self.owner = hydroshare.create_account( '*****@*****.**', username='******', first_name='owner_firstname', last_name='owner_lastname', superuser=False, groups=[] ) # create a user who is NOT the owner of the resource to be copied self.nonowner = hydroshare.create_account( '*****@*****.**', username='******', first_name='nonowner_firstname', last_name='nonowner_lastname', superuser=False, groups=[] ) # create a generic resource self.res_generic = hydroshare.create_resource( resource_type='GenericResource', owner=self.owner, title='Test Generic Resource' ) test_file1 = open('test1.txt', 'w') test_file1.write("Test text file in test1.txt") test_file1.close() test_file2 = open('test2.txt', 'w') test_file2.write("Test text file in test2.txt") test_file2.close() self.test_file1 = open('test1.txt', 'r') self.test_file2 = open('test2.txt', 'r') hydroshare.add_resource_files(self.res_generic.short_id, self.test_file1, self.test_file2) # create a generic empty resource with one license that prohibits derivation statement = 'This resource is shared under the Creative Commons Attribution-NoDerivs CC ' \ 'BY-ND.' url = 'http://creativecommons.org/licenses/by-nd/4.0/' metadata = [] metadata.append({'rights': {'statement': statement, 'url': url}}) self.res_generic_lic_nd = hydroshare.create_resource( resource_type='GenericResource', owner=self.owner, title='Test Generic Resource', metadata=metadata ) # create a generic empty resource with another license that prohibits derivation statement = 'This resource is shared under the Creative Commons ' \ 'Attribution-NoCommercial-NoDerivs CC BY-NC-ND.' url = 'http://creativecommons.org/licenses/by-nc-nd/4.0/' metadata = [] metadata.append({'rights': {'statement': statement, 'url': url}}) self.res_generic_lic_nc_nd = hydroshare.create_resource( resource_type='GenericResource', owner=self.owner, title='Test Generic Resource', metadata=metadata ) # create a raster resource that represents a specific resource type raster_file = 'hs_core/tests/data/cea.tif' temp_dir = tempfile.mkdtemp() self.temp_raster_file = os.path.join(temp_dir, 'cea.tif') shutil.copy(raster_file, self.temp_raster_file) self.raster_obj = open(self.temp_raster_file, 'r') files = [UploadedFile(file=self.raster_obj, name='cea.tif')] self.res_raster = hydroshare.create_resource( resource_type='RasterResource', owner=self.owner, title='Test Raster Resource', files=files, metadata=[] ) # call the post creation process here for the metadata to be # extracted utils.resource_post_create_actions(resource=self.res_raster, user=self.owner, metadata=[])