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")
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)
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
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)
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}
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, )
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()
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.'])
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.'])
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, }
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, )
def setUpTestData(cls): cls.unicef_staff = UserFactory(is_staff=True) cls.intervention = InterventionFactory() cls.result_link = InterventionResultLinkFactory( intervention=cls.intervention, )
def setUpTestData(cls): cls.unicef_staff = UserFactory(is_staff=True) cls.result_link = InterventionResultLinkFactory() cls.lower_result = LowerResultFactory(result_link=cls.result_link)
def get_fixtures(cls): return {'intervention': InterventionFactory(id=101), 'amendment': InterventionAmendmentFactory(), 'result': InterventionResultLinkFactory(), }
def setUpTestData(cls): cls.result_link = InterventionResultLinkFactory()
def setUpTestData(cls): cls.result_link = InterventionResultLinkFactory() cls.lower_result = LowerResultFactory(result_link=cls.result_link)
def setUp(self): super(TestInterventionResultModelExport, self).setUp() indicator = IndicatorFactory() self.link = InterventionResultLinkFactory( intervention=self.intervention, ) self.link.ram_indicators.add(indicator)
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)