def test_apply_opportunity_with_questions_should_validate_all_answered(
            self, mock_request):

        # PREPARE DATA
        self.init_mock(mock_request)
        opp = self.create_opportunity(questions=3)
        user = self.get_user()
        request_mock_account.add_mock(user,
                                      is_consultant=True,
                                      is_superuser=False)
        self.setup_credentials(user)
        self.add_marketplace_permission(user)
        url = reverse('api:opportunity-apply', kwargs={'pk': opp.pk})

        test_cases = [
            {
                'questions_answered': [],
                'status': status.HTTP_400_BAD_REQUEST
            },
            {
                'questions_answered': [{
                    'response': str(faker.boolean()),
                    'question': question.pk,
                } for question in opp.questions.all()[0:1]],
                'status':
                status.HTTP_400_BAD_REQUEST
            },
            {
                'questions_answered': [{
                    'response': str(faker.boolean()),
                    'question': question.pk,
                } for question in opp.questions.all()],
                'status':
                status.HTTP_200_OK
            },
        ]

        for test_case in test_cases:
            # DO ACTION
            answers = test_case.get('questions_answered')
            expected_response_status = test_case.get('status')
            response = self.client.post(url,
                                        data={
                                            'comment': faker.text(),
                                            'questions_extra_info':
                                            faker.text(),
                                            'budget': faker.text(),
                                            'answers': answers,
                                        })

            # ASSERTS
            self.assertEqual(response.status_code, expected_response_status)
 def get_mock_data(self, optional=True):
     answers = [{
         'question': faker.text(),
         'response': faker.boolean(),
         'response_text': ['Yes', 'No'][random.randint(0, 1)]
     } for _ in range(random.randint(0, 2))]
     mock_data = {
         'title':
         '[Role] for [Project Name]',
         'applicant_name':
         '[EM Name]',
         'applicant_profile_picture':
         faker.image_url(settings.DEFAULT_IMAGE_SIZE,
                         settings.DEFAULT_IMAGE_SIZE),
         'applicant_role':
         '[Applicant User Title]',
         'summary':
         '[Comment]',
         'questions_extra_info':
         '[Extra info from Consultant]',
         'applicant_email':
         '[email]',
         'applicant_profile_url':
         '/{}'.format(faker.uri_path()),
         'disable_notification_url':
         None,
         'public_url':
         '/{}'.format(faker.uri_path()),
         'answers':
         answers,
     }
     return mock_data
Exemplo n.º 3
0
    def test_apply_opportunity_with_questions(self, mock_request):

        # PREPARE DATA
        self.init_mock(mock_request)
        NUM_QUESTIONS = 3
        opp = self.create_opportunity(questions=NUM_QUESTIONS)
        user = self.get_user()
        request_mock_account.add_mock(user,
                                      is_consultant=True,
                                      is_superuser=False)

        answers_responses = [{
            'response': str(faker.boolean()).lower(),
            'question': question,
        } for question in opp.questions.all()]

        # DO ACTION
        Applicant.objects.create_open_applicant(
            user_from=user,
            user=user,
            opportunity=opp,
            summary=faker.text(),
            budget=faker.text(),
            questions_extra_info=faker.word(),
            answers=answers_responses)

        # ASSERTS
        opp.refresh_from_db()
        self.assertTrue(opp.is_requested)
        self.assertEqual(opp.applicants_info.count(), 1)
        self.assertIsNotNone(opp.applicants_info.first().budget)
        self.assertIsNotNone(opp.applicants_info.first().summary)
        self.assertIsNotNone(opp.applicants_info.first().questions_extra_info)
        self.assertEqual(opp.applicants_info.first().answers.count(),
                         NUM_QUESTIONS)
 def get_mock_data(self, optional=True):
     mock_data = {
         'user_name': '[[Consultant Short Name]]',
         'public_url': '/' + faker.uri_path(),
         'user_in_waiting_list': faker.boolean()
     }
     return mock_data
    def test_apply_opportunity_with_questions(self, mock_request):

        # PREPARE DATA
        self.init_mock(mock_request)
        NUM_QUESTIONS = 3
        opp = self.create_opportunity(questions=NUM_QUESTIONS)
        user = self.get_user()
        request_mock_account.add_mock(user,
                                      is_consultant=True,
                                      is_superuser=False)
        self.setup_credentials(user)
        self.add_marketplace_permission(user)
        url = reverse('api:opportunity-apply', kwargs={'pk': opp.pk})

        answers_responses = [{
            'response': str(faker.boolean()).lower(),
            'question': question.pk,
        } for question in opp.questions.all()]

        # DO ACTION
        response = self.client.post(url,
                                    data={
                                        'comment': faker.text(),
                                        'questions_extra_info': faker.text(),
                                        'budget': faker.text(),
                                        'answers': answers_responses,
                                    })

        # ASSERTS
        self.assertTrue(status.is_success(response.status_code))
Exemplo n.º 6
0
    def test_create_participants_api(self, mock_request):
        # PREPARE DATA
        self.init_mock(mock_request)
        self.setup_credentials(self.consultant_user)

        data = {
            'title':
            faker.sentence(),
            'sub_title':
            faker.sentence(),
            'description':
            faker.text(),
            'start':
            timezone.now().date(),
            'end':
            timezone.now().date(),
            'category':
            settings.EXO_ROLE_CATEGORY_OTHER,
            'follow_type':
            'P',
            'location':
            '{}, {}'.format(faker.city(), faker.country()),
            'url':
            faker.uri(),
            'languages': [faker.word()],
            'show_price':
            faker.boolean(),
            'amount':
            faker.numerify(),
            'currency': [*dict(settings.EVENT_CURRENCY_CHOICES).keys()
                         ][random.randint(0, 1)],
            'organizers': [
                {
                    'name': faker.name(),
                    'email': faker.email(),
                    'url': faker.uri()
                },
            ],
            'participants': [{
                'uuid': self.consultant_user.uuid.__str__(),
                'exo_role': settings.EXO_ROLE_CODE_OTHER_SPEAKER,
                'order': 1,
            }]
        }

        url = reverse('api:event:api-root')

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

        # ASSERTS
        event = Event.objects.first()
        self.assertTrue(status.is_success(response.status_code))
        self.assertEqual(event.participants.count(), 1)
Exemplo n.º 7
0
    def get_mock_data(self, optional=True):
        mock_data = super().get_mock_data()

        mock_data.update({
            'short_name': '[Shot name]',
            'location': '[Project location]',
            'timezone_name': 'Europe/Madrid',
            'timezone_utc': '+1.00',
            'start_at': '2017-08-03T10:00:00.000000',
            'public_url': '/{}'.format(faker.uri_path()),
            'one_day': faker.boolean(),
            'disable_notification_url': '/{}'.format(faker.uri_path()),
        })
        return mock_data
Exemplo n.º 8
0
    def test_workshop_reminder_email(self, mock_notify_manager_task, mock_task,
                                     mock_request):
        # PREPARE DATA
        self.init_mock(mock_request)
        data = {
            'title':
            faker.sentence(),
            'sub_title':
            faker.sentence(),
            'description':
            faker.text(),
            'start':
            timezone.now().date(),
            'end':
            timezone.now().date(),
            'category':
            Category.objects.get(code=settings.EXO_ROLE_CATEGORY_WORKSHOP),
            'follow_type':
            settings.EVENT_CH_FOLLOW_MODE_DEFAULT,
            'location':
            '{}, {}'.format(faker.city(), faker.country()),
            'url':
            faker.uri(),
            'languages': [faker.word()],
            'show_price':
            faker.boolean(),
            'amount':
            faker.numerify(),
            'currency':
            settings.EVENT_CH_CURRENCY_EUR,
            'organizers': [
                {
                    'name': faker.name(),
                    'email': faker.email(),
                    'url': faker.uri()
                },
            ],
            'participants': [],
            'user_from':
            self.super_user,
        }

        # DO ACTION
        Event.objects.create_event(force_retrieve_user_data=True, **data)

        # ASSERTS
        self.assertTrue(mock_task.called)
    def get_mock_data(self, optional=True):
        mock_data = super().get_mock_data()

        mock_data.update({
            'name': faker.name(),
            'email': faker.email(),
            'company': '[company]',
            'position': '[position]',
            'participant': '[participant]',
            'motivation': '[motivation]',
            'employees': '[employees]',
            'initiatives': '[initiatives]',
            'goal': '[goal]',
            'book': faker.boolean(),
            'comment': '[comment]',
        })
        return mock_data
Exemplo n.º 10
0
class FakeAnswerFactory(factory.django.DjangoModelFactory):

    response = factory.LazyAttribute(lambda x: faker.boolean())

    class Meta:
        model = Answer