Exemplo 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)
Exemplo n.º 2
0
    def test_user_can_rewrite_his_email_on_invitation_accept(self):
        invitation = factories.CustomerInvitationFactory(created_by=self.customer_owner, email='*****@*****.**')
        self.client.force_authenticate(user=self.user)

        self.client.post(
            factories.CustomerInvitationFactory.get_url(invitation, action='accept'), {'replace_email': True})

        self.assertEqual(self.user.email, invitation.email)
Exemplo n.º 3
0
    def test_user_with_invalid_civil_number_cannot_accept_invitation(self):
        customer_invitation = factories.CustomerInvitationFactory(
            customer=self.customer, customer_role=self.customer_role, civil_number='123456789')
        self.client.force_authenticate(user=self.user)
        response = self.client.post(factories.CustomerInvitationFactory.get_url(customer_invitation, action='accept'))

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, ['User has an invalid civil number.'])
Exemplo n.º 4
0
 def test_if_user_has_civil_number_non_matching_invitation_is_concealed(
         self):
     customer_invitation = factories.CustomerInvitationFactory(
         customer=self.customer,
         customer_role=self.customer_role,
         civil_number='123456789',
     )
     response = self.get_details(self.user, customer_invitation)
     self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Exemplo n.º 5
0
    def test_user_which_already_has_role_within_customer_cannot_accept_invitation(self):
        customer_invitation = factories.CustomerInvitationFactory(
            customer=self.customer, customer_role=self.customer_role)
        self.client.force_authenticate(user=self.user)
        self.customer.add_user(self.user, customer_invitation.customer_role)
        response = self.client.post(factories.CustomerInvitationFactory.get_url(customer_invitation, action='accept'))

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, ['User already has role within this customer.'])
Exemplo n.º 6
0
 def test_user_which_created_invitation_is_stored_in_permission(self):
     invitation = factories.CustomerInvitationFactory(
         created_by=self.customer_owner)
     self.client.force_authenticate(user=self.user)
     self.client.post(
         factories.CustomerInvitationFactory.get_url(invitation,
                                                     action='accept'))
     permission = structure_models.CustomerPermission.objects.get(
         user=self.user, customer=invitation.customer)
     self.assertEqual(permission.created_by, self.customer_owner)
Exemplo n.º 7
0
 def test_if_user_has_civil_number_only_matching_invitation_is_shown(self):
     customer_invitation = factories.CustomerInvitationFactory(
         customer=self.customer,
         customer_role=self.customer_role,
         civil_number='123456789',
     )
     self.user.civil_number = '123456789'
     self.user.save()
     response = self.get_details(self.user, customer_invitation)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
Exemplo n.º 8
0
    def test_user_can_accept_invitation_if_emails_match_and_validation_of_emails_is_on(self):
        invitation = factories.CustomerInvitationFactory(created_by=self.customer_owner, email=self.user.email)
        self.client.force_authenticate(user=self.user)
        url = factories.CustomerInvitationFactory.get_url(invitation, action='accept')

        response = self.client.post(url, {'replace_email': True})

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.user.refresh_from_db()
        self.assertEqual(self.user.email, invitation.email)
Exemplo n.º 9
0
    def test_user_can_not_rewrite_his_email_on_acceptance_if_validation_of_emails_is_on(self):
        invitation = factories.CustomerInvitationFactory(created_by=self.customer_owner, email='*****@*****.**')
        self.client.force_authenticate(user=self.user)
        url = factories.CustomerInvitationFactory.get_url(invitation, action='accept')

        response = self.client.post(url, {'replace_email': True})

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.user.refresh_from_db()
        self.assertNotEqual(self.user.email, invitation.email)
Exemplo n.º 10
0
    def test_user_can_resend_expired_invitation(self):
        customer_expired_invitation = factories.CustomerInvitationFactory(
            state=models.Invitation.State.EXPIRED)

        self.client.force_authenticate(user=self.staff)
        response = self.client.post(factories.CustomerInvitationFactory
                                    .get_url(customer_expired_invitation, action='send'))
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        customer_expired_invitation.refresh_from_db()
        self.assertEqual(customer_expired_invitation.state, models.Invitation.State.PENDING)
        self.assertEqual(customer_expired_invitation.created, timezone.now())
Exemplo n.º 11
0
    def test_user_can_not_reuse_existing_email(self):
        # Arrange
        invitation = factories.CustomerInvitationFactory(created_by=self.customer_owner)
        structure_factories.UserFactory(email=invitation.email)

        # Act
        self.client.force_authenticate(user=self.user)
        url = factories.CustomerInvitationFactory.get_url(invitation, action='accept')
        response = self.client.post(url, {'replace_email': True})

        # Assert
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.user.refresh_from_db()
        self.assertNotEqual(self.user.email, invitation.email)
Exemplo n.º 12
0
 def test_if_email_validation_is_disabled_non_matching_invitation_is_shown(
     self, ):
     invitation = factories.CustomerInvitationFactory(
         created_by=self.customer_owner)
     response = self.get_details(self.user, invitation)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
Exemplo n.º 13
0
 def test_if_email_validation_is_enabled_non_matching_invitation_is_concealed(
     self, ):
     invitation = factories.CustomerInvitationFactory(
         created_by=self.customer_owner)
     response = self.get_details(self.user, invitation)
     self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)