Esempio 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.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)
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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.'])
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
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.'])