class OpenGroupMemberCreationTests(APITestCase):
    @classmethod
    def setUpTestData(self):
        super(APITestCase, self).setUpTestData()

        # Routes
        self.members_url = "/group-member/"
        self.member_url = self.members_url + "%d/"

        # Public Group, open to anyone
        self.group = GroupFactory()
        self.group.is_private = False
        self.group.default_member_rank = 1
        self.group.save()

        # Users already in group
        self.users = [UserFactory()]
        # Associated GroupMember
        self.group_member1 = GroupMember(user=self.users[0], group=self.group, perm_rank=Group.ADMINISTRATOR_RANK)

        # Testing user
        self.user = UserFactory()

        # Misc
        self.new_membership_data = {"group_id": self.group.id, "user_id": self.user.id}

    def test_create_not_authed(self):
        self.client.force_authenticate(user=None)
        response = self.client.post(self.members_url, self.new_membership_data)
        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

    def test_create_not_for_self(self):
        # Attempt to add somebody else to a group
        self.client.force_authenticate(user=self.users[0])
        response = self.client.post(self.members_url, self.new_membership_data)
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

    def test_create_success(self):
        # Succesful attempt to join an open group
        self.client.force_authenticate(user=self.user)
        response = self.client.post(self.members_url, self.new_membership_data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(response.data["perm_rank"], self.group.default_member_rank)
Beispiel #2
0
    def setUpTestData(self):
        # Summary: 1 cluster, 4 users + 1 admin, 5 groups (+1 group for the cluster)
        # Users #1 and #2 are in cluster #1
        # User #5 is Sigma admin
        # Group #1 is public, others are private
        # Users #1 and #2 are members of group #3; user #1 is group admin
        # Users #3 and #4 are members of group #2; user #3 has invitation clearance, not user #4
        # User #4 is member of group #5
        # User #1 is invited to group #5
        # Group #4 is acknowledged by cluster #1

        super(GroupTests, self).setUpTestData()
        self.clusters = ClusterFactory.create_batch(1)
        self.groups = GroupFactory.create_batch(5, is_private=True)
        self.users = UserFactory.create_batch(3) + [AdminUserFactory()]

        # Group #1 is public
        self.groups[0].is_private = False
        self.groups[0].default_member_rank = 1
        self.groups[0].name = "Public group without invitation"
        self.groups[0].save()

        # Group #2 clearance parameters
        self.groups[1].req_rank_invite = 5
        self.groups[1].save()

        # Users in cluster
        self.users[0].clusters.add(self.clusters[0])
        self.users[1].clusters.add(self.clusters[0])
        GroupMemberFactory(user=self.users[0], group=self.clusters[0].group_ptr)
        GroupMemberFactory(user=self.users[1], group=self.clusters[0].group_ptr)
        # Users in group #2
        GroupMemberFactory(user=self.users[2], group=self.groups[1], perm_rank=self.groups[1].req_rank_invite)
        GroupMemberFactory(user=self.users[3], group=self.groups[1])
        # Users in group #3
        GroupMemberFactory(user=self.users[0], group=self.groups[2], perm_rank=Group.ADMINISTRATOR_RANK)
        GroupMemberFactory(user=self.users[1], group=self.groups[2])
        # Users in group #5
        GroupMemberFactory(user=self.users[3], group=self.groups[4])
        # User #1 is invited to group #5
        self.users[0].invited_to_groups.add(self.groups[4])

        # GroupAcknowledgment
        GroupAcknowledgmentFactory(subgroup=self.groups[3], parent_group=self.clusters[0].group_ptr, validated=True)

        self.groups_url = "/group/"
        self.group_url = self.groups_url + "%d/"

        self.new_private_group_data = {"name": "New private group", "is_private": True}
        self.new_public_group_data = {"name": "New public group", "is_private": False}
        self.invite_data = {"user_id": self.users[0].id}
Beispiel #3
0
    def setUpTestData(self):
        # Summary: 2 clusters, 2 groups, 10 users
        # Cluster #1: users #1 to #5
        # Cluster #2: users #5 to #9
        # Group #1: users #1, #2 and #6 (pending request)
        # Group #2: users #3, #7 and #8 (invitation not accepted yet)
        # User #1 is admin in cluster #1
        # User #6 is admin in cluster #2
        # User #10 is Sigma admin

        super(UserTests, self).setUpTestData()
        self.clusters = ClusterFactory.create_batch(2)
        self.users = UserFactory.create_batch(9)
        self.groups = GroupFactory.create_batch(2)

        # User #10 is Sigma admin
        self.users.append(AdminUserFactory())

        # Add users in clusters (user #1 is admin in cluster #1 and user #6 is admin in cluster #2)
        for i in range(5):
            self.clusters[0].cluster_users.add(self.users[i])
            GroupMemberFactory(
                group=self.clusters[0], user=self.users[i], perm_rank=(Group.ADMINISTRATOR_RANK if i == 0 else 1)
            )

            self.clusters[1].cluster_users.add(self.users[4 + i])
            GroupMemberFactory(
                group=self.clusters[1], user=self.users[4 + i], perm_rank=(Group.ADMINISTRATOR_RANK if i == 1 else 1)
            )

        # Add users in group #1
        GroupMemberFactory(group=self.groups[0], user=self.users[0], perm_rank=Group.ADMINISTRATOR_RANK)
        GroupMemberFactory(group=self.groups[0], user=self.users[1], perm_rank=1)
        GroupMemberFactory(group=self.groups[0], user=self.users[5], perm_rank=0)  # pending request

        # Add users in group #2
        GroupMemberFactory(group=self.groups[1], user=self.users[2], perm_rank=1)
        GroupMemberFactory(group=self.groups[1], user=self.users[6], perm_rank=1)
        self.users[7].invited_to_groups.add(self.groups[1])  # User #8 is invited to group #2

        self.user_url = "/user/"
        self.new_user_data = {
            "lastname": "Doe",
            "firstname": "John",
            "email": "*****@*****.**",
            "password": "******",
            "clusters_ids": {self.clusters[0].id},
        }
    def setUpTestData(self):
        # Summary: 1 Sigma admin + 10 users, 4 groups, 2 clusters
        super().setUpTestData()

        self.users = [AdminUserFactory()] + UserFactory.create_batch(10)
        self.clusters = ClusterFactory.create_batch(2)
        self.groups = [None] + GroupFactory.create_batch(4, is_private=True)

        # Group #2 is public
        self.groups[2].is_private = False
        self.groups[2].save()

        # Add users in clusters (user #1 is admin in cluster #1 and user #6 is admin in cluster #2)
        for i in range(5):
            self.clusters[0].cluster_users.add(self.users[1 + i])
            GroupMemberFactory(
                group=self.clusters[0], user=self.users[1 + i], perm_rank=(Group.ADMINISTRATOR_RANK if i == 0 else 1)
            )

            self.clusters[1].cluster_users.add(self.users[6 + i])
            GroupMemberFactory(
                group=self.clusters[1], user=self.users[6 + i], perm_rank=(Group.ADMINISTRATOR_RANK if i == 0 else 1)
            )

        # Add users to group
        self.mships = [
            GroupMemberFactory(user=self.users[2], group=self.groups[1], perm_rank=1),
            GroupMemberFactory(user=self.users[3], group=self.groups[2], perm_rank=1),
            GroupMemberFactory(user=self.users[6], group=self.groups[2], perm_rank=1),
            GroupMemberFactory(user=self.users[6], group=self.groups[3], perm_rank=1),
            GroupMemberFactory(user=self.users[8], group=self.groups[3], perm_rank=1),
            GroupMemberFactory(user=self.users[4], group=self.groups[4], perm_rank=1),
            GroupMemberFactory(user=self.users[7], group=self.groups[4], perm_rank=1),
            GroupMemberFactory(user=self.users[9], group=self.groups[4], perm_rank=0),  # pending request
        ]

        # User #5 is invited to group #2
        self.users[5].invited_to_groups.add(self.groups[2])

        # GroupAcknowledgments
        GroupAcknowledgmentFactory(parent_group=self.clusters[0].group_ptr, subgroup=self.groups[1], validated=True)

        # Misc
        self.mship_url = "/group-member/?"
    def setUpTestData(self):
        super(APITestCase, self).setUpTestData()

        # Routes
        self.members_url = "/group-member/"
        self.member_url = self.members_url + "%d/"

        # Public Group, open to anyone
        self.group = GroupFactory()
        self.group.is_private = False
        self.group.default_member_rank = 1
        self.group.save()

        # Users already in group
        self.users = [UserFactory()]
        # Associated GroupMember
        self.group_member1 = GroupMember(user=self.users[0], group=self.group, perm_rank=Group.ADMINISTRATOR_RANK)

        # Testing user
        self.user = UserFactory()

        # Misc
        self.new_membership_data = {"group_id": self.group.id, "user_id": self.user.id}
Beispiel #6
0
    def setUpTestData(self):
        # Summary: 2 clusters, 2 groups, 10 users
        # Cluster #1: users #1 to #5
        # Cluster #2: users #5 to #9
        # Group #1: users #1, #2 and #6 (pending request)
        # Group #2: users #3, #7 and #8 (invitation not accepted yet)
        # User #1 is admin in cluster #1
        # User #6 is admin in cluster #2
        # User #10 is Sigma admin

        super(UserTests, self).setUpTestData()
        self.clusters = ClusterFactory.create_batch(2)
        self.users = UserFactory.create_batch(9)
        self.groups = GroupFactory.create_batch(2)

        # User #10 is Sigma admin
        self.users.append(AdminUserFactory())

        # Add users in clusters (user #1 is admin in cluster #1 and user #6 is admin in cluster #2)
        for i in range(5):
            self.clusters[0].cluster_users.add(self.users[i])
            GroupMemberFactory(
                group=self.clusters[0],
                user=self.users[i],
                perm_rank=(Group.ADMINISTRATOR_RANK if i == 0 else 1))

            self.clusters[1].cluster_users.add(self.users[4 + i])
            GroupMemberFactory(
                group=self.clusters[1],
                user=self.users[4 + i],
                perm_rank=(Group.ADMINISTRATOR_RANK if i == 1 else 1))

        # Add users in group #1
        GroupMemberFactory(group=self.groups[0],
                           user=self.users[0],
                           perm_rank=Group.ADMINISTRATOR_RANK)
        GroupMemberFactory(group=self.groups[0],
                           user=self.users[1],
                           perm_rank=1)
        GroupMemberFactory(group=self.groups[0],
                           user=self.users[5],
                           perm_rank=0)  # pending request

        # Add users in group #2
        GroupMemberFactory(group=self.groups[1],
                           user=self.users[2],
                           perm_rank=1)
        GroupMemberFactory(group=self.groups[1],
                           user=self.users[6],
                           perm_rank=1)
        self.users[7].invited_to_groups.add(
            self.groups[1])  # User #8 is invited to group #2

        self.user_url = '/user/'
        self.new_user_data = {
            'lastname': 'Doe',
            'firstname': 'John',
            'email': '*****@*****.**',
            'password': '******',
            'clusters_ids': {self.clusters[0].id}
        }