Пример #1
0
 def setUpTestData(cls):
     cls.unicef_staff = UserFactory(is_staff=True)
     cls.partner = PartnerFactory(
         partner_type=PartnerType.UN_AGENCY,
         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="High",
         core_values_assessment_date=datetime.date.today(),
         total_ct_cp=10000,
         total_ct_cy=20000,
         total_ct_ytd=30000,
         deleted_flag=False,
         blocked=False,
         type_of_assessment="Type of Assessment",
         last_assessment_date=datetime.date.today(),
         hact_values=
         '{"outstanding_findings": 0, "audits": {"completed": 0, "minimum_requirements": 0}, "programmatic_visits": {"completed": {"q1": 0, "total": 0, "q3": 0, "q2": 0, "q4": 0}, "planned": {"q1": 0, "total": 0, "q3": 0, "q2": 0, "q4": 0}}, "spot_checks": {"completed": {"q1": 0, "total": 0, "q3": 0, "q2": 0, "q4": 0}, "planned": {"q1": 0, "total": 0, "q3": 0, "q2": 0, "q4": 0}, "follow_up_required": 0}}',
     )
     cls.partnerstaff = PartnerStaffFactory(partner=cls.partner)
     cls.planned_visit = PartnerPlannedVisitsFactory(partner=cls.partner)
Пример #2
0
    def setUpTestData(cls):
        cls.unicef_staff = UserFactory(is_staff=True)
        cls.partner = PartnerFactory(
            partner_type=PartnerType.UN_AGENCY,
            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")
        cls.planned_visit = PartnerPlannedVisitsFactory(partner=cls.partner)

        output_res_type, _ = ResultType.objects.get_or_create(name='Output')
        cls.result = ResultFactory(result_type=output_res_type)
Пример #3
0
 def setUpTestData(cls):
     cls.unicef_staff = UserFactory(is_staff=True)
     cls.unicef_staff.groups.add(GroupFactory(name='Partnership Manager'))
     cls.partner = PartnerFactory()
     cls.planned_visit = PartnerPlannedVisitsFactory(partner=cls.partner, )
     cls.url = reverse("partners_api:partner-planned-visits-del",
                       args=[cls.planned_visit.pk])
Пример #4
0
    def test_update_planned_visits_no_year(self):
        """Ensure update happens if no id value provided"""
        current_year = datetime.date.today().year
        planned_visit = PartnerPlannedVisitsFactory(
            partner=self.partner,
            year=current_year,
            programmatic_q1=1,
            programmatic_q2=2,
            programmatic_q3=3,
            programmatic_q4=4,
        )
        response = self.forced_auth_req(
            'get',
            reverse('partners_api:partner-detail', args=[self.partner.pk]),
            user=self.unicef_staff,
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data["planned_visits"]), 1)
        data = response.data["planned_visits"][0]
        self.assertEqual(data["programmatic_q1"], 1)
        self.assertEqual(data["programmatic_q2"], 2)
        self.assertEqual(data["programmatic_q3"], 3)
        self.assertEqual(data["programmatic_q4"], 4)

        planned_visits = [{
            "programmatic_q1": 4,
            "programmatic_q2": 3,
            "programmatic_q3": 2,
            "programmatic_q4": 1,
        }]
        data = {
            "name": self.partner.name + ' Updated',
            "partner_type": self.partner.partner_type,
            "vendor_number": self.partner.vendor_number,
            "planned_visits": planned_visits,
        }
        response = self.forced_auth_req(
            'patch',
            reverse('partners_api:partner-detail', args=[self.partner.pk]),
            user=self.unicef_staff,
            data=data,
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data["planned_visits"]), 1)
        data = response.data["planned_visits"][0]
        self.assertEqual(data["id"], planned_visit.pk)
        self.assertEqual(data["year"], current_year)
        self.assertEqual(data["programmatic_q1"], 4)
        self.assertEqual(data["programmatic_q2"], 3)
        self.assertEqual(data["programmatic_q3"], 2)
        self.assertEqual(data["programmatic_q4"], 1)
Пример #5
0
    def test_validation_fail_non_government(self):
        """Ensure update happens if no id value provided"""
        current_year = datetime.date.today().year
        cso_partner = PartnerFactory(
            partner_type=PartnerType.CIVIL_SOCIETY_ORGANIZATION,
            cso_type="International",
            hidden=False,
            vendor_number="XYZ",
            short_name="City Hunter",
        )

        PartnerPlannedVisitsFactory(
            partner=cso_partner,
            year=current_year,
            programmatic_q1=1,
            programmatic_q2=2,
            programmatic_q3=3,
            programmatic_q4=4,
        )
        planned_visits = [{
            "programmatic_q1": 4,
            "programmatic_q2": 3,
            "programmatic_q3": 2,
            "programmatic_q4": 1,
        }]
        data = {
            "name": cso_partner.name + ' Updated',
            "partner_type": cso_partner.partner_type,
            "vendor_number": cso_partner.vendor_number,
            "planned_visits": planned_visits,
        }
        response = self.forced_auth_req(
            'patch',
            reverse('partners_api:partner-detail', args=[cso_partner.pk]),
            user=self.unicef_staff,
            data=data,
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.data["planned_visits"]["partner"],
            ErrorDetail(
                string='Planned Visit can be set only for Government partners',
                code='invalid'))