Ejemplo n.º 1
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)
Ejemplo n.º 2
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
Ejemplo n.º 3
0
 def test_update_carryover_and_target_date_correct_evaluated(
     self,
     user_object,
     contract_ending_in_april,
     shift_contract_ending_in_april,
     plain_request_object,
 ):
     """
     By the tests 'test_update_carryover_target_date_recreates_reports' and
     'test_update_initial_carryover_minutes_updates_reports' we allready checked that PATCH'ing
     (parital updates) works. In order to not bother checking the Reports etc. for PUT'ing
     we just test the logic which determines whether or not either carryover_target_date and/or
     initial_carryover_minutes change (see update method of ContractSerializer).
     :param contract_ending_in_april:
     :param shift_contract_ending_in_april:
     :param plain_request_object:
     :return:
     """
     data = {
         "name": "Test Contract1",
         "minutes": 1200,
         "start_date": datetime.date(2019, 1, 1),
         "end_date": datetime.date(2019, 4, 30),
         "user": str(user_object.id),
         "created_by": str(user_object.id),
         "modified_by": str(user_object.id),
         "created_at": contract_ending_in_april.created_at,
         "modified_at": contract_ending_in_april.modified_at,
         "carryover_target_date": datetime.date(2019, 2, 1),
         "initial_carryover_minutes": 600,
     }
     seri = ContractSerializer(
         instance=contract_ending_in_april,
         data=data,
         context={"request": plain_request_object},
     )
     seri.is_valid()
     validated_data = seri.validated_data
     carryover_target_date_changed = (
         validated_data.get("carryover_target_date") !=
         contract_ending_in_april.carryover_target_date)
     initial_carryover_minutes_changed = (
         validated_data.get("initial_carryover_minutes") !=
         contract_ending_in_april.initial_carryover_minutes)
     assert carryover_target_date_changed
     assert initial_carryover_minutes_changed
Ejemplo n.º 4
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)
Ejemplo n.º 5
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'])
Ejemplo n.º 6
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'])