Exemplo n.º 1
0
 def setUpTestData(cls):
     cls.unicef_staff = UserFactory(is_staff=True)
     cls.intervention = InterventionFactory()
     cls.result_link = InterventionResultLinkFactory()
     cls.lower_result = LowerResultFactory(
         name="LL Name",
         result_link=cls.result_link,
     )
     cls.indicator = IndicatorBlueprintFactory()
     AppliedIndicatorFactory(
         context_code="CC321",
         indicator=cls.indicator,
         lower_result=LowerResultFactory(name="LL Name", result_link=cls.result_link),
         cluster_name='ABC',
     )
     AppliedIndicatorFactory(
         context_code="CC321",
         indicator=cls.indicator,
         lower_result=LowerResultFactory(name="LL Name", result_link=cls.result_link),
         cluster_name='XYZ',
     )
     AppliedIndicatorFactory(
         context_code="CC321",
         indicator=cls.indicator,
         lower_result=LowerResultFactory(name="LL Name", result_link=cls.result_link),
         cluster_name='XYZ',
     )
     AppliedIndicatorFactory(
         context_code="CC321",
         indicator=cls.indicator,
         lower_result=LowerResultFactory(name="LL Name", result_link=cls.result_link),
     )
     cls.url = reverse("reports:cluster")
Exemplo n.º 2
0
 def setUpTestData(cls):
     cls.unicef_staff = UserFactory(is_staff=True)
     cls.result_link = InterventionResultLinkFactory()
     cls.lower_result = LowerResultFactory(result_link=cls.result_link)
     cls.indicator = IndicatorBlueprintFactory()
     cls.applied = AppliedIndicatorFactory(indicator=cls.indicator,
                                           lower_result=cls.lower_result)
Exemplo n.º 3
0
    def setUpTestData(cls):
        cls.code_1 = "test_code_1"
        cls.file_type_1 = AttachmentFileTypeFactory(code=cls.code_1)
        cls.code_2 = "test_code_2"
        cls.file_type_2 = AttachmentFileTypeFactory(code=cls.code_2)
        cls.unicef_staff = UserFactory(is_staff=True)
        cls.user = UserFactory()
        cls.url = reverse("attachments:list")
        cls.attachment_1 = AttachmentFactory(
            file_type=cls.file_type_1,
            code=cls.code_1,
            file="sample1.pdf",
            content_object=cls.file_type_1,
            uploaded_by=cls.unicef_staff
        )
        cls.attachment_2 = AttachmentFactory(
            file_type=cls.file_type_2,
            code=cls.code_2,
            file="sample2.pdf",
            content_object=cls.file_type_2,
            uploaded_by=cls.user
        )

        cls.partner = PartnerFactory(
            partner_type=PartnerType.UN_AGENCY,
            vendor_number="V123",
        )
        cls.agreement = AgreementFactory(partner=cls.partner)
        cls.assessment = AssessmentFactory(partner=cls.partner)
        cls.amendment = AgreementAmendmentFactory(agreement=cls.agreement)
        cls.intervention = InterventionFactory(agreement=cls.agreement)
        cls.result_link = InterventionResultLinkFactory(
            intervention=cls.intervention
        )
        cls.intervention_amendment = InterventionAmendmentFactory(
            intervention=cls.intervention
        )
        cls.intervention_attachment = InterventionAttachmentFactory(
            intervention=cls.intervention
        )

        cls.tpm_partner = SimpleTPMPartnerFactory(vendor_number="V432")
        cls.tpm_visit = TPMVisitFactory(tpm_partner=cls.tpm_partner)
        cls.tpm_activity = TPMActivityFactory(
            partner=cls.partner,
            intervention=cls.intervention,
            tpm_visit=cls.tpm_visit
        )

        cls.engagement = EngagementFactory(partner=cls.partner)

        cls.default_partner_response = [{
            "partner": "",
            "partner_type": "",
            "vendor_number": "",
            "pd_ssfa_number": "",
            "agreement_reference_number": "",
            "source": "",
        }] * 2
Exemplo n.º 4
0
 def test_update_exception(self):
     result_link = InterventionResultLinkFactory()
     self.data["result_link"] = result_link.pk
     serializer = LowerResultSimpleCUSerializer(data=self.data)
     self.assertTrue(serializer.is_valid())
     msg = "You can't associate this PD Output to a different CP Result"
     with self.assertRaisesRegexp(ValidationError, msg):
         serializer.update(self.lower_result, serializer.validated_data)
Exemplo n.º 5
0
 def setUpTestData(cls):
     cls.intervention = InterventionFactory(
         start=datetime.date(2001, 1, 1),
         in_amendment=True,
     )
     cls.result_link = InterventionResultLinkFactory(
         intervention=cls.intervention)
     cls.lower_result = LowerResultFactory(result_link=cls.result_link)
     cls.indicator = AppliedIndicatorFactory(lower_result=cls.lower_result)
     cls.context = {"intervention": cls.intervention}
Exemplo n.º 6
0
 def setUpTestData(cls):
     cls.unicef_staff = UserFactory(is_staff=True)
     cls.url = reverse("reports:lower-results")
     cls.intervention = InterventionFactory()
     cls.result_link = InterventionResultLinkFactory(
         intervention=cls.intervention, )
     cls.lower_result = LowerResultFactory(
         name="LL Name",
         result_link=cls.result_link,
     )
Exemplo n.º 7
0
 def setUpTestData(cls):
     cls.section = SectorFactory()
     cls.intervention = InterventionFactory()
     cls.result_link = InterventionResultLinkFactory(
         intervention=cls.intervention, )
     cls.lower_result = LowerResultFactory(result_link=cls.result_link, )
     cls.applied_indicator = AppliedIndicatorFactory(
         lower_result=cls.lower_result, )
     cls.location = LocationFactory()
     cls.indicator = IndicatorBlueprintFactory()
Exemplo n.º 8
0
 def test_validation_pd_has_no_start(self):
     intervention = InterventionFactory(in_amendment=True)
     result_link = InterventionResultLinkFactory(intervention=intervention)
     lower_result = LowerResultFactory(result_link=result_link)
     AppliedIndicatorFactory(lower_result=lower_result)
     data = {
         "report_type": ReportingRequirement.TYPE_QPR,
         "reporting_requirements": []
     }
     serializer = InterventionReportingRequirementCreateSerializer(
         data=data, context={"intervention": intervention})
     self.assertFalse(serializer.is_valid())
     self.assertEqual(serializer.errors['non_field_errors'],
                      ['PD needs to have a start date.'])
Exemplo n.º 9
0
 def test_validation_pd_status(self):
     intervention = InterventionFactory(start=datetime.date(2001, 1, 1),
                                        status=Intervention.CLOSED)
     result_link = InterventionResultLinkFactory(intervention=intervention)
     lower_result = LowerResultFactory(result_link=result_link)
     AppliedIndicatorFactory(lower_result=lower_result)
     data = {
         "report_type": ReportingRequirement.TYPE_QPR,
         "reporting_requirements": []
     }
     serializer = InterventionReportingRequirementCreateSerializer(
         data=data, context={"intervention": intervention})
     self.assertFalse(serializer.is_valid())
     self.assertEqual(
         serializer.errors['non_field_errors'],
         ['Changes not allowed when PD not in amendment state.'])
Exemplo n.º 10
0
 def setUp(self):
     self.indicator = IndicatorBlueprintFactory()
     self.intervention = InterventionFactory(status=Intervention.ACTIVE)
     self.result_link = InterventionResultLinkFactory(
         intervention=self.intervention, )
     self.lower_result = LowerResultFactory(result_link=self.result_link, )
     self.applied_indicator = AppliedIndicatorFactory(
         lower_result=self.lower_result,
         target={
             "d": 3,
             "v": 4
         },
     )
     self.intervention.flat_locations.add(self.location)
     self.intervention.sections.add(self.section)
     self.data = {
         "indicator": {
             "title": self.indicator.title
         },
         "lower_result": self.lower_result.pk,
         "locations": [self.location.pk],
         "section": self.section.pk,
     }
Exemplo n.º 11
0
    def test_intervention_location_export(self):
        # First intervention was already created for us in setUpTestData
        partner_name = self.intervention.agreement.partner.name

        # Assign known dates that we can test for in the output later on
        self.intervention.start = datetime.date(2013, 1, 6)
        self.intervention.end = datetime.date(2013, 3, 20)
        self.intervention.save()

        # Some locations
        self.intervention.flat_locations.add(
            LocationFactory(name='Location 0'),
            LocationFactory(name='Location 1'))

        # Some sections
        sec = SectorFactory(name='Sector 0')
        sec1 = SectorFactory(name='Sector 1')
        self.intervention.sections.add(sec, sec1)

        # Some focal points
        self.intervention.unicef_focal_points.add(
            UserFactory(first_name='Jack', last_name='Bennie'),
            UserFactory(first_name='Phil', last_name='Silver'))

        # Some results
        InterventionResultLinkFactory(cp_output=ResultFactory(sector=sec1,
                                                              name='Result A'),
                                      intervention=self.intervention)
        InterventionResultLinkFactory(cp_output=ResultFactory(sector=sec1,
                                                              name='Result B'),
                                      intervention=self.intervention)

        # Another intervention, with no locations
        self.intervention2 = InterventionFactory(agreement=AgreementFactory(
            partner=PartnerFactory(name='Partner 2')))
        # Sections
        sec2 = SectorFactory(name='Sector 2')
        sec3 = SectorFactory(name='Sector 3')
        self.intervention2.sections.add(sec2, sec3)
        # Results
        InterventionResultLinkFactory(cp_output=ResultFactory(sector=sec2,
                                                              name='Result C'),
                                      intervention=self.intervention2)
        InterventionResultLinkFactory(cp_output=ResultFactory(sector=sec3,
                                                              name='Result D'),
                                      intervention=self.intervention2)

        # Intervention with no sectors
        self.intervention3 = InterventionFactory(agreement=AgreementFactory(
            partner=PartnerFactory(name='Partner 3')))
        self.intervention3.flat_locations.add(
            LocationFactory(name='Location 2'))
        InterventionResultLinkFactory(
            intervention=self.intervention3,
            cp_output=ResultFactory(name='Result Fred'))

        self.url = reverse('partners_api:intervention-locations-list', )

        response = self.forced_auth_req(
            'get',
            self.url,
            user=self.unicef_staff,
            data={"format": "csv"},
        )
        self.assertEqual(200,
                         response.status_code,
                         msg=response.content.decode('utf-8'))
        result = response.content.decode('utf-8')

        today = datetime.date.today()
        self.assertEqual(
            f'attachment;filename={today.year}_{today.month}_{today.day}_TST_Interventions.csv',
            response['Content-Disposition'],
        )

        # Leave this here to easily uncomment for debugging.
        # print("RESULT:")
        # for line in result.split('\r\n'):
        #     print('f' + repr(line + '\r\n'))

        agreement_number_1 = self.intervention.agreement.agreement_number
        agreement_number_2 = self.intervention2.agreement.agreement_number
        agreement_number_3 = self.intervention3.agreement.agreement_number
        self.assertEqual(
            f'Partner,PD Ref Number,Partnership,Status,Location,Section,CP output,Start Date,End Date,Name of UNICEF Focal Point,Hyperlink\r\n'
            f'{partner_name},{self.intervention.number},{agreement_number_1},draft,Location 0,Sector 0,"Result A, Result B",2013-01-06,2013-03-20,"Jack Bennie, Phil Silver",https://testserver/pmp/interventions/{self.intervention.id}/details/\r\n'
            f'{partner_name},{self.intervention.number},{agreement_number_1},draft,Location 1,Sector 0,"Result A, Result B",2013-01-06,2013-03-20,"Jack Bennie, Phil Silver",https://testserver/pmp/interventions/{self.intervention.id}/details/\r\n'
            f'{partner_name},{self.intervention.number},{agreement_number_1},draft,Location 0,Sector 1,"Result A, Result B",2013-01-06,2013-03-20,"Jack Bennie, Phil Silver",https://testserver/pmp/interventions/{self.intervention.id}/details/\r\n'
            f'{partner_name},{self.intervention.number},{agreement_number_1},draft,Location 1,Sector 1,"Result A, Result B",2013-01-06,2013-03-20,"Jack Bennie, Phil Silver",https://testserver/pmp/interventions/{self.intervention.id}/details/\r\n'
            f'Partner 2,{self.intervention2.number},{agreement_number_2},draft,,Sector 2,"Result C, Result D",,,,https://testserver/pmp/interventions/{self.intervention2.id}/details/\r\n'
            f'Partner 2,{self.intervention2.number},{agreement_number_2},draft,,Sector 3,"Result C, Result D",,,,https://testserver/pmp/interventions/{self.intervention2.id}/details/\r\n'
            f'Partner 3,{self.intervention3.number},{agreement_number_3},draft,Location 2,,Result Fred,,,,https://testserver/pmp/interventions/{self.intervention3.id}/details/\r\n',
            result,
        )
Exemplo n.º 12
0
 def setUpTestData(cls):
     cls.unicef_staff = UserFactory(is_staff=True)
     cls.intervention = InterventionFactory()
     cls.result_link = InterventionResultLinkFactory(
         intervention=cls.intervention, )
Exemplo n.º 13
0
 def setUpTestData(cls):
     cls.unicef_staff = UserFactory(is_staff=True)
     cls.result_link = InterventionResultLinkFactory()
     cls.lower_result = LowerResultFactory(result_link=cls.result_link)
Exemplo n.º 14
0
 def get_fixtures(cls):
     return {'intervention': InterventionFactory(id=101),
             'amendment': InterventionAmendmentFactory(),
             'result': InterventionResultLinkFactory(),
             }
Exemplo n.º 15
0
 def setUpTestData(cls):
     cls.result_link = InterventionResultLinkFactory()
Exemplo n.º 16
0
 def setUpTestData(cls):
     cls.result_link = InterventionResultLinkFactory()
     cls.lower_result = LowerResultFactory(result_link=cls.result_link)
Exemplo n.º 17
0
 def setUp(self):
     super(TestInterventionResultModelExport, self).setUp()
     indicator = IndicatorFactory()
     self.link = InterventionResultLinkFactory(
         intervention=self.intervention, )
     self.link.ram_indicators.add(indicator)
Exemplo n.º 18
0
 def setUp(self):
     super(TestInterventionIndicatorModelExport, self).setUp()
     self.indicator = IndicatorFactory(name="Name", code="Code")
     self.link = InterventionResultLinkFactory(
         intervention=self.intervention, )
     self.link.ram_indicators.add(self.indicator)