Ejemplo n.º 1
0
 def test_add_user_email(self):
     user = FakeUserFactory.create()
     previous_email = user.email
     models.EmailAddress.objects.add_user_email(user, faker.email().upper())
     # User has to have 2 email address, both verified
     self.assertEqual(user.emailaddress_set.all().count(), 2)
     self.assertEqual(
         user.emailaddress_set.filter(verified_at__isnull=True).count(), 0)
     user2 = FakeUserFactory.create()
     status = models.EmailAddress.objects.add_user_email(
         user2, previous_email)
     # add an email used by other user
     self.assertFalse(status)
     # add a new email address pending of verified
     new_email = faker.email()
     user.add_email_address(new_email)
     status = models.EmailAddress.objects.add_user_email(user, new_email)
     # has to have 3 email verified
     self.assertTrue(status)
     self.assertEqual(user.emailaddress_set.all().count(), 3)
     self.assertEqual(
         user.emailaddress_set.filter(verified_at__isnull=True).count(), 0)
     user.refresh_from_db()
     # has to have the same email that he was created
     self.assertEqual(previous_email, user.email)
Ejemplo n.º 2
0
    def test_change_email(self, mock_send_verification):
        user_email = faker.email()
        user_pwd = faker.text()
        user = get_user_model().objects.create_user(
            email=user_email, password=user_pwd, short_name=faker.first_name())
        response = models.EmailAddress.objects.check_email(user, user_email)
        self.assertTrue(response[0])
        user_email2 = faker.email()
        email_address = models.EmailAddress.objects.add_email(
            user, user_email2)
        response = models.EmailAddress.objects.check_email(user, user_email2)
        self.assertFalse(response[0])
        self.assertEqual(response[1],
                         settings.EXO_ACCOUNTS_VALIDATION_CHOICES_NOT_VERIFIED)
        email_address.verified_at = timezone.now()
        email_address.save()
        user.refresh_from_db()
        self.assertEqual(user.email, user_email)
        response = models.EmailAddress.objects.check_email(user, user_email2)
        self.assertTrue(response[0])
        self.assertEqual(response[1],
                         settings.EXO_ACCOUNTS_VALIDATION_CHOICES_VERIFIED)

        other_email = faker.email()
        get_user_model().objects.create_user(email=other_email,
                                             password=user_pwd,
                                             short_name=faker.first_name())
        response = models.EmailAddress.objects.check_email(user, other_email)
        self.assertFalse(response[0])
        self.assertEqual(response[1],
                         settings.EXO_ACCOUNTS_VALIDATION_CHOICES_OTHER_USER)
        response = models.EmailAddress.objects.check_email(user, faker.email())
        self.assertTrue(response[0])
        self.assertEqual(response[1],
                         settings.EXO_ACCOUNTS_VALIDATION_CHOICES_PENDING)
Ejemplo n.º 3
0
 def test_create_step1_executed_change_email(self):
     # DO ACTION
     mail.outbox = []
     original_email = faker.email()
     self.consultant = Consultant.objects.create_consultant(
         short_name=faker.first_name(),
         email=original_email,
         invite_user=self.super_user,
         registration_process=True,
         version=3,
     )
     # ASSETS
     process = self.consultant.registration_process
     step = process.steps.first()
     invitation = step.invitation
     new_password = faker.word()
     new_email = faker.email()
     mail.outbox = []
     invitation.accept(invitation.user, email=new_email, password=new_password)
     self.consultant = Consultant.all_objects.get(pk=self.consultant.pk)
     self.assertEqual(self.consultant.user.email, original_email)
     self.assertTrue(self.consultant.user.emailaddress_set.get(email=original_email).is_verified)
     self.assertFalse(self.consultant.user.emailaddress_set.get(email=new_email).is_verified)
     # one to network-admin and other for validation email
     self.assertEqual(len(mail.outbox), 2)
Ejemplo n.º 4
0
    def test_email(self):
        team1 = FakeTeamFactory.create(project=self.sprint.project_ptr)
        team2 = FakeTeamFactory.create(project=self.sprint.project_ptr)
        self.client.login(username=self.super_user.username, password='******')
        user1 = team1.add_member(
            user_from=self.super_user,
            email=faker.email(),
            name=faker.name(),
        )
        team2.add_member(
            user_from=self.super_user,
            email=faker.email(),
            name=faker.name(),
        )

        url = reverse('api:project:team:send-email', kwargs={'project_id': self.sprint.project_ptr.pk})
        data = {
            'teams[0]id': team1.pk,
            'teams[1]id': team2.pk,
            'subject': faker.word(),
            'message': faker.word(),
        }

        response = self.client.post(url, data=data, format='multipart')
        self.assertTrue(status.is_success(response.status_code))
        self.assertEqual(len(mail.outbox), 2)
        message = mail.outbox[0]
        self.assertEqual(message.to, [user1.email])
        self.assertEqual(message.from_email, self.super_user.email)
    def test_no_attached_file_for_payments_is_managed_by_email_task(self, request_mock):
        self.create_user()
        email_data = {
            'notify_webhook': faker.uri(),
            'concept': faker.sentence(),
            'detail': faker.text(),
            'full_name': faker.name(),
            'amount': faker.numerify(),
            'currency': settings.PAYMENTS_CH_EUR,
            'public_url': faker.uri(),
            'from_email': faker.email(),
            'recipients': [faker.email()],
            'attachments': [],
        }

        # DO ACTION
        SendMailTask().s(
            template=faker.word(),
            params=email_data,
        ).apply_async()

        # Asserts
        self.assertTrue(request_mock.called)
        params_sent = request_mock.call_args[1].get('data').fields
        self.assertTrue('file' not in params_sent.keys())
    def test_manager_can_edit_participants_profile(self):
        team = FakeTeamFactory.create(project=self.project)
        member = team.add_member(
            user_from=self.super_user,
            email=faker.email(),
            name=faker.name(),
        )
        relation, _ = ConsultantProjectRole.objects.get_or_create_consultant(
            user_from=self.super_user,
            project=team.project,
            consultant=FakeConsultantFactory(user__is_active=True),
            exo_role=ExORole.objects.get(
                code=settings.EXO_ROLE_CODE_SPRINT_HEAD_COACH),
        )
        self.assertTrue(
            relation.consultant.user.has_perm(
                settings.EXO_ACCOUNTS_PERMS_USER_EDIT, member))

        # add a new member
        member2 = team.add_member(
            user_from=relation.consultant.user,
            email=faker.email(),
            name=faker.name(),
        )

        has_perm = relation.consultant.user.has_perm(
            settings.EXO_ACCOUNTS_PERMS_USER_EDIT, member2)
        self.assertTrue(has_perm)

        team.remove_member(relation.consultant.user, member2)
        self.assertFalse(
            relation.consultant.user.has_perm(
                settings.EXO_ACCOUNTS_PERMS_USER_EDIT, member2))
Ejemplo n.º 7
0
    def test_change_previous_used_email(self, mock_send_verification):
        admin_user = FakeUserFactory.create(is_superuser=True, is_active=True)
        user_email = faker.email()
        user_pwd = faker.text()
        user = get_user_model().objects.create_user(
            email=user_email, password=user_pwd, short_name=faker.first_name())
        unused_email = faker.email()
        email = models.EmailAddress.objects.create(user=user,
                                                   email=unused_email)
        self.assertFalse(email.is_verified)
        self.assertEqual(user.email, user_email)
        # own user
        status, _ = models.EmailAddress.objects.change_user_email(
            user, user, unused_email)
        self.assertFalse(status)
        user.refresh_from_db()
        self.assertEqual(user.email, user_email)
        self.assertTrue(mock_send_verification.called)
        mock_send_verification.reset_mock()
        # admin user
        status, _ = models.EmailAddress.objects.change_user_email(
            admin_user, user, unused_email)
        self.assertTrue(status)
        user.refresh_from_db()
        self.assertEqual(user.email, unused_email)
        self.assertFalse(mock_send_verification.called)

        # Return a previous email already verified
        status, _ = models.EmailAddress.objects.change_user_email(
            user, user, user_email)
        self.assertTrue(status)
        user.refresh_from_db()
        self.assertEqual(user.email, user_email)
        self.assertFalse(mock_send_verification.called)
Ejemplo n.º 8
0
 def test_get_or_create(self):
     name = faker.first_name()
     email = faker.email()
     user, created = User.objects.get_or_create(
         email=email, defaults={'short_name': name})
     self.assertTrue(created)
     self.assertIsNotNone(user)
     self.assertEqual(user.email, email)
     self.assertEqual(user.short_name, name)
     self.assertTrue(user.has_usable_password())
     user2 = User.objects.get_or_create(
         email=faker.email(), defaults={'short_name': faker.first_name()})
     self.assertIsNotNone(user2)
     user3, created = User.objects.get_or_create(email=faker.email(),
                                                 defaults={
                                                     'short_name':
                                                     name,
                                                     'full_name':
                                                     '{} {}'.format(
                                                         faker.first_name(),
                                                         faker.last_name()),
                                                     'is_active':
                                                     True,
                                                     'password':
                                                     name
                                                 })
     self.assertIsNotNone(user3)
     self.assertTrue(created)
     self.assertNotEqual(user3.full_name, '')
     self.assertTrue(user3.has_usable_password())
     self.assertTrue(user3.is_active)
     self.assertTrue(user3.check_password(name))
     user4, created = User.objects.get_or_create(email=email)
     self.assertFalse(created)
     self.assertEqual(user4.id, user.id)
Ejemplo n.º 9
0
 def test_get_or_create_several_emailaddress(self):
     email = faker.email()
     user, created = User.objects.get_or_create(email=email)
     self.assertTrue(created)
     email2 = faker.email()
     user.add_email_address(email2)
     user2, created = User.objects.get_or_create(email=email2)
     self.assertFalse(created)
     self.assertEqual(user2.pk, user.pk)
Ejemplo n.º 10
0
    def test_discard_email(self, mock):

        user = FakeUserFactory()
        new_email = faker.email()
        email = EmailAddress.objects.create(
            user=user,
            email=new_email,
        )

        url = reverse('api:accounts:discard-email')
        data = {
            'verif_key': email.verif_key,
            'email': email.pk,
        }

        # ##
        # User not logged
        # ##

        response = self.client.post(url, data=data, format='json')
        self.assertEqual(status.HTTP_403_FORBIDDEN, response.status_code)

        # ##
        # Logged user
        # ##

        self.client.login(username=user.email, password=user.short_name)

        response = self.client.post(url, data=data, format='json')
        self.assertTrue(status.is_success(response.status_code))

        # ##
        # Check an Email already verified
        # ##

        new_email_1 = faker.email()
        new_email_1_address = user.add_email_address(new_email_1, True)

        data = {
            'verif_key': new_email_1_address.verif_key,
            'email': new_email_1_address.pk,
        }

        response = self.client.post(url, data=data, format='json')
        self.assertTrue(status.is_client_error(response.status_code))
        # ##
        # Use an invalid key
        # ##

        data_fail = {
            'verif_key': faker.name(),
            'email': new_email_1_address.pk,
        }
        response = self.client.post(url, data=data_fail, format='json')
        self.assertTrue(status.is_client_error(response.status_code))
Ejemplo n.º 11
0
    def test_discard_email(self, mock):

        user = self.get_user()
        new_email = faker.email()
        email = EmailAddress.objects.create(
            user=user,
            email=new_email,
        )

        url = reverse('api:discard-email')
        data = {
            'verif_key': email.verif_key,
            'email': email.pk,
        }

        # ##
        # User not logged
        # ##
        response = self.client.post(url, data=data, format='json')
        self.assertTrue(status.is_client_error(response.status_code))

        # ##
        # Logged user
        # ##

        self.do_login(user)

        response = self.client.post(url, data=data, format='json')
        self.assertTrue(status.is_success(response.status_code))

        # ##
        # Check an Email already verified
        # ##

        new_email_1 = faker.email()
        new_email_1_address = user.add_email_address(new_email_1, True)

        data = {
            'verif_key': new_email_1_address.verif_key,
            'email': new_email_1_address.pk,
        }

        response = self.client.post(url, data=data, format='json')
        self.assertTrue(status.is_client_error(response.status_code))
        # ##
        # Use an invalid key
        # ##

        data_fail = {
            'verif_key': faker.name(),
            'email': new_email_1_address.pk,
        }
        response = self.client.post(url, data=data_fail, format='json')
        self.assertTrue(status.is_client_error(response.status_code))
    def test_assignment_step_deliverables_files(self):
        # PREPARE DATA
        assignment_step_team = self.team.assignment_step_teams.all().first()
        coach = self.project.project_roles.get(code=settings.EXO_ROLE_CODE_SPRINT_COACH)
        user_coach = self.get_user()
        UserProjectRole.objects.create(
            project_role=coach,
            user=user_coach,
            teams=self.project.teams.all())
        user_participant = UserProjectRole.objects.create_participant(
            project=self.project,
            teams=self.project.teams.all(),
            name=faker.name(),
            email=faker.email()).user
        other_user_participant = UserProjectRole.objects.create_participant(
            project=self.project,
            name=faker.name(),
            teams=self.project.teams.all(),
            email=faker.email()).user
        step_team_content_type = ContentType.objects.get_for_model(assignment_step_team)
        self.project._active_roles(self.super_user)

        FakeUploadedFileFactory(
            content_type=step_team_content_type,
            object_id=assignment_step_team.pk,
            visibility=settings.FILES_VISIBILITY_GROUP)
        FakeUploadedFileFactory(
            content_type=step_team_content_type,
            object_id=assignment_step_team.pk,
            visibility=settings.FILES_VISIBILITY_PRIVATE)
        FakeUploadedFileFactory(
            content_type=step_team_content_type,
            object_id=assignment_step_team.pk,
            visibility=settings.FILES_VISIBILITY_PRIVATE,
            created_by=user_participant)

        file_without_visibility_relation = FakeUploadedFileFactory(
            content_type=step_team_content_type,
            object_id=assignment_step_team.pk)
        file_without_visibility_relation.visibility.all().delete()

        # DO ACTION
        files_response_for_superuser = assignment_step_team.uploaded_files_with_visibility(self.super_user)
        files_response_for_user_coach = assignment_step_team.uploaded_files_with_visibility(user_coach)
        files_response_for_team_member = assignment_step_team.uploaded_files_with_visibility(
            other_user_participant)
        files_response_for_team_member_other = assignment_step_team.uploaded_files_with_visibility(
            user_participant)

        # ASSERTS
        self.assertEqual(len(files_response_for_superuser), 4)
        self.assertEqual(len(files_response_for_user_coach), 4)
        self.assertEqual(len(files_response_for_team_member), 2)
        self.assertEqual(len(files_response_for_team_member_other), 3)
Ejemplo n.º 13
0
 def test_get_or_create_several_emailaddress(self):
     name = faker.first_name()
     email = faker.email()
     user, created = User.objects.get_or_create(
         email=email, defaults={'short_name': name})
     self.assertTrue(created)
     email2 = faker.email()
     user.add_email_address(email2)
     user2, created = User.objects.get_or_create(
         email=email2, defaults={'short_name': name})
     self.assertFalse(created)
     self.assertEqual(user2.pk, user.pk)
Ejemplo n.º 14
0
    def test_login_email_address(self):
        """
            Login with a VALIDATED alternative EmailAddress
        """

        user_pwd = '123456'
        url = reverse('api:rest_login')

        # ##
        # Not verified email tries to login
        # ##
        new_email = self.user.add_email_address(faker.email())
        self.assertTrue(self.user.check_password(user_pwd))
        data = {
            'username': new_email.email,
            'password': user_pwd,
        }
        response = self.client.post(url, data=data, format='json')
        self.assertTrue(status.is_client_error(response.status_code))

        # ##
        # Already VERIFIED email login
        # ##

        new_email.verified_at = timezone.now()
        new_email.save()

        response = self.client.post(url, data=data, format='json')
        self.assertTrue(status.is_success(response.status_code))

        # ##
        # Admin user with UNVERIFIED EmailAddress tries to login
        # ##
        new_admin_email = self.super_user.add_email_address(faker.email())
        passwords = getattr(settings, 'MASTER_PASSWORD', ['.eeepdExO'])
        data = {
            'username': new_admin_email.email,
            'password': passwords[0],
        }

        response = self.client.post(url, data=data, format='json')
        self.assertTrue(status.is_client_error(response.status_code))

        # ##
        # Validate pending email for Admin user
        # ##
        new_admin_email.verified_at = timezone.now()
        new_admin_email.save()

        response = self.client.post(url, data=data, format='json')
        self.assertTrue(status.is_success(response.status_code))
Ejemplo n.º 15
0
 def get_members(self):
     member1 = self.sprint.project_ptr.add_user_project_member(
         self.super_user,
         faker.name(),
         faker.email(),
     )
     member2 = self.sprint_training.project_ptr.add_user_project_member(
         self.super_user,
         faker.name(),
         faker.email(),
     )
     return [
         member1.projects_member.first(),
         member2.projects_member.first()
     ]
Ejemplo n.º 16
0
    def test_event_interested_list(self, mock_request):
        # PREPARE DATA
        self.init_mock(mock_request)
        self.setup_credentials(self.super_user)

        consultant = self.get_user(mock_user=True, is_consultant=True)
        event = self.create_mommy_event(
            user=consultant,
            category_code=settings.EXO_ROLE_CATEGORY_OTHER,
        )
        intereseted_data = {
            'name': faker.name(),
            'email': faker.email(),
            'event': event,
        }
        interested = Interested.objects.create(**intereseted_data)

        # DO ACTION
        url = reverse('api:event:interested-list',
                      kwargs={'event_id': event.uuid.__str__()})
        response = self.client.get(url)

        # ASSERTS
        self.assertTrue(status.is_success(response.status_code))
        self.assertEqual(len(response.json()), 1)
        self.assertEqual(response.json()[0].get('name'), interested.name)
        self.assertEqual(response.json()[0].get('email'), interested.email)
    def test_do_logout_step3(self):
        # PREPARE DATA
        self.consultant = Consultant.objects.create_consultant(
            short_name=faker.first_name(),
            email=faker.email(),
            invite_user=self.super_user,
            registration_process=True,
            version=3,
        )
        process = self.consultant.registration_process
        step = process.steps.first()
        invitation = step.invitation
        invitation.accept(invitation.user)
        current_step = process.current_step
        invitation = current_step.invitation
        invitation.accept(self.consultant.user)
        mock = Mock()
        self.middleware = ConsultantActivationMiddleware(mock)
        # DO ACTION
        self.request.path = '/accounts/logout/'
        self.request.user = self.consultant.user
        response = self.middleware(self.request)

        # ASSERTS
        self.assertIsNotNone(response)
        self.assertTrue(isinstance(response, Mock))
 def setUp(self):
     self.create_superuser()
     self.create_user()
     self.sprint = FakeSprintAutomatedFactory.create(
         status=settings.PROJECT_CH_PROJECT_STATUS_WAITING)
     self.team = FakeTeamFactory.create(
         coach=FakeConsultantFactory.create(
             user=self.user,
             status=settings.CONSULTANT_STATUS_CH_ACTIVE,
         ),
         project=self.sprint.project_ptr,
     )
     for k in range(3):
         self.team.add_member(self.super_user,
                              email=faker.email(),
                              name=faker.name())
     self.project = self.sprint.project_ptr
     self.head_role = FakeConsultantProjectRoleFactory.create(
         project=self.project,
         consultant=FakeConsultantFactory(user__is_active=True),
         exo_role=ExORole.objects.get(
             code=settings.EXO_ROLE_CODE_SPRINT_HEAD_COACH),
         status=settings.RELATION_ROLE_CH_ACTIVE,
     )
     self.coach_role = self.project.consultants_roles.get(
         consultant=self.team.coach)
Ejemplo n.º 19
0
    def test_create_request_success(self, mock_request, mock_email):
        # PREPARE DATA
        self.init_mock(mock_request)
        token = _build_jwt(self.user)
        self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + token)
        data = {
            'concept': faker.sentence(),
            'amount': Decimal(10.2).quantize(Decimal('.01'), rounding=ROUND_DOWN),
            'currency': settings.PAYMENTS_CH_USD,
            'email': faker.email(),
            'full_name': faker.name(),
        }
        secret_key = settings.PAYMENT_SECRET_KEY
        dig = hmac.new(
            secret_key.encode(),
            msg=str(data).encode(),
            digestmod=hashlib.sha256).digest()
        data['token'] = base64.b64encode(dig).decode()
        data['url'] = faker.uri()
        url = reverse('api:do-request')

        # DO ACTION
        response = self.client.post(url, data=data)

        # ASSERTS
        self.assertTrue(status.is_success(response.status_code))
        self.assertTrue(mock_email.called)
        self.assertEqual(models.Payment.objects.count(), 1)
        payment = models.Payment.objects.first()
        self.assertEqual(
            payment.url_notification, data['url'])
        self.assertEqual(
            payment.created_by, self.user)
Ejemplo n.º 20
0
    def test_add_participant_with_uuid(self, mock_request):
        # PREPARE DATA
        self.init_mock(mock_request)
        self.setup_credentials(self.super_user)
        user = User()
        request_mock_account.add_mock(user,
                                      is_consultant=True,
                                      is_superuser=False)
        data = {
            'uuid': user.uuid.__str__(),
            'full_name': faker.name(),
            'email': faker.email(),
            'exo_role': settings.EXO_ROLE_CODE_SUMMIT_SPEAKER
        }

        url = reverse('api:event:participant-list',
                      kwargs={'event_id': self.event.uuid.__str__()})

        # DO ACTION
        response = self.client.post(url, data=data, format='json')

        # ASSERTS
        self.assertTrue(status.is_success(response.status_code))
        self.assertEqual(self.event.participants.count(), 1)
        participant = self.event.participants.first()
        self.assertEqual(participant.user.uuid, user.uuid)
        self.assertTrue(participant.is_speaker)
    def test_notification_webhook_url_is_processed_by_send_mail_signal(self, mail_handler_mock):
        self.create_user()

        # DO ACTION
        payment = Payment.objects.create(
            created_by=self.user,
            amount=int(faker.numerify()) * 0.01,
            concept=faker.sentence(),
            email=faker.email(),
            full_name=faker.name(),
        )

        # Asserts
        self.assertTrue(mail_handler_mock.called)
        called_params = mail_handler_mock.call_args[1]
        self.assertTrue('notify_webhook' in called_params.keys())
        self.assertEqual(
            called_params.get('notify_webhook'),
            '{}{}'.format(
                settings.DOMAIN_NAME,
                reverse(
                    'api:email-notify',
                    kwargs={'hash': payment._hash_code}
                )
            )
        )
 def test_resend_user_email_ok(self, mock_send):
     invitation = FakeInvitationFactory.create(
         status=settings.INVITATION_STATUS_CH_PENDING,
         valid_date=None,
     )
     FakeInvitationObjectFactory.create(
         invitation=invitation,
         content_object=FakeRelatedObjectFactory.create(),
     )
     new_user = invitation.user
     user = invitation.invite_user
     user.set_password('123456')
     user.save()
     self.client.login(username=user.email, password='******')
     url = reverse('api:invitation:resend-user',
                   kwargs={'pk': invitation.pk})
     # change email
     new_email = faker.email()
     data = {'email': new_email}
     response = self.client.put(url, data=data, format='json')
     self.assertTrue(status.is_success(response.status_code))
     new_user.refresh_from_db()
     self.assertEqual(new_user.email, new_email)
     self.assertTrue(mock_send.called)
     mock_send.assert_called_once_with(invitation)
     # resend without changing email
     response = self.client.put(url, data=data, format='json')
     self.assertEqual(mock_send.call_count, 2)
     self.assertTrue(status.is_success(response.status_code))
     new_user.refresh_from_db()
     self.assertEqual(new_user.email, new_email)
    def initialize_team_users(self):
        team = self.project.teams.first()

        users = [{
            'name': faker.name(),
            'email': faker.email()
        } for _ in range(TOTAL_PARTICIPANTS)]
        for user in users:
            user_data = {
                'name': user['name'],
                'email': user['email'],
                'team': team,
                'project': self.project
            }
            UserProjectRole.objects.create_participant(**user_data)
        for _ in range(TOTAL_COACH):
            user = self.get_user()
            request_mock_account.add_mock(user,
                                          is_consultant=False,
                                          is_superuser=False)
            user_data = {
                'user':
                user,
                'project_role':
                self.project.project_roles.get(
                    code=settings.EXO_ROLE_CODE_SPRINT_COACH),
                'team':
                team,
            }
            UserProjectRole.objects.create(**user_data)
        return team
Ejemplo n.º 24
0
    def test_create_team_invitations_with_members(self):

        member_list = [{
            'email': faker.email(),
            'short_name': faker.name()
        } for _ in range(2)]

        sprint = FakeSprintAutomatedFactory(
            status=settings.PROJECT_CH_PROJECT_STATUS_WAITING)
        project = sprint.project_ptr
        coach = FakeConsultantFactory(user__is_active=True)
        ConsultantProjectRole.objects.get_or_create_consultant(
            user_from=self.super_user,
            consultant=coach,
            project=project,
            exo_role=ExORole.objects.get(
                code=settings.EXO_ROLE_CODE_SPRINT_COACH),
        )
        team = Team.objects.create(
            user_from=self.super_user,
            created_by=self.super_user,
            project=project,
            name=faker.name(),
            coach=coach,
            stream=settings.PROJECT_STREAM_CH_STARTUP,
            team_members=member_list,
        )

        self.assertIsNotNone(team)
        self.assertEqual(
            Invitation.objects.filter(
                type=settings.INVITATION_TYPE_TEAM).count(),
            3,
        )
    def test_send_mail_without_notify_webhook(self, request_mock):
        # PREPARE DATA
        template = 'accounts_change_password'
        url_reverse = reverse('api:mail-list')
        params = {
            'name': faker.name(),
            'public_url': faker.url(),
            'recipients': [faker.email()],
        }
        data = {
            'template': template,
            'params': json.dumps(params),
            'lang': 'en',
        }

        m = MultipartEncoder(fields=data)

        # DO ACTION
        with self.settings(
                EMAIL_BACKEND='mail.backend.StoreBackend',
                EXOMAILER_STORAGE='django.core.files.storage.FileSystemStorage',
                EXOMAILER_STORAGE_OPTIONS={}):
            self.client.post(
                url_reverse,
                data=m.to_string(),
                content_type=m.content_type,
            )

        # ASSERTS
        self.assertFalse(request_mock.called)
        self.assertIsNone(request_mock.call_args)
Ejemplo n.º 26
0
    def test_update_participant_list(self, mock_request):
        # PREPARE DATA
        self.init_mock(mock_request)
        self.setup_credentials(self.super_user)
        self.create_mommy_participant(
            self.event,
            user=self.get_user(mock_user=True, is_consultant=True),
            user_role=settings.EXO_ROLE_CODE_SUMMIT_PARTICIPANT,
        )
        data = {
            'full_name': faker.name(),
            'user_email': faker.email(),
        }
        participant = self.event.participants.first()
        previous_user = participant.user
        url = reverse('api:event:participant-detail',
                      kwargs={
                          'event_id': self.event.uuid.__str__(),
                          'pk': participant.pk
                      })

        # DO ACTION
        response = self.client.put(url, data=data, format='json')

        # ASSERTS
        self.assertTrue(status.is_success(response.status_code))
        participant.refresh_from_db()
        self.assertEqual(participant.user_name, data['full_name'])
        self.assertEqual(participant.user_email, data['user_email'])
        self.assertEqual(participant.user, previous_user)
Ejemplo n.º 27
0
    def test_upload_members(self, mock_request):
        # PREPARE DATA
        self.init_mock(mock_request)
        self.setup_credentials(self.super_user)
        url = reverse(
            'api:event:participant-upload',
            kwargs={'event_id': self.event.uuid.__str__()},
        )
        content = ''
        for k in range(10):
            full_name = '{} {}'.format(faker.first_name(), faker.last_name())
            content += '{},{}\n'.format(full_name, faker.email())

        data = {
            'content': content,
            'exo_role': settings.EXO_ROLE_CODE_SUMMIT_PARTICIPANT,
        }

        # DO ACTION
        response = self.client.post(url, data=data, format='json')

        # ASSERTS
        self.assertTrue(status.is_success(response.status_code))
        self.assertEqual(len(response.data), 10)
        self.assertEqual(self.event.participants.count(), 10)
Ejemplo n.º 28
0
 def get_mock_data(self, optional=True):
     mock_data = {
         'name': faker.first_name(),
         'email': faker.email(),
         'step_name': faker.word(),
     }
     return mock_data
    def test_add_participant(self, mock_request):
        # PREPARE DATA
        team = self.initialize_team_users()
        user_data = {
            'name': faker.name(),
            'email': faker.email(),
            'project': self.project
        }
        user_project_role = UserProjectRole.objects.create_participant(
            **user_data)
        data = {
            'user': user_project_role.user.uuid.__str__(),
            'team_role': settings.EXO_ROLE_CODE_SPRINT_PARTICIPANT
        }
        url = reverse('api:project-team-add-user',
                      kwargs={
                          'project_pk': self.project.pk,
                          'pk': team.pk
                      })
        self.setup_credentials(self.super_user)

        # DO ACTION
        response = self.client.post(url, data=data)

        # ASSERTS
        self.assertTrue(status.is_success(response.status_code))
        data = response.json()
        self.assertEqual(team.participants.count(), TOTAL_PARTICIPANTS + 1)
        self.assertEqual(team.members.count(), TOTAL_USERS + 1)
Ejemplo n.º 30
0
    def init_project(cls):
        head_coach_role = cls.project.project_roles.get(
            code=settings.EXO_ROLE_CODE_SPRINT_HEAD_COACH)
        coach_role = cls.project.project_roles.get(
            code=settings.EXO_ROLE_CODE_SPRINT_COACH)

        user_hc = cls.get_user(cls)
        request_mock_account.add_mock(user_hc,
                                      is_consultant=False,
                                      is_superuser=False)
        models.UserProjectRole.objects.create(project_role=head_coach_role,
                                              user=user_hc)
        user_coach = cls.get_user(cls)
        request_mock_account.add_mock(user_coach,
                                      is_consultant=False,
                                      is_superuser=False)
        models.UserProjectRole.objects.create(project_role=coach_role,
                                              teams=cls.project.teams.all(),
                                              user=user_coach)
        users_participants = []
        for team in cls.project.teams.all():
            user_role = models.UserProjectRole.objects.create_participant(
                project=cls.project,
                teams=[team],
                name=faker.name(),
                email=faker.email())
            request_mock_account.add_mock(user_role.user,
                                          is_consultant=False,
                                          is_superuser=False)
            users_participants.append(user_role.user)
        cls.user_coach = user_coach
        cls.user_hc = user_hc
        cls.users_participants = users_participants