Ejemplo n.º 1
0
    def setUp(self):
        self.staff = structure_factories.UserFactory(is_staff=True)
        self.customer_owner = structure_factories.UserFactory()
        self.project_admin = structure_factories.UserFactory()
        self.project_manager = structure_factories.UserFactory()
        self.user = structure_factories.UserFactory()

        self.customer = structure_factories.CustomerFactory()
        self.second_customer = structure_factories.CustomerFactory()
        self.customer.add_user(self.customer_owner,
                               structure_models.CustomerRole.OWNER)

        self.customer_role = structure_models.CustomerRole.OWNER
        self.customer_invitation = factories.CustomerInvitationFactory(
            customer=self.customer, customer_role=self.customer_role)

        self.project = structure_factories.ProjectFactory(
            customer=self.customer)
        self.project.add_user(self.project_admin,
                              structure_models.ProjectRole.ADMINISTRATOR)
        self.project.add_user(self.project_manager,
                              structure_models.ProjectRole.MANAGER)

        self.project_role = structure_models.ProjectRole.ADMINISTRATOR
        self.project_invitation = factories.ProjectInvitationFactory(
            project=self.project, project_role=self.project_role)
Ejemplo n.º 2
0
    def test_invitation_is_canceled_after_expiration_date(self):
        waldur_section = settings.WALDUR_CORE.copy()
        waldur_section['INVITATION_LIFETIME'] = timedelta(weeks=1)

        with self.settings(WALDUR_CORE=waldur_section):
            invitation = factories.ProjectInvitationFactory(created=timezone.now() - timedelta(weeks=1))
            tasks.cancel_expired_invitations()

        self.assertEqual(models.Invitation.objects.get(uuid=invitation.uuid).state, models.Invitation.State.EXPIRED)
Ejemplo n.º 3
0
    def test_user_which_already_has_role_within_project_cannot_accept_invitation(self):
        project_invitation = factories.ProjectInvitationFactory(
            project=self.project, project_role=self.project_role)
        self.client.force_authenticate(user=self.user)
        self.project.add_user(self.user, project_invitation.project_role)
        response = self.client.post(factories.ProjectInvitationFactory.get_url(project_invitation, action='accept'))

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, ['User already has role within this project.'])
Ejemplo n.º 4
0
    def test_when_expert_request_is_cancelled_pending_invitations_are_cancelled(self):
        # Arrange
        expert = structure_factories.UserFactory()
        self.expert_team.add_user(expert, structure_models.ProjectRole.ADMINISTRATOR)
        user_factories.ProjectInvitationFactory(
            email=expert.email,
            project=self.expert_request.project,
            project_role=structure_models.ProjectRole.ADMINISTRATOR,
        )

        # Act
        self.client.force_authenticate(self.staff)
        response = self.cancel_expert_request()

        # Assert
        pending_invitations = user_models.Invitation.objects.filter(state=user_models.Invitation.State.PENDING)
        self.assertFalse(pending_invitations.exists())

        cancelled_invitations = user_models.Invitation.objects.filter(state=user_models.Invitation.State.CANCELED)
        self.assertEqual(cancelled_invitations.count(), 1)