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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    def set_group_owner(self, g, u):
        originator = get_user(self.request)
        g = group_from_id(g)

        if not GroupOwnership.objects.filter(group=g, user=originator).exists():
            raise exceptions.PermissionDenied("user must be a group owner to change group ownership.")
        else:
            hydroshare.set_group_owner(g, u)
            return HttpResponse(g.name, content_type='text/plain')
Ejemplo n.º 5
0
    def set_group_owner(self, g, u):
        originator = get_user(self.request)
        g = group_from_id(g)

        if not GroupOwnership.objects.filter(group=g,
                                             user=originator).exists():
            raise exceptions.PermissionDenied(
                "user must be a group owner to change group ownership.")
        else:
            hydroshare.set_group_owner(g, u)
            return HttpResponse(g.name,
                                content_type='text/plain',
                                status='204')
Ejemplo n.º 6
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,
        )
Ejemplo n.º 7
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)