Ejemplo n.º 1
0
    def test_edit_contracting_data(self):
        # PREPARE DATA
        consultant = FakeConsultantFactory.create(
            status=settings.CONSULTANT_STATUS_CH_ACTIVE)
        contracting_data = ContractingData.objects.create(
            profile=consultant.exo_profile,
            name=faker.name(),
            address=faker.address(),
            company_name=faker.company(),
        )
        url = reverse(
            'api:accounts:user-contracting-data',
            kwargs={'uuid': consultant.user.uuid.__str__()})

        new_data = {
            'name': faker.name(),
            'address': faker.address(),
            'company_name': faker.company(),
            'tax_id': '2522',
        }

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

        # ASSERTS
        contracting_data.refresh_from_db()
        self.assertTrue(status.is_success(response.status_code))
        self.assertEqual(contracting_data.name, new_data['name'])
Ejemplo n.º 2
0
 def test_change_contracting(self):
     consultant = FakeConsultantFactory.create()
     ContractingData.objects.create(
         profile=consultant.exo_profile,
         name=faker.name(),
         address=faker.address(),
         company_name=faker.company(),
     )
     self.client.login(
         username=self.super_user.username,
         password='******',
     )
     url = reverse(
         'api:profile:change-contracting',
         kwargs={'pk': consultant.user.pk},
     )
     data = {
         'name': faker.name(),
         'address': faker.address(),
         'company_name': faker.company(),
     }
     response = self.client.put(url, data=data, format='json')
     self.assertTrue(status.is_success(response.status_code))
     self.assertTrue(
         consultant.exo_profile.contracting_data.name,
         data['name'],
     )
     self.assertEqual(ContractingData.objects.count(), 1)
 def create_opportunity(self, user):
     data = {
         'title':
         faker.word(),
         'description':
         faker.text(),
         'location':
         '{}, {}'.format(faker.city(), faker.country()),
         'exo_role':
         ExoRole.objects.get(code=COACH),
         'certification_required':
         CertificationRole.objects.get(code=CERT_COACH),
         'start_date':
         timezone.now() + timedelta(days=10),
         'duration':
         '1 week',
         'keywords': [],
         'entity':
         faker.company(),
         'questions': [{
             'title': faker.word()
         }]
     }
     opportunity = Opportunity.objects.create_opportunity(user, **data)
     return opportunity
Ejemplo n.º 4
0
    def test_edit_project(self, mock_request, mock_email):
        # PREPARE DATA
        self.project.refresh_from_db()
        self.init_mock(mock_request)
        coach_role = self.project.project_roles.get(
            code=settings.EXO_ROLE_CODE_SPRINT_COACH)

        user = self.get_user()
        request_mock_account.add_mock(user,
                                      is_consultant=False,
                                      is_superuser=False)
        models.UserProjectRole.objects.create(project_role=coach_role,
                                              user=user)
        self.project.set_status(self.project.created_by,
                                settings.PROJECT_CH_STATUS_WAITING)
        mock_email.reset_mock()
        url = reverse('api:project-detail', kwargs={'pk': self.project.pk})

        # DO ACTION
        self.setup_credentials(self.super_user)
        data = {
            'name': faker.word(),
            'customer': faker.company(),
            'location': '{}, {}'.format(faker.city(), faker.country()),
            'place_id': faker.pyint(),
            'start':
            (self.project.start + timedelta(days=5)).strftime('%Y-%m-%d'),
        }
        response = self.client.put(url, data=data)

        # ASSERTS
        self.assertTrue(status.is_success(response.status_code))
        self.assertTrue(mock_email.called)
        self.assertEqual(mock_email.call_count, 2)
Ejemplo n.º 5
0
class FakeOpportunityGroupFactory(factory.django.DjangoModelFactory):
    total = 1
    entity = factory.LazyAttribute(lambda x: faker.company())
    origin = 'T'
    duration_unity = factory.fuzzy.FuzzyChoice(
        dict(settings.OPPORTUNITIES_DURATION_UNITY_CHOICES).keys(), )
    duration_value = faker.random_digit_not_null()
    exo_role = factory.Iterator(ExORole.objects.all())

    class Meta:
        model = OpportunityGroup
Ejemplo n.º 6
0
class FakeOpportunityFactory(factory.django.DjangoModelFactory):

    title = factory.LazyAttribute(lambda x: faker.text(max_nb_chars=20))
    description = factory.LazyAttribute(lambda x: faker.text())
    location = factory.LazyAttribute(
        lambda x: '{}, {}'.format(faker.city(), faker.country()))
    exo_role = factory.LazyAttribute(lambda o: ExORole.objects.get(
        code=settings.EXO_ROLE_CODE_SPRINT_COACH))
    certification_required = factory.LazyAttribute(
        lambda o: CertificationRole.objects.get(
            code=settings.EXO_ROLE_CODE_CERTIFICATION_SPRINT_COACH))
    start_date = factory.fuzzy.FuzzyDate(datetime.date.today())
    deadline_date = factory.fuzzy.FuzzyDate(datetime.date.today())
    duration_unity = factory.fuzzy.FuzzyChoice(
        dict(settings.OPPORTUNITIES_DURATION_UNITY_CHOICES).keys(), )
    duration_value = faker.random_digit_not_null()
    entity = factory.LazyAttribute(lambda x: faker.company())
    keywords = []
    languages = []
    budget = factory.LazyAttribute(lambda x: faker.pyint())
    budget_currency = settings.OPPORTUNITIES_CH_CURRENCY_DOLLAR
    virtual_budget = factory.LazyAttribute(lambda x: faker.pyint())
    virtual_budget_currency = settings.OPPORTUNITIES_CH_CURRENCY_EXOS

    class Meta:
        model = Opportunity

    @classmethod
    def _create(cls, model_class, *args, **kwargs):
        """Override the default ``_create`` with our custom call."""
        manager = cls._get_manager(model_class)

        if not kwargs.get('user_from'):
            raise Exception('User is required')

        # The default would use ``manager.create(*args, **kwargs)``
        budgets = []

        if kwargs.get('budget'):
            budgets.append({
                'budget': kwargs.get('budget'),
                'currency': kwargs.get('budget_currency')
            })

        if kwargs.get('virtual_budget'):
            budgets.append({
                'budget': kwargs.get('virtual_budget').__str__(),
                'currency': kwargs.get('virtual_budget_currency')
            })

        kwargs['budgets'] = budgets

        return manager.create_opportunity(*args, **kwargs)
Ejemplo n.º 7
0
    def test_create_request_api(self, mock_request):
        # PREPARE DATA
        self.init_mock(mock_request)
        self.setup_credentials(self.super_user)

        keywords = [
            {'name': faker.word() + faker.numerify()},
            {'name': faker.word() + faker.numerify()},
        ]
        data = {
            'title': faker.word(),
            'description': faker.text(),
            'mode': settings.OPPORTUNITIES_CH_MODE_ONSITE,
            'location': '{}, {}'.format(faker.city(), faker.country()),
            'exo_role': ExORole.objects.get(code=COACH).code,
            'certification_required': CertificationRole.objects.get(code=CERT_COACH).code,
            'start_date': timezone.now().date(),
            'duration_unity': settings.OPPORTUNITIES_DURATION_UNITY_DAY,
            'duration_value': 2,
            'keywords': keywords,
            'entity': faker.company(),
            'budget': 222,
            'budget_currency': settings.OPPORTUNITIES_CH_CURRENCY_EUR,
            'virtual_budget': 222.55,
            'questions': [
                {
                    'title': faker.text(),
                },
                {
                    'title': faker.text(),
                }
            ]
        }
        url = reverse('api:opportunity-list')

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

        # ASSERTS
        self.assertTrue(status.is_success(response.status_code))
        opportunity = models.Opportunity.objects.get(
            pk=response_data['pk'])
        self.assertEqual(
            opportunity.questions.count(),
            2
        )
        self.assertTrue(
            models.Question.objects.filter(
                type_question=settings.OPPORTUNITIES_QUESTION_CH_TYPE_DEFAULT
            ).exists()
        )
Ejemplo n.º 8
0
 def get_api_data(self, users=[]):
     keywords = [
         {'name': faker.word() + faker.numerify()},
         {'name': faker.word() + faker.numerify()},
     ]
     data = {
         'title': faker.word(),
         'description': faker.text(),
         'mode': settings.OPPORTUNITIES_CH_MODE_ONSITE,
         'location': '{}, {}'.format(faker.city(), faker.country()),
         'exo_role': ExORole.objects.get(code=settings.EXO_ROLE_CODE_OTHER_OTHER).code,
         'other_category_name': faker.word(),
         'other_role_name': faker.word(),
         'certification_required': None,
         'due_date': timezone.now().date(),
         'deadline_date': (timezone.now() + timedelta(days=10)).date(),
         'duration_unity': settings.OPPORTUNITIES_DURATION_UNITY_DAY,
         'duration_value': 2,
         'num_positions': 2,
         'keywords': keywords,
         'entity': faker.company(),
         'files': [{
             'filestack_status': 'Stored',
             'url': 'https://cdn.filestackcontent.com/Lr59QG8oQRWliC6x70cx',
             'filename': 'gato.jpg',
             'mimetype': 'image/jpeg'}],
         'budgets': [
             {
                 'currency': settings.OPPORTUNITIES_CH_CURRENCY_EUR,
                 'budget': '{}.0'.format(int(faker.numerify()))
             },
             {
                 'currency': settings.OPPORTUNITIES_CH_CURRENCY_EXOS,
                 'budget': '{}.0'.format(int(faker.numerify()))
             },
         ]
     }
     if users:
         data['target'] = settings.OPPORTUNITIES_CH_TARGET_FIXED
         data['users_tagged'] = [
             {'user': user.uuid.__str__()} for user in users
         ]
     return data
Ejemplo n.º 9
0
    def test_contracting_data(self):
        # PREPARE DATA
        consultant = FakeConsultantFactory.create(
            status=settings.CONSULTANT_STATUS_CH_ACTIVE)
        ContractingData.objects.create(
            profile=consultant.exo_profile,
            name=faker.name(),
            address=faker.address(),
            company_name=faker.company(),
        )
        url = reverse(
            'api:accounts:user-contracting-data',
            kwargs={'uuid': consultant.user.uuid.__str__()})

        # DO ACTION
        response = self.client.get(url, HTTP_USERNAME=settings.AUTH_SECRET_KEY)

        # ASSERTS
        data = response.json()
        self.assertTrue(status.is_success(response.status_code))
        self.assertIsNotNone(data['name'])
Ejemplo n.º 10
0
    def test_contracting_data_ok_filled(self):
        # PREPARE DATA
        consultant = FakeConsultantFactory.create(user__password='******')
        contracting_data = ContractingData.objects.create(
            profile=consultant.exo_profile,
            name=faker.name(),
            address=faker.address(),
            company_name=faker.company(),
        )
        data = {'username': consultant.user.email, 'password': '******'}
        url = reverse('api:accounts:public-contracting-data')

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

        # ASSERTS
        self.assertTrue(status.is_success(response.status_code))
        data = response.json()
        self.assertEqual(data['fullName'], consultant.user.full_name)
        self.assertEqual(data['contractingData']['name'],
                         contracting_data.name)
Ejemplo n.º 11
0
class FakeProjectFactory(django.DjangoModelFactory):
    class Meta:
        model = Project

    uuid = factory.LazyAttribute(lambda x: faker.uuid4())
    name = factory.LazyAttribute(lambda x: faker.word())
    description = factory.LazyAttribute(lambda x: faker.text())
    start = factory.LazyAttribute(
        lambda x: faker.date_time(tzinfo=string_to_timezone('utc')))
    location = factory.LazyAttribute(
        lambda x: '{}, {}'.format(faker.city(), faker.country()))
    status = settings.PROJECT_CH_STATUS_DRAFT
    content_template = settings.PROJECT_CH_PROJECT_TEMPLATE_DEFAULT
    customer = factory.LazyAttribute(lambda x: faker.company())

    @classmethod
    def _create(cls, model_class, *args, **kwargs):
        """Override the default ``_create`` with our custom call."""
        manager = cls._get_manager(model_class)
        if not kwargs.get('created_by'):
            raise Exception('User is required')
        return manager.create_project(*args, **kwargs)