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_with_groups(self): g0 = hydroshare.create_group(name="group0") g1 = hydroshare.create_group(name="group1") g2 = hydroshare.create_group(name="group2") groups = [g0, g1, g2] username, first_name, last_name, password = '******', 'shaun', 'joseph', 'mypass' user = hydroshare.create_account('*****@*****.**', username=username, first_name=first_name, last_name=last_name, groups=groups) new_groups = list(Group.objects.filter(user=user.id)) self.assertEqual(groups, new_groups)
def setUp(self): self.user = hydroshare.create_account( '*****@*****.**', username='******', first_name='User0_FirstName', last_name='User0_LastName', ) g0 = hydroshare.create_group(name="group0") g1 = hydroshare.create_group(name="group1") g2 = hydroshare.create_group(name="group2") self.user.groups.add(g0,g1,g2) self.g_ids = sorted([g0.id,g1.id,g2.id]) self.query = {'user': self.user.id}
def setUp(self): self.user = hydroshare.create_account( '*****@*****.**', username='******', first_name='User0_FirstName', last_name='User0_LastName', ) g0 = hydroshare.create_group(name="group0") g1 = hydroshare.create_group(name="group1") g2 = hydroshare.create_group(name="group2") self.user.groups.add(g0, g1, g2) self.g_ids = sorted([g0.id, g1.id, g2.id]) self.query = {'user': self.user.id}
def setUp(self): self.api_client = TestApiClient() self.username = '******' self.password = '******' # create a user self.user = hydroshare.create_account( '*****@*****.**', username=self.username, first_name='Tian', last_name='Gan', superuser=False, password=self.password, groups=[] ) # create a resource self.res = hydroshare.create_resource( 'GenericResource', self.user, 'My resource' ) # create a group self.group = hydroshare.create_group( 'Test group', members=[], owners=[self.user1] )
def test_update_group_to_add_owner_duplicate(self): user_owner_1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Owner_1_FirstName', last_name='Owner_1_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]) # update with duplicate data hydroshare.update_group(test_group, owners=[user_owner_1]) # test we have one group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 1) # test the group ownership has the correct group group_ownership = GroupOwnership.objects.filter(group=test_group) self.assertEqual(group_ownership[0].group, test_group) # test the group ownership has the correct owner self.assertEqual(group_ownership[0].owner, user_owner_1)
def test_delete_group_the_same_owner_twice(self): user_owner_1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Owner_1_FirstName', last_name='Owner_1_LastName', superuser=False, groups=[]) group_name = 'Test Group' test_group = hydroshare.create_group(group_name) # test we don't have any group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 0) hydroshare.set_group_owner(test_group, user_owner_1) # test we have only one group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 1) # this is the api call we are testing hydroshare.delete_group_owner(test_group, user_owner_1) # deleting the same owner again hydroshare.delete_group_owner(test_group, user_owner_1) # test we don't have any group ownership after we delete the group owner self.assertEqual(GroupOwnership.objects.all().count(), 0)
def test_set_group_owner_duplicate(self): user_owner_1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Owner_1_FirstName', last_name='Owner_1_LastName', superuser=False, groups=[] ) group_name = 'Test Group' test_group = hydroshare.create_group(group_name) # test we don't have any group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 0) # this is the api call we are testing hydroshare.set_group_owner(test_group, user_owner_1) # set the same user again as the group owner hydroshare.set_group_owner(test_group, user_owner_1) # test we have only one group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 1) # test the group ownership has the correct group group_ownership = GroupOwnership.objects.filter(group=test_group) self.assertEqual(group_ownership[0].group, test_group) # test the group ownership has the correct owner self.assertEqual(group_ownership[0].owner, user_owner_1)
def test_create_group_no_member_one_owner(self): user_owner_1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Owner_1_FirstName', last_name='Owner_1_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 one owner group_name = 'Test Group with one owner' test_group = hydroshare.create_group(group_name, owners=[user_owner_1]) # test the group has the matching name self.assertEqual(test_group.name, group_name) # test we have only one group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 1) # test the group ownership has the correct group group_ownership = GroupOwnership.objects.filter(group=test_group) self.assertEqual(group_ownership[0].group, test_group) # test the group ownership has the correct owner self.assertEqual(group_ownership[0].owner, user_owner_1)
def test_create_group_no_member_one_owner(self): user_owner_1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Owner_1_FirstName', last_name='Owner_1_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 one owner group_name = 'Test Group with one owner' test_group = hydroshare.create_group(group_name, owners=[user_owner_1]) # test the group has the matching name self.assertEqual(test_group.name, group_name) # test we have only one group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 1) # test the group ownership has the correct group group_ownership = GroupOwnership.objects.filter(group=test_group) self.assertEqual(group_ownership[0].group, test_group) # test the group ownership has the correct owner self.assertEqual(group_ownership[0].owner, user_owner_1)
def test_update_group_to_add_owner_duplicate(self): user_owner_1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Owner_1_FirstName', last_name='Owner_1_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]) # update with duplicate data hydroshare.update_group(test_group, owners=[user_owner_1]) # test we have one group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 1) # test the group ownership has the correct group group_ownership = GroupOwnership.objects.filter(group=test_group) self.assertEqual(group_ownership[0].group, test_group) # test the group ownership has the correct owner self.assertEqual(group_ownership[0].owner, user_owner_1)
def test_delete_group_the_same_owner_twice(self): user_owner_1 = hydroshare.create_account( "*****@*****.**", username="******", first_name="Owner_1_FirstName", last_name="Owner_1_LastName", superuser=False, groups=[], ) group_name = "Test Group" test_group = hydroshare.create_group(group_name) # test we don't have any group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 0) hydroshare.set_group_owner(test_group, user_owner_1) # test we have only one group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 1) # this is the api call we are testing hydroshare.delete_group_owner(test_group, user_owner_1) # deleting the same owner again hydroshare.delete_group_owner(test_group, user_owner_1) # test we don't have any group ownership after we delete the group owner self.assertEqual(GroupOwnership.objects.all().count(), 0)
def test_update_group_to_add_member_duplicate(self): user_member_1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Member_1_FirstName', last_name='Member_1_LastName', superuser=False, groups=[] ) group_name = 'Test Group' test_group = hydroshare.create_group(group_name) # this is the api call we are testing hydroshare.update_group(test_group, members=[user_member_1]) # update with duplicate data hydroshare.update_group(test_group, members=[user_member_1]) # test at this point the group should have one member group_members = User.objects.filter(groups=test_group) self.assertEqual(len(group_members), 1) # test that it is the same member we used in updating the group self.assertEqual(group_members[0], user_member_1 )
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): # 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 test_with_groups(self): g0 = hydroshare.create_group(name="group0") g1 = hydroshare.create_group(name="group1") g2 = hydroshare.create_group(name="group2") groups = [g0, g1, g2] username,first_name,last_name,password = '******', 'shaun', 'joseph', 'mypass' user = hydroshare.create_account( '*****@*****.**', username=username, first_name=first_name, last_name=last_name, groups=groups ) new_groups = list(Group.objects.filter(user=user.id)) self.assertEqual(groups, new_groups)
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 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.owner for a in GroupOwnership.objects.filter(group=a_group)], msg='user1 not listed in the group ownership list' ) self.assertNotIn( user2, [a.owner for a in GroupOwnership.objects.filter(group=a_group)], msg='user2 listed in the group ownership list' ) user1.delete() user2.delete() a_group.delete()
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): self.api_client = TestApiClient() self.user = hydroshare.create_account( '*****@*****.**', username='******', first_name='User0_FirstName', last_name='User0_LastName', superuser=True, password='******' ) g0=hydroshare.create_group(name="group0") g1=hydroshare.create_group(name="group1") g2=hydroshare.create_group(name="group2") self.user.groups.add(g0,g1,g2) self.g_ids=[g0.id,g1.id,g2.id] self.groups_url_base = '/hsapi/groups/' self.api_client.client.login(username=self.user.username, password=self.user.password)
def test_create_group_no_member_no_owner(self): group_name = 'Test Group' test_group = hydroshare.create_group(group_name) # test the group has the matching name self.assertEqual(test_group.name, group_name) # test that there are no members in this group yet this point group_members = User.objects.filter(groups=test_group) self.assertEqual(len(group_members), 0) # test we don't have any group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 0)
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 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): # create a group self.group = hydroshare.create_group('Test group', members=[], owners=[]) # create a user self.user = hydroshare.create_account('*****@*****.**', username='******', first_name='user1_first', last_name='user1_last', superuser=False, groups=[self.group])
def setUp(self): self.user = hydroshare.create_account( '*****@*****.**', username='******', first_name='Tian', last_name='Gan', superuser=False, groups=[] ) self.group = hydroshare.create_group( 'Jamy group', members=[self.user], owners=[self.user] )
def test_set_group_rules(self): group = hydroshare.create_group(name="group0") url = '{0}{1}/'.format(self.account_url_base, group.id) put_data = self.serialize({ 'principaltype': 'group', 'principleID': group.id, 'access': 'view', 'allow': 'true' }) resp = self.api_client.put(url, data=put_data) self.assertEqual(resp.status_code, 200)
def create_group(self): creator = get_user(self.request) if not get_user(self.request).is_authenticated(): raise exceptions.PermissionDenied("user must be authenticated to create a group.") params = CreateOrListGroups.CreateGroupForm(self.request.REQUEST) if params.is_valid(): r = params.cleaned_data r['owners'] = set(r['owners']) if r['owners'] else set() r['owners'].add(creator) g = hydroshare.create_group(**r) return HttpResponse(g.name, content_type='text/plain') else: raise exceptions.ValidationError('invalid request')
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 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 test_create_group_two_members_no_owner(self): # create a user to be used for creating the resource 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=[] ) # test we don't have any group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 0) # test creating a group with 2 members group_name = 'Test Group with 2 members' test_group = hydroshare.create_group(group_name, members=[user_member_1, user_member_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 don't have any group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 0)
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 ) self.assertIn( fully_specified_user, [a for a in hydroshare.list_group_members(a_group)], msg='user not listed in the group membership list' ) user_without_username.delete() fully_specified_user.delete() a_group.delete()
def setUp(self): # create a group self.group = hydroshare.create_group( 'Test group', members=[], owners=[] ) # create a user self.user = hydroshare.create_account( '*****@*****.**', username='******', first_name='user1_first', last_name='user1_last', superuser=False, groups=[self.group] )
def test_create_group_two_members_no_owner(self): # create a user to be used for creating the resource 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=[]) # test we don't have any group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 0) # test creating a group with 2 members group_name = 'Test Group with 2 members' test_group = hydroshare.create_group( group_name, members=[user_member_1, user_member_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 don't have any group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 0)
def test_delete_group_one_of_the_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 don't have any group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 0) hydroshare.set_group_owner(test_group, user_owner_1) hydroshare.set_group_owner(test_group, user_owner_2) # test we have 2 group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 2) # this is the api call we are testing hydroshare.delete_group_owner(test_group, user_owner_1) # test we now have 1 group ownership after we delete one of the 2 group owners self.assertEqual(GroupOwnership.objects.all().count(), 1) # test we still have the 2nd group owner group_ownerships = GroupOwnership.objects.filter(group=test_group) 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 create_group(self): creator = get_user(self.request) if not get_user(self.request).is_authenticated(): raise exceptions.PermissionDenied( "user must be authenticated to create a group.") params = utils.create_form(CreateOrListGroups.CreateGroupForm, self.request) if params.is_valid(): r = params.cleaned_data r['owners'] = set(r['owners']) if r['owners'] else set() r['owners'].add(creator) g = hydroshare.create_group(**r) return HttpResponse(g.name, content_type='text/plain', status='201') else: raise exceptions.ValidationError('invalid request')
def test_create_group_one_member_no_owner(self): # create a user to be used for creating the resource 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=[] ) # test we don't have any group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 0) # test creating a group with one member group_name = 'Test Group with one member' test_group = hydroshare.create_group(group_name, members=[user_member_1]) # test the group has the matching name self.assertEqual(test_group.name, group_name) # test at this point the group has only one member group_members = User.objects.filter(groups=test_group) self.assertEqual(len(group_members), 1) # test that it is the same member we used in creating the group self.assertEqual(group_members[0], user_member_1 ) # test that user_member_2 is not part of the group self.assertNotEqual(group_members[0], user_member_2 ) # test we don't have any group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 0)
def test_differentiate(self): user1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='User1_FirstName', last_name='User1_LastName', ) g3 = hydroshare.create_group(name="group3") user1.groups.add(g3) q = self.query l = hydroshare.list_groups(query=q) self.assertEqual(len(l), 3) new_ids = [] for g in l: new_ids.append(g.id) self.assertEqual(self.g_ids, sorted(new_ids)) self.assertNotIn(g3.id, l)
def test_differentiate(self): user1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='User1_FirstName', last_name='User1_LastName', ) g3 = hydroshare.create_group(name="group3") user1.groups.add(g3) q = self.query l = hydroshare.list_groups(query=q) self.assertEqual(len(l),3) new_ids = [] for g in l: new_ids.append(g.id) self.assertEqual(self.g_ids,sorted(new_ids)) self.assertNotIn(g3.id,l)
def test_create_group_one_member_no_owner(self): # create a user to be used for creating the resource 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=[]) # test we don't have any group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 0) # test creating a group with one member group_name = 'Test Group with one member' test_group = hydroshare.create_group(group_name, members=[user_member_1]) # test the group has the matching name self.assertEqual(test_group.name, group_name) # test at this point the group has only one member group_members = User.objects.filter(groups=test_group) self.assertEqual(len(group_members), 1) # test that it is the same member we used in creating the group self.assertEqual(group_members[0], user_member_1) # test that user_member_2 is not part of the group self.assertNotEqual(group_members[0], user_member_2) # test we don't have any group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 0)
def test_update_group_to_add_member(self): user_member_1 = hydroshare.create_account( '*****@*****.**', username='******', first_name='Member_1_FirstName', last_name='Member_1_LastName', superuser=False, groups=[]) group_name = 'Test Group' test_group = hydroshare.create_group(group_name) # this is the api call we are testing hydroshare.update_group(test_group, members=[user_member_1]) # test at this point the group should have one member group_members = User.objects.filter(groups=test_group) self.assertEqual(len(group_members), 1) # test that it is the same member we used in updating the group self.assertEqual(group_members[0], user_member_1)
def test_delete_group_one_of_the_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 don't have any group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 0) hydroshare.set_group_owner(test_group, user_owner_1) hydroshare.set_group_owner(test_group, user_owner_2) # test we have 2 group ownership at this point self.assertEqual(GroupOwnership.objects.all().count(), 2) # this is the api call we are testing hydroshare.delete_group_owner(test_group, user_owner_1) # test we now have 1 group ownership after we delete one of the 2 group owners self.assertEqual(GroupOwnership.objects.all().count(), 1) # test we still have the 2nd group owner group_ownerships = GroupOwnership.objects.filter(group=test_group) 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_update_group_to_add_members(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=[] ) group_name = 'Test Group' test_group = hydroshare.create_group(group_name) # this is the api call we are testing hydroshare.update_group(test_group, members=[user_member_1, user_member_2]) # test at this point the group should have 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 updating 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 )
def test_update_group_to_add_members(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=[]) group_name = 'Test Group' test_group = hydroshare.create_group(group_name) # this is the api call we are testing hydroshare.update_group(test_group, members=[user_member_1, user_member_2]) # test at this point the group should have 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 updating 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)