예제 #1
0
    def process_pages(self, pages, dry_run):
        num_rates = 0
        num_pages = 0
        progress_bar = None

        try:
            for rates, total_pages in pages:
                if progress_bar is None:
                    progress_bar = tqdm(total=total_pages)
                serializer = ContractSerializer(data=rates, many=True)
                if serializer.is_valid():
                    num_rates += len(rates)
                    if not dry_run:
                        serializer.save()
                else:
                    rates_with_errors = [
                        (r, e) for r, e in zip(rates, serializer.errors)
                        if e
                    ]
                    for rate, error in rates_with_errors:
                        self.stderr.write(
                            f"Rate {self.style.WARNING(rate)} has "
                            f"error {self.style.ERROR(error)}!"
                        )
                progress_bar.update(1)
                num_pages += 1
        finally:
            if progress_bar is not None:
                progress_bar.close()

        return num_rates, num_pages
예제 #2
0
    def test_update_initial_carryover_minutes_updates_reports(
        self,
        contract_ending_in_april,
        shift_contract_ending_in_april,
        plain_request_object,
    ):
        """
        Test wether the serializers update method also updates the Reports when we change the initial_carryover_minutes.
        :param contract_ending_in_april:
        :param shift_contract_ending_in_april:
        :return:
        """
        assert Report.objects.get(
            contract=contract_ending_in_april,
            month_year=datetime.date(
                2019, 3, 1)).worktime == datetime.timedelta(hours=10)

        seri = ContractSerializer(
            instance=contract_ending_in_april,
            data={"initial_carryover_minutes": 600},
            partial=True,
            context={"request": plain_request_object},
        )
        seri.is_valid(raise_exception=True)
        seri.save()

        assert Report.objects.get(
            contract=contract_ending_in_april,
            month_year=datetime.date(
                2019, 3, 1)).worktime == datetime.timedelta(hours=15)
예제 #3
0
 def test_search_index_is_updated(self):
     rates = [{
         'idv_piid': 'GS-123-4567',
         'vendor_name': 'Blarg Inc.',
         'labor_category': 'Software Engineer',
         'education_level': 'Bachelors',
         'min_years_experience': 2,
         'current_price': 100,
         'hourly_rate_year1': 100
     }]
     serializer = ContractSerializer(data=rates, many=True)
     if not serializer.is_valid():
         raise AssertionError(serializer.errors)
     serializer.save()
     results = Contract.objects.all().multi_phrase_search('engineer').all()
     self.assertEqual([r.labor_category for r in results], ['Software Engineer'])
예제 #4
0
 def test_search_index_is_updated(self):
     rates = [{
         'idv_piid': 'GS-123-4567',
         'vendor_name': 'Blarg Inc.',
         'labor_category': 'Software Engineer',
         'education_level': 'Bachelors',
         'min_years_experience': 2,
         'current_price': 100,
         'hourly_rate_year1': 100
     }]
     serializer = ContractSerializer(data=rates, many=True)
     if not serializer.is_valid():
         raise AssertionError(serializer.errors)
     serializer.save()
     results = Contract.objects.multi_phrase_search('engineer').all()
     self.assertEqual([r.labor_category for r in results],
                      ['Software Engineer'])
예제 #5
0
    def test_update_carryover_target_date_recreates_reports(
        self,
        contract_ending_in_april,
        shift_contract_ending_in_april,
        plain_request_object,
    ):
        """
        Test wether the serializers update method deletes existing reports and recreates them when
        the carryover_target_date is updated.
        :param contract_ending_in_april:
        :param shift_contract_ending_in_april:
        :return:
        """

        assert Report.objects.filter(
            contract=contract_ending_in_april).count() == 1
        old_report_pk = Report.objects.filter(
            contract=contract_ending_in_april)[0].pk
        seri = ContractSerializer(
            instance=contract_ending_in_april,
            data={"carryover_target_date": datetime.date(2019, 2, 1)},
            partial=True,
            context={"request": plain_request_object},
        )
        seri.is_valid(raise_exception=True)
        seri.save()

        assert Report.objects.filter(
            contract=contract_ending_in_april).count() == 2
        assert not Report.objects.filter(pk=old_report_pk).exists()
        assert Report.objects.get(
            contract=contract_ending_in_april,
            month_year=datetime.date(
                2019, 2, 1)).worktime == datetime.timedelta(hours=5)
        assert Report.objects.get(
            contract=contract_ending_in_april,
            month_year=datetime.date(
                2019, 3, 1)).worktime == datetime.timedelta(hours=-10)