Пример #1
0
 def test_process_indicators_wbs_found(self):
     """Check that update happens if result wbs differs and found"""
     result_old = ResultFactory(
         result_type=self.result_type_output,
         wbs="1234/56/78/90A/EFG"
     )
     result_new = ResultFactory(
         result_type=self.result_type_output,
         wbs="1234/56/78/90A/BCD"
     )
     indicator = IndicatorFactory(
         code="WBS",
         name="NAME",
         baseline="BLINE",
         target="Target",
         result=result_old
     )
     response = self.adapter.process_indicators([self.data])
     self.assertEqual(response, {
         "details": "Created Skipped 0\n"
         "Updated Skipped 0\n"
         "Created 0\n"
         "Indicators Updated to Active 0\n"
         "Indicators Updated to Inactive 0\n"
         "Updated 1",
         "total_records": 1,
         "processed": 1
     })
     indicator_updated = Indicator.objects.get(pk=indicator.pk)
     self.assertEqual(indicator_updated.result, result_new)
Пример #2
0
    def test_no_issue(self):
        """Check that valida interventions results in no issue"""
        qs_issue = FlaggedIssue.objects.filter(issue_id="pd_outputs_wrong")
        start_date = datetime.date(2001, 1, 1)
        end_date = datetime.date(2001, 12, 31)
        country = CountryProgrammeFactory(
            from_date=start_date,
            to_date=end_date,
        )
        intervention = InterventionFactory(
            country_programme=country,
            start=start_date,
        )
        result = ResultFactory(country_programme=country)
        InterventionResultLink.objects.create(
            intervention=intervention,
            cp_output=result,
        )
        self.assertEqual(intervention.country_programme,
                         result.country_programme)

        self.assertFalse(qs_issue.exists())
        checks.bootstrap_checks(default_is_active=True)
        checks.run_all_checks()
        self.assertFalse(qs_issue.exists())
Пример #3
0
    def test_issue_found(self):
        """Check that is country programme for intervention does not
        match result country programme then issue is created"""
        qs_issue = FlaggedIssue.objects.filter(issue_id="pd_outputs_wrong")
        start_date = datetime.date(2001, 1, 1)
        end_date = datetime.date(2001, 12, 31)
        country = CountryProgrammeFactory(
            from_date=start_date,
            to_date=end_date,
        )
        intervention = InterventionFactory(
            country_programme=country,
            start=start_date,
        )
        result = ResultFactory(country_programme=CountryProgrammeFactory())
        InterventionResultLink.objects.create(
            intervention=intervention,
            cp_output=result,
        )
        self.assertNotEqual(intervention.country_programme,
                            result.country_programme)

        self.assertFalse(qs_issue.exists())
        checks.bootstrap_checks(default_is_active=True)
        checks.run_all_checks()
        self.assertTrue(qs_issue.exists())
        issue = qs_issue.first()
        self.assertIn("has wrongly mapped outputs", issue.message)
Пример #4
0
 def test_update_changes(self):
     """Check it remote differs to local"""
     remote = {"name": "Change"}
     result = ResultFactory(name="New")
     self.assertTrue(self.adapter._update_changes(result, remote))
     self.assertEqual(result.name, remote["name"])
     self.assertFalse(self.adapter._update_changes(result, remote))
Пример #5
0
 def test_prp_api_performance(self):
     EXPECTED_QUERIES = 23
     with self.assertNumQueries(EXPECTED_QUERIES):
         self.run_prp_v1(
             user=self.unicef_staff, method='get'
         )
     # make a bunch more stuff, make sure queries don't go up.
     intervention = InterventionFactory(agreement=self.agreement, title='New Intervention')
     result = ResultFactory(name='Another Result')
     result_link = InterventionResultLink.objects.create(
         intervention=intervention, cp_output=result)
     lower_result = LowerResult.objects.create(result_link=result_link, name='Lower Result 1')
     indicator_blueprint = IndicatorBlueprint.objects.create(
         title='The Blueprint'
     )
     applied_indicator = AppliedIndicator.objects.create(
         indicator=indicator_blueprint,
         lower_result=lower_result,
     )
     applied_indicator.locations.add(LocationFactory(name='A Location',
                                                     gateway=GatewayTypeFactory(name='Another Gateway'),
                                                     p_code='a-p-code'))
     applied_indicator.disaggregation.create(name='Another Disaggregation')
     with self.assertNumQueries(EXPECTED_QUERIES):
         self.run_prp_v1(
             user=self.unicef_staff, method='get'
         )
Пример #6
0
 def test_process_indicators_wbs_not_found(self):
     """Check that NO update happens if result wbs differs and NOT found
     update is skipped
     """
     result = ResultFactory(
         result_type=self.result_type_output,
         wbs="1234/56/78/90A/EFG"
     )
     IndicatorFactory(
         code="WBS",
         name="NAME",
         baseline="BLINE",
         target="Target",
         result=result
     )
     response = self.adapter.process_indicators([self.data])
     self.assertEqual(response, {
         "details": "Created Skipped 0\n"
         "Updated Skipped 1\n"
         "Created 0\n"
         "Indicators Updated to Active 0\n"
         "Indicators Updated to Inactive 0\n"
         "Updated 0",
         "total_records": 1,
         "processed": 0
     })
     result_updated = Result.objects.get(pk=result.pk)
     self.assertEqual(result_updated.wbs, result.wbs)
Пример #7
0
    def test_filtering_options(self):
        t1 = TravelFactory(traveler=self.traveler, supervisor=self.unicef_staff)
        a1 = TravelActivityFactory(travel_type=TravelType.MEETING, primary_traveler=self.unicef_staff)
        a1.travels.add(t1)

        result = ResultFactory()
        t2 = TravelFactory(traveler=self.traveler, supervisor=self.unicef_staff)
        a2 = TravelActivityFactory(
            travel_type=TravelType.PROGRAMME_MONITORING,
            primary_traveler=self.unicef_staff,
            result=result
        )
        a2.travels.add(t2)

        data = {
            'f_travel_type': TravelType.PROGRAMME_MONITORING,
            'f_month': t2.start_date.month - 1,  # Frontend sends 0-11
            'f_cp_output': result.id,
        }
        response = self.forced_auth_req('get', reverse('t2f:travels:list:index'),
                                        data=data, user=self.unicef_staff)

        response_json = json.loads(response.rendered_content)
        self.assertIn('data', response_json)
        self.assertEqual(len(response_json['data']), 1)
        self.assertEqual(response_json['data'][0]['id'], t2.id)
Пример #8
0
    def test_no_interventions(self):
        """If intervention does not fit in with Country Programmes
        then no issues raised
        """
        qs_issue = FlaggedIssue.objects.filter(issue_id="pd_outputs_wrong")
        start_date = datetime.date(2001, 1, 1)
        end_date = datetime.date(2001, 12, 31)
        country = CountryProgrammeFactory(
            from_date=start_date,
            to_date=end_date,
        )
        intervention = InterventionFactory(
            country_programme=country,
            start=start_date - datetime.timedelta(days=1),
        )
        result = ResultFactory(country_programme=CountryProgrammeFactory())
        InterventionResultLink.objects.create(
            intervention=intervention,
            cp_output=result,
        )
        self.assertNotEqual(intervention.country_programme,
                            result.country_programme)

        self.assertFalse(qs_issue.exists())
        checks.bootstrap_checks(default_is_active=True)
        checks.run_all_checks()
        self.assertFalse(qs_issue.exists())
Пример #9
0
    def setUpTestData(cls):
        cls.user = UserFactory(is_staff=True)  # UNICEF staff user
        cls.result_type = ResultTypeFactory(name=ResultType.OUTPUT)

        today = datetime.date.today()
        cls.country_programme = CountryProgrammeFactory(
            wbs='0000/A0/01',
            from_date=datetime.date(today.year - 1, 1, 1),
            to_date=datetime.date(today.year + 1, 1, 1))

        cls.result1 = ResultFactory(
            result_type=cls.result_type,
            country_programme=cls.country_programme,
        )

        cls.result2 = ResultFactory(result_type=cls.result_type,
                                    country_programme=cls.country_programme)
        cls.url = reverse('report-result-detail', args=[cls.result1.pk])
Пример #10
0
    def setUpTestData(cls):
        for name, _ in ResultType.NAME_CHOICES:
            ResultTypeFactory(name=name)
        cls.user = UserFactory(is_staff=True)  # UNICEF staff user
        cls.result_type = ResultType.objects.get(name=ResultType.OUTPUT)

        today = datetime.date.today()
        cls.country_programme = CountryProgrammeFactory(
            wbs='0000/A0/01',
            from_date=datetime.date(today.year - 1, 1, 1),
            to_date=datetime.date(today.year + 1, 1, 1))

        cls.result1 = ResultFactory(
            result_type=cls.result_type,
            country_programme=cls.country_programme,
        )

        cls.result2 = ResultFactory(result_type=cls.result_type,
                                    country_programme=cls.country_programme)
        cls.v2_results_url = reverse('report-result-list')
Пример #11
0
 def test_update_all_exist(self):
     """Check response from all update which is a wrapper method
     that calls;
     - update_cps
     - update_outcomes
     - update_outputs
     - update_activities
     """
     CountryProgrammeFactory(name="New CP", wbs="C1")
     ResultFactory(
         name="New Outcome",
         wbs="R1",
         result_type=self.result_type_outcome
     )
     ResultFactory(
         name="New Output",
         wbs="R2",
         result_type=self.result_type_output
     )
     ResultFactory(
         name="New Activity",
         wbs="R3",
         result_type=self.result_type_activity
     )
     self.data["cps"] = {"C1": {"name": "New CP"}}
     self.data["outcomes"] = {"R1": {"name": "New Outcome"}}
     self.data["outputs"] = {"R2": {"name": "New Output"}}
     self.data["activities"] = {"R3": {"name": "New Activity"}}
     self.adapter.data = self.data
     result = self.adapter.update()
     self.assertEqual(
         result["details"],
         "CPs updated: Total 1, Updated 0, New 0\n"
         "Outcomes updated: Total 1, Updated 0, New 0\n"
         "Outputs updated: Total 1, Updated 0, New 0\n"
         "Activities updated: Total 1, Updated 0, New 0"
     )
     self.assertEqual(result["total_records"], 4)
     self.assertEqual(result["processed"], 0)
Пример #12
0
 def test_update_activities_exists(self):
     """If Result (of type activity) exists with WBS value, and attributes
     have NOT changed then no update
     """
     ResultFactory(
         name="New",
         wbs="R1",
         result_type=self.result_type_activity
     )
     self.data["activities"] = {"R1": {"name": "New"}}
     self.adapter.data = self.data
     total_data, total_updated, length = self.adapter.update_activities()
     self.assertEqual(total_data, 1)
     self.assertEqual(total_updated, 0)
     self.assertEqual(length, 0)
Пример #13
0
 def test_update_activities_updated(self):
     """If Result (of type activity) exists with WBS value, and attributes
     have changed then update
     """
     result = ResultFactory(
         name="New",
         wbs="R1",
         result_type=self.result_type_activity
     )
     self.data["activities"] = {"R1": {"name": "Changed"}}
     self.adapter.data = self.data
     total_data, total_updated, length = self.adapter.update_activities()
     self.assertEqual(total_data, 1)
     self.assertEqual(total_updated, 1)
     self.assertEqual(length, 0)
     result_updated = Result.objects.get(pk=result.pk)
     self.assertEqual(result_updated.name, "Changed")
Пример #14
0
    def test_no_country_programme(self):
        """Check that if intervention has no country programme
        the intervention is ignored during the check
        """
        qs_issue = FlaggedIssue.objects.filter(issue_id="pd_outputs_wrong")
        intervention = InterventionFactory()
        result = ResultFactory(country_programme=CountryProgrammeFactory())
        InterventionResultLink.objects.create(
            intervention=intervention,
            cp_output=result,
        )
        self.assertIsNone(intervention.country_programme)
        self.assertNotEqual(intervention.country_programme,
                            result.country_programme)

        self.assertFalse(qs_issue.exists())
        checks.bootstrap_checks(default_is_active=True)
        checks.run_all_checks()
        self.assertFalse(qs_issue.exists())
Пример #15
0
 def test_process_indicators_create(self):
     """Check that indicator is created"""
     ResultFactory(
         result_type=self.result_type_output,
         wbs="1234/56/78/90A/BCD"
     )
     indicator_qs = Indicator.objects.filter(name="NAME")
     self.assertFalse(indicator_qs.exists())
     response = self.adapter.process_indicators([self.data])
     self.assertEqual(response, {
         "details": "Created Skipped 0\n"
         "Updated Skipped 0\n"
         "Created 1\n"
         "Indicators Updated to Active 0\n"
         "Indicators Updated to Inactive 0\n"
         "Updated 0",
         "total_records": 1,
         "processed": 1
     })
     self.assertTrue(indicator_qs.exists())
Пример #16
0
def setup_intervention_test_data(test_case,
                                 include_results_and_indicators=False):
    today = datetime.date.today()
    test_case.unicef_staff = UserFactory(is_staff=True)
    test_case.partnership_manager_user = UserFactory(is_staff=True)
    test_case.partnership_manager_user.groups.add(GroupFactory())
    test_case.partner = PartnerFactory(name='Partner 1', vendor_number="VP1")
    test_case.partner1 = PartnerFactory(name='Partner 2')
    test_case.agreement = AgreementFactory(
        partner=test_case.partner, signed_by_unicef_date=datetime.date.today())

    test_case.active_agreement = AgreementFactory(
        partner=test_case.partner1,
        status='active',
        signed_by_unicef_date=datetime.date.today(),
        signed_by_partner_date=datetime.date.today())

    test_case.intervention = InterventionFactory(agreement=test_case.agreement,
                                                 title='Intervention 1')
    test_case.intervention_2 = InterventionFactory(
        agreement=test_case.agreement,
        title='Intervention 2',
        document_type=Intervention.PD,
    )
    test_case.active_intervention = InterventionFactory(
        agreement=test_case.active_agreement,
        title='Active Intervention',
        document_type=Intervention.PD,
        start=today - datetime.timedelta(days=1),
        end=today + datetime.timedelta(days=90),
        status='active',
        signed_by_unicef_date=today - datetime.timedelta(days=1),
        signed_by_partner_date=today - datetime.timedelta(days=1),
        unicef_signatory=test_case.unicef_staff,
        partner_authorized_officer_signatory=test_case.partner1.staff_members.
        all().first())

    test_case.result_type = ResultType.objects.get_or_create(
        name=ResultType.OUTPUT)[0]
    test_case.result = ResultFactory(result_type=test_case.result_type)

    test_case.partnership_budget = InterventionBudget.objects.create(
        intervention=test_case.intervention,
        unicef_cash=10,
        unicef_cash_local=100,
        partner_contribution=20,
        partner_contribution_local=200,
        in_kind_amount_local=10,
    )

    # set up two frs not connected to any interventions
    test_case.fr_1 = FundsReservationHeaderFactory(intervention=None,
                                                   currency='USD')
    test_case.fr_2 = FundsReservationHeaderFactory(intervention=None,
                                                   currency='USD')

    if include_results_and_indicators:
        # setup additional inicator/results
        test_case.result = ResultFactory(name='A Result')
        test_case.result_link = InterventionResultLink.objects.create(
            intervention=test_case.active_intervention,
            cp_output=test_case.result)
        test_case.lower_result = LowerResult.objects.create(
            result_link=test_case.result_link, name='Lower Result 1')
        test_case.indicator_blueprint = IndicatorBlueprint.objects.create(
            title='The Blueprint')
        test_case.applied_indicator = AppliedIndicator.objects.create(
            indicator=test_case.indicator_blueprint,
            lower_result=test_case.lower_result,
        )
        test_case.applied_indicator.locations.add(
            LocationFactory(name='A Location',
                            gateway=GatewayTypeFactory(name='A Gateway'),
                            p_code='a-p-code'))
        test_case.disaggregation = test_case.applied_indicator.disaggregation.create(
            name='A Disaggregation')
Пример #17
0
 def setUpTestData(cls):
     cls.unicef_staff = UserFactory(is_staff=True)
     cls.result = ResultFactory()
     cls.indicator = IndicatorFactory(result=cls.result)
     cls.url = reverse("result-indicator-list", args=[cls.result.pk])
Пример #18
0
    def test_activity_export(self):
        office = OfficeFactory(name='Budapest')
        section_health = SectorFactory(name='Health')
        section_education = SectorFactory(name='Education')

        location_ABC = LocationFactory(name='Location ABC')
        location_345 = LocationFactory(name='Location 345')
        location_111 = LocationFactory(name='Location 111')

        partnership_A1 = InterventionFactory(title='Partnership A1')
        partner = partnership_A1.agreement.partner
        partner.name = 'Partner A'
        partner.save()

        partnership_A2 = InterventionFactory(title='Partnership A2')
        agreement = partnership_A2.agreement
        agreement.partner = partner
        agreement.save()

        partnership_B3 = InterventionFactory(title='Partnership B3')
        partner = partnership_B3.agreement.partner
        partner.name = 'Partner B'
        partner.save()

        partnership_C1 = InterventionFactory(title='Partnership C1')
        partner = partnership_C1.agreement.partner
        partner.name = 'Partner C'
        partner.save()

        # Some results
        result_A11 = ResultFactory(name='Result A11')
        result_A21 = ResultFactory(name='Result A21')

        # set up travels
        user_joe_smith = UserFactory(first_name='Joe', last_name='Smith')
        user_alice_carter = UserFactory(first_name='Alice', last_name='Carter')
        user_lenox_lewis = UserFactory(first_name='Lenox', last_name='Lewis')
        travel_1 = TravelFactory(
            reference_number='2016/1000',
            traveler=user_joe_smith,
            office=office,
            sector=section_health,
            start_date=datetime.strptime('08-Nov-2017', '%d-%b-%Y'),
            end_date=datetime.strptime('14-Nov-2017', '%d-%b-%Y'))
        travel_2 = TravelFactory(
            reference_number='2016/1211',
            traveler=user_alice_carter,
            office=office,
            sector=section_education,
            start_date=datetime.strptime('08-Nov-2017', '%d-%b-%Y'),
            end_date=datetime.strptime('14-Nov-2017', '%d-%b-%Y'))

        # Do some cleanup
        TravelActivity.objects.all().delete()

        # Create the activities finally
        activity_1 = TravelActivityFactory(
            travel_type=TravelType.PROGRAMME_MONITORING,
            date=datetime(2016, 12, 3, tzinfo=UTC),
            result=result_A11,
            primary_traveler=user_joe_smith)
        activity_1.travels.add(travel_1)
        activity_1.locations.set([location_ABC, location_345])
        activity_1.partner = partnership_A1.agreement.partner
        activity_1.partnership = partnership_A1
        activity_1.save()

        activity_2 = TravelActivityFactory(
            travel_type=TravelType.PROGRAMME_MONITORING,
            date=datetime(2016, 12, 4, tzinfo=UTC),
            result=result_A21,
            primary_traveler=user_lenox_lewis)
        activity_2.travels.add(travel_1)
        activity_2.locations.set([location_111])
        activity_2.partner = partnership_A2.agreement.partner
        activity_2.partnership = partnership_A2
        activity_2.save()

        activity_3 = TravelActivityFactory(travel_type=TravelType.MEETING,
                                           date=datetime(2016,
                                                         12,
                                                         3,
                                                         tzinfo=UTC),
                                           result=None,
                                           primary_traveler=user_joe_smith)
        activity_3.travels.add(travel_1)
        activity_3.locations.set([location_ABC])
        activity_3.partner = partnership_B3.agreement.partner
        activity_3.partnership = partnership_B3
        activity_3.save()

        activity_4 = TravelActivityFactory(travel_type=TravelType.SPOT_CHECK,
                                           date=datetime(2016,
                                                         12,
                                                         6,
                                                         tzinfo=UTC),
                                           result=None,
                                           primary_traveler=user_alice_carter)
        activity_4.travels.add(travel_2)
        activity_4.locations.set([location_111, location_345])
        activity_4.partner = partnership_C1.agreement.partner
        activity_4.partnership = partnership_C1
        activity_4.save()

        with self.assertNumQueries(6):
            response = self.forced_auth_req(
                'get',
                reverse('t2f:travels:list:activity_export'),
                user=self.unicef_staff)
        export_csv = csv.reader(StringIO(response.content.decode('utf-8')))
        rows = [r for r in export_csv]

        self.assertEqual(len(rows), 5)

        # check header
        self.assertEqual(rows[0], [
            'reference_number', 'traveler', 'office', 'section', 'status',
            'trip_type', 'partner', 'partnership', 'results', 'locations',
            'start_date', 'end_date', 'is_secondary_traveler',
            'primary_traveler_name'
        ])

        self.assertEqual(rows[1], [
            '2016/1000', 'Joe Smith', 'Budapest', 'Health', 'planned',
            'Programmatic Visit', 'Partner A', 'Partnership A1', 'Result A11',
            'Location 345, Location ABC', '08-Nov-2017', '14-Nov-2017', '', ''
        ])

        self.assertEqual(rows[2], [
            '2016/1000', 'Joe Smith', 'Budapest', 'Health', 'planned',
            'Programmatic Visit', 'Partner A', 'Partnership A2', 'Result A21',
            'Location 111', '08-Nov-2017', '14-Nov-2017', 'YES', 'Lenox Lewis'
        ])

        self.assertEqual(rows[3], [
            '2016/1000', 'Joe Smith', 'Budapest', 'Health', 'planned',
            'Meeting', 'Partner B', 'Partnership B3', '', 'Location ABC',
            '08-Nov-2017', '14-Nov-2017', '', ''
        ])

        self.assertEqual(rows[4], [
            '2016/1211', 'Alice Carter', 'Budapest', 'Education', 'planned',
            'Spot Check', 'Partner C', 'Partnership C1', '',
            'Location 111, Location 345', '08-Nov-2017', '14-Nov-2017', '', ''
        ])
Пример #19
0
    def setUpTestData(cls):
        cls.unicef_staff = UserFactory(is_staff=True)
        cls.partner = PartnerFactory(
            partner_type='Government',
            vendor_number='Vendor No',
            short_name="Short Name",
            alternate_name="Alternate Name",
            shared_with=["DPKO", "ECA"],
            address="Address 123",
            phone_number="Phone no 1234567",
            email="*****@*****.**",
            rating=PartnerOrganization.RATING_HIGH,
            core_values_assessment_date=datetime.date.today(),
            total_ct_cp=10000,
            total_ct_cy=20000,
            net_ct_cy=100.0,
            reported_cy=300.0,
            total_ct_ytd=400.0,
            deleted_flag=False,
            blocked=False,
            type_of_assessment="Type of Assessment",
            last_assessment_date=datetime.date.today(),
        )
        cls.partnerstaff = PartnerStaffFactory(partner=cls.partner)
        attachment = tempfile.NamedTemporaryFile(suffix=".pdf").name
        cls.agreement = AgreementFactory(
            partner=cls.partner,
            country_programme=CountryProgrammeFactory(wbs="random WBS"),
            attached_agreement=attachment,
            start=datetime.date.today(),
            end=datetime.date.today(),
            signed_by_unicef_date=datetime.date.today(),
            signed_by=cls.unicef_staff,
            signed_by_partner_date=datetime.date.today())
        cls.agreement.authorized_officers.add(cls.partnerstaff)
        cls.agreement.save()
        # This is here to test partner scoping
        AgreementFactory(signed_by_unicef_date=datetime.date.today())
        cls.intervention = InterventionFactory(
            agreement=cls.agreement,
            document_type='SHPD',
            status='draft',
            start=datetime.date.today(),
            end=datetime.date.today(),
            submission_date=datetime.date.today(),
            submission_date_prc=datetime.date.today(),
            review_date_prc=datetime.date.today(),
            signed_by_unicef_date=datetime.date.today(),
            signed_by_partner_date=datetime.date.today(),
            unicef_signatory=cls.unicef_staff,
            population_focus="Population focus",
            partner_authorized_officer_signatory=cls.partnerstaff,
            country_programme=cls.agreement.country_programme,
        )
        cls.ib = InterventionBudgetFactory(intervention=cls.intervention,
                                           currency="USD")

        output_res_type, _ = ResultType.objects.get_or_create(name='Output')
        cls.result = ResultFactory(result_type=output_res_type)

        cls.planned_visit = InterventionPlannedVisitsFactory(
            intervention=cls.intervention, )