Example #1
0
    def test_form_with_an_authorised_project_member(self):
        """
        Ensure it is not possible to create a project user membership when a user is an
        authorised member of the project. By default, when the project is approved, a project user
        membership will be created for the technical lead.
        """
        accounts = [
            self.project_owner,
        ]

        for account in accounts:
            # Create a project.
            code = ''.join(
                random.sample(string.ascii_uppercase + string.digits, k=10)
            )
            project = Project.objects.get(code="scw0000")
            # self.approve_project(project)

            # A request to create a project user membership should be rejected.
            form = ProjectUserInviteForm(
                initial={
                    'project_id': project.id,
                },
                data={
                    'email': account.email,
                },
            )
            self.assertFalse(form.is_valid())

            # Ensure the project user membership status is currently set authorised.
            membership = ProjectUserMembership.objects.get(
                user=account, project=project
            )
            self.assertTrue(membership.is_authorised())
Example #2
0
    def test_form(self):
        """
        Ensure it is possible to create a project user membership.
        """
        # self.approve_project(self.project)

        form = ProjectUserInviteForm(
            initial={
                'project_id': 1,
            },
            data={
                'email': self.project_applicant.email,
            },
        )
        self.assertTrue(form.is_valid())
Example #3
0
    def test_form_when_user_is_not_found(self):
        """
        Ensure it is not possible to create a project user membership when the use does
        not exist.
        """
        # Create a project.
        project = Project.objects.get(code="scw0000")

        # A request to create a project user membership should be rejected.
        form = ProjectUserInviteForm(
            initial={
                'project_id': project.id,
            },
            data={
                'email': '*****@*****.**',
            },
        )
        self.assertFalse(form.is_valid())
Example #4
0
    def test_form_when_a_user_has_a_request_awaiting_authorisation(self):
        """
        Ensure it is not possible to create a project user membership when a user has a
        membership request awaiting authorisation.
        """
        # Create a project.
        code = ''.join(
            random.sample(string.ascii_uppercase + string.digits, k=10)
        )
        project = Project.objects.get(code="scw0000")
        # self.approve_project(project)

        # Create a project user membership.
        ProjectUserMembership.objects.create(
            project=project,
            user=self.project_applicant,
            status=ProjectUserMembership.AWAITING_AUTHORISATION,
            date_joined=datetime.datetime.now(),
            date_left=datetime.datetime.now() + datetime.timedelta(days=10),
        )

        # Ensure the project user membership status is currently set to awaiting authorisation.
        membership = ProjectUserMembership.objects.get(
            user=self.project_applicant,
            project=project,
        )
        self.assertTrue(membership.is_awaiting_authorisation())

        # A request to create a project user membership should be rejected.
        form = ProjectUserInviteForm(
            initial={
                'project_id': 1,
            },
            data={
                'email': self.project_applicant.email,
            },
        )
        self.assertFalse(form.is_valid())