def test_run_all_checks(self): PartnerFactory(short_name='A name') # make a good one as well just to ensure it's not flagging everything partner_bad = PartnerFactory() checks.bootstrap_checks(default_is_active=True) checks.run_all_checks() self.assertEqual(1, FlaggedIssue.objects.count()) issue = FlaggedIssue.objects.first() self.assertEqual(PartnersMustHaveShortNameTestCheck.check_id, issue.issue_id) self.assertEqual(partner_bad, issue.content_object)
def test_notification(self): agreement = AgreementFactory(partner=PartnerFactory(name='xyz')) notification = NotificationFactory(sender=agreement) self.assertIn('Email Notification from', str(notification)) self.assertIn('for xyz', str(notification)) agreement = AgreementFactory(partner=PartnerFactory(name='R\xe4dda Barnen')) notification = NotificationFactory(sender=agreement) self.assertIn('Email Notification from', str(notification)) self.assertIn('for R\xe4dda Barnen', str(notification))
def test_cso_types(self): """Verify the cso_types portion of the response""" PartnerFactory(cso_type=PartnerOrganization.CSO_TYPES['International']) # These should be filtered out of the endpoint response (https://github.com/unicef/etools/issues/510) PartnerFactory(cso_type='') response = self.forced_auth_req('get', self.url) d = self._assertResponseFundamentals(response) self.assertCountEqual( d['cso_types'], [{'value': PartnerOrganization.CSO_TYPES['International'], 'label': PartnerOrganization.CSO_TYPES['International']}])
def setUpTestData(cls): cls.aggregate_hact = AggregateHactFactory() cls.partner = PartnerFactory( name="Partner Name", partner_type=PartnerType.CIVIL_SOCIETY_ORGANIZATION, shared_with=[PartnerOrganization.AGENCY_CHOICES.UN], rating=PartnerOrganization.RATING_HIGH, total_ct_cp=200.0, total_ct_cy=400.0, net_ct_cy=110000.0, reported_cy=300.0, total_ct_ytd=140000.0, ) cls.partner2 = PartnerFactory( name="Partner Name", partner_type=PartnerType.GOVERNMENT, shared_with=[PartnerOrganization.AGENCY_CHOICES.UNHCR], rating=PartnerOrganization.RATING_LOW, total_ct_cp=200.0, total_ct_cy=2200.0, net_ct_cy=510000.0, reported_cy=52000.0, total_ct_ytd=550000.0, ) AuditFactory( status=Engagement.FINAL, audit_opinion=Audit.OPTION_UNQUALIFIED, date_of_draft_report_to_unicef=datetime(datetime.today().year, 1, 3), additional_supporting_documentation_provided=1000.0, justification_provided_and_accepted=20000.0, write_off_required=30000.0, amount_refunded=400000.0, audited_expenditure=50.0, financial_findings=999.0, ) AuditFactory( status=Engagement.FINAL, audit_opinion=Audit.OPTION_UNQUALIFIED, date_of_draft_report_to_unicef=datetime(datetime.today().year - 1, 1, 3), additional_supporting_documentation_provided=10.0, justification_provided_and_accepted=20.0, write_off_required=30.0, amount_refunded=40.0, audited_expenditure=50.0, financial_findings=100.0, )
def test_invalid_pca(self): """The agreement transition validation fails if; - Agreement type is PCA AND there exists an agreement that has ALL of the following; - same partner - status is SIGNED - agreement type is PCA - same country programme - start date > 2015-07-01 """ partner = PartnerFactory() country = CountryProgrammeFactory() AgreementFactory(partner=partner, agreement_type=Agreement.PCA, status=Agreement.SIGNED, country_programme=country, start=datetime.date.today()) agreement = AgreementFactory( partner=partner, agreement_type=Agreement.PCA, country_programme=country, ) with self.assertRaises(TransitionError): agreements.agreement_transition_to_signed_valid(agreement)
def setUpTestData(cls): cls.url = reverse("partners_api:partner-hact") cls.unicef_staff = UserFactory(is_staff=True) cls.partner = PartnerFactory( total_ct_cp=10.00, total_ct_cy=8.00, )
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])
def setUpTestData(cls): cls.unicef_staff = UserFactory(is_staff=True) 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="High", core_values_assessment_date=datetime.date.today(), total_ct_cp=10000, total_ct_cy=20000, deleted_flag=False, blocked=False, type_of_assessment="Type of Assessment", last_assessment_date=datetime.date.today(), ) partnerstaff = PartnerStaffFactory(partner=partner) cls.agreement = AgreementFactory( partner=partner, country_programme=CountryProgrammeFactory(wbs="random WBS"), attached_agreement="fake_attachment.pdf", 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(partnerstaff) cls.agreement.save()
def test_recheck(self): partner_bad = PartnerFactory() checks.bootstrap_checks(default_is_active=True) checks.run_all_checks() self.assertEqual(1, FlaggedIssue.objects.count()) issue = FlaggedIssue.objects.first() self.assertEqual(PartnersMustHaveShortNameTestCheck.check_id, issue.issue_id) self.assertEqual(partner_bad, issue.content_object) self.assertEqual(ISSUE_STATUS_NEW, issue.issue_status) update_date = issue.date_updated # initial recheck should not do anything except modify timestamps issue = FlaggedIssue.objects.get(pk=issue.pk) issue.recheck() self.assertEqual(ISSUE_STATUS_NEW, issue.issue_status) self.assertNotEqual(update_date, issue.date_updated) update_date = issue.date_updated # recheck after fixing the issue should update the status to resolved partner_bad.short_name = 'Name added' partner_bad.save() issue = FlaggedIssue.objects.get(pk=issue.pk) issue.recheck() self.assertEqual(ISSUE_STATUS_RESOLVED, issue.issue_status) self.assertNotEqual(update_date, issue.date_updated) update_date = issue.date_updated # recheck after re-creating the issue should update the status to reactivated partner_bad.short_name = '' partner_bad.save() issue = FlaggedIssue.objects.get(pk=issue.pk) issue.recheck() self.assertEqual(ISSUE_STATUS_REACTIVATED, issue.issue_status) self.assertNotEqual(update_date, issue.date_updated)
def test_cp_previous(self): date_past = datetime.date.today() - datetime.timedelta(days=10) date_future = datetime.date.today() + datetime.timedelta(days=10) partner = PartnerFactory() cp_previous = CountryProgrammeFactory( from_date=date_past, to_date=datetime.date.today(), ) agreement_previous = AgreementFactory( partner=partner, agreement_type=Agreement.PCA, country_programme=cp_previous, ) cp = CountryProgrammeFactory( from_date=datetime.date.today() + datetime.timedelta(days=1), to_date=date_future, ) AgreementFactory( partner=partner, agreement_type=Agreement.PCA, country_programme=cp, ) InterventionFactory( document_type=Intervention.PD, start=date_past + datetime.timedelta(days=1), end=datetime.date.today() + datetime.timedelta(days=1), agreement=agreement_previous, ) mock_send = Mock() with patch(self.send_path, mock_send): utils.send_pca_missing_notifications() self.assertEqual(mock_send.call_count, 0)
def test_recheck_all_open_issues(self): """Check that recheck_all_open_issues call changes those issues that are not resolved And handles invalid issues """ partner = PartnerFactory(short_name='A name') issue_resolved = FlaggedIssueFactory( content_object=partner, issue_id='partners_must_have_short_name', issue_status=ISSUE_STATUS_RESOLVED, ) issue_new = FlaggedIssueFactory( content_object=partner, issue_id='partners_must_have_short_name', issue_status=ISSUE_STATUS_NEW, ) issue_bad = FlaggedIssueFactory( content_object=partner, issue_status=ISSUE_STATUS_NEW, ) checks.recheck_all_open_issues() issue_resolved_updated = FlaggedIssue.objects.get(pk=issue_resolved.pk) self.assertEqual(issue_resolved_updated.date_updated, issue_resolved.date_updated) issue_new_updated = FlaggedIssue.objects.get(pk=issue_new.pk) self.assertNotEqual(issue_new_updated.date_updated, issue_new.date_updated) issue_bad_updated = FlaggedIssue.objects.get(pk=issue_bad.pk) self.assertEqual(issue_bad_updated.date_updated, issue_bad.date_updated)
def setUpTestData(cls): cls.file_type_partner = AttachmentFileTypeFactory( code="partners_partner_assessment") cls.file_type_agreement = AttachmentFileTypeFactory( code="partners_agreement") cls.file_type_assessment = AttachmentFileTypeFactory( code="partners_assessment_report") cls.file_type_agreement_amendment = AttachmentFileTypeFactory( code="partners_agreement_amendment") cls.file_type_intervention_prc_review = AttachmentFileTypeFactory( code="partners_intervention_prc_review") cls.file_type_intervention_signed_pd = AttachmentFileTypeFactory( code="partners_intervention_signed_pd") cls.file_type_intervention_amendment = AttachmentFileTypeFactory( code="partners_intervention_amendment_signed") cls.file_type_intervention_attachment = AttachmentFileTypeFactory( code="partners_intervention_attachment") cls.partner = PartnerFactory() cls.core_values_assessment = CoreValuesAssessmentFactory( assessment="sample.pdf") cls.agreement = AgreementFactory(attached_agreement="sample.pdf") cls.assessment = AssessmentFactory(report="sample.pdf") cls.agreement_amendment = AgreementAmendmentFactory( signed_amendment="sample.pdf") cls.intervention = InterventionFactory( prc_review_document="prc_sample.pdf", signed_pd_document="pd_sample.pdf") cls.intervention_amendment = InterventionAmendmentFactory( signed_amendment="sample.pdf") cls.intervention_attachment = InterventionAttachmentFactory( attachment="sample.pdf")
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)
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)
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_partner_staff(self): partner = PartnerFactory() partner_staff = PartnerStaffFactory(partner=partner) fields = utils.get_to_many_field_names(partner_staff.__class__) # check many_to_one field self.assertIn("signed_interventions", fields) # check many_to_many field self.assertIn("agreement_authorizations", fields)
def test_clean_email_no_change(self): """Ensure valid if no change in email """ partner = PartnerFactory() staff = PartnerStaffFactory( partner=partner, email="*****@*****.**", ) form = forms.PartnerStaffMemberForm(self.data, instance=staff) self.assertTrue(form.is_valid())
def setUpTestData(cls): cls.unicef_staff = UserFactory(is_staff=True) cls.partner = PartnerFactory( partner_type=PartnerType.CIVIL_SOCIETY_ORGANIZATION, cso_type="International", hidden=False, vendor_number="DDD", short_name="Short name", ) cls.url = reverse('partners_api:partner-delete', args=[cls.partner.pk])
def test_save_records_update_name(self): """Check that partner organization record is updated, name changed """ partner = PartnerFactory(name="New", vendor_number=self.data["VENDOR_CODE"]) response = self.adapter._save_records([self.data]) self.assertEqual(response, 1) partner_updated = PartnerOrganization.objects.get(pk=partner.pk) self.assertEqual(partner_updated.name, self.data["VENDOR_NAME"])
def test_get_or_new_returns_saved(self): issue_id = 'test-return-saved' partner = PartnerFactory() issue = FlaggedIssueFactory(content_object=partner, issue_id=issue_id, message='test message') self.assertTrue(issue.pk is not None) issue_back = FlaggedIssue.get_or_new(partner, issue_id) # make sure we got the same one back self.assertEqual(issue.pk, issue_back.pk)
def test_delete(self): partner = PartnerFactory() response = self.forced_auth_req( 'delete', reverse('partners_api:partner-delete', args=[partner.pk]), user=self.unicef_staff, ) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertFalse( PartnerOrganization.objects.filter(pk=partner.pk).exists())
def setUpTestData(cls): cls.unicef_staff = UserFactory(is_staff=True) cls.partner = PartnerFactory( partner_type=PartnerType.CIVIL_SOCIETY_ORGANIZATION, cso_type="International", hidden=False, vendor_number="DDD", short_name="Short name", ) report = "report.pdf" cls.assessment1 = Assessment.objects.create(partner=cls.partner, type="Micro Assessment") cls.assessment2 = Assessment.objects.create( partner=cls.partner, type="Micro Assessment", report=report, completed_date=datetime.date.today()) cls.partner_gov = PartnerFactory(partner_type=PartnerType.GOVERNMENT) agreement = AgreementFactory( partner=cls.partner, signed_by_unicef_date=datetime.date.today()) cls.intervention = InterventionFactory(agreement=agreement) cls.output_res_type = ResultTypeFactory(name=ResultType.OUTPUT) cls.result = ResultFactory(result_type=cls.output_res_type, ) cls.partnership_budget = InterventionBudget.objects.create( intervention=cls.intervention, unicef_cash=100, unicef_cash_local=10, partner_contribution=200, partner_contribution_local=20, in_kind_amount_local=10, ) cls.amendment = InterventionAmendment.objects.create( intervention=cls.intervention, types=[InterventionAmendment.RESULTS]) cls.cp = CountryProgrammeFactory(__sequence=10) cls.cp_output = ResultFactory(result_type=cls.output_res_type)
def test_get(self): partner = PartnerFactory() agreement = AgreementFactory(partner=partner) intervention_1 = InterventionFactory(agreement=agreement) intervention_2 = InterventionFactory(agreement=agreement) intervention_3 = InterventionFactory() res = tags.get_interventions(partner.pk) self.assertIn(intervention_1.number, res) self.assertIn(intervention_2.number, res) self.assertNotIn(intervention_3.number, res)
def setUpTestData(cls): cls.unicef_staff = UserFactory(is_staff=True) 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="High", core_values_assessment_date=datetime.date.today(), total_ct_cp=10000, total_ct_cy=20000, deleted_flag=False, blocked=False, type_of_assessment="Type of Assessment", last_assessment_date=datetime.date.today(), ) partnerstaff = PartnerStaffFactory(partner=partner) agreement = AgreementFactory( partner=partner, country_programme=CountryProgrammeFactory(wbs="random WBS"), attached_agreement="fake_attachment.pdf", 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()) agreement.authorized_officers.add(partnerstaff) agreement.save() AgreementFactory(signed_by_unicef_date=datetime.date.today()) cls.intervention = InterventionFactory( agreement=agreement, document_type=Intervention.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=partnerstaff, country_programme=agreement.country_programme, ) cls.ib = InterventionBudgetFactory(intervention=cls.intervention, currency="USD") cls.attachment = InterventionAttachmentFactory( intervention=cls.intervention, ) cls.planned_visit = InterventionPlannedVisitsFactory( intervention=cls.intervention, )
def get_fixtures(self): partner = PartnerFactory( id=101, hidden=False, partner_type=PartnerType.CIVIL_SOCIETY_ORGANIZATION, cso_type="International", vendor_number="DDD", short_name="Short name", modified=datetime.datetime.today() ) partner_not_programmatic_visit_compliant = PartnerFactory( net_ct_cy=PartnerOrganization.CT_MR_AUDIT_TRIGGER_LEVEL + 1, hact_values={'programmatic_visits': {'completed': {'total': 0}}}, hidden=False, reported_cy=10000 ) return { 'partner': partner, 'partner_not_programmatic_visit_compliant': partner_not_programmatic_visit_compliant, }
def test_task_create(self): logs = VisionSyncLog.objects.all() self.assertEqual(logs.count(), 0) PartnerFactory(name="Partner XYZ", reported_cy=20000) update_hact_for_country(self.tenant.name) self.assertEqual(logs.count(), 1) log = logs.first() self.assertEqual(log.total_records, 1) self.assertEqual(log.total_processed, 1) self.assertTrue(log.successful)
def test_clean_activate(self): """If staff member made active, ensure user not already associated with another partner """ UserFactory(email="*****@*****.**") partner = PartnerFactory() staff = PartnerStaffFactory(partner=partner, email="*****@*****.**", active=False) form = forms.PartnerStaffMemberForm(self.data, instance=staff) self.assertTrue(form.is_valid())
def test_flagged_issue(self): partner = PartnerFactory() issue = FlaggedIssueFactory(content_object=partner, issue_id="321", message='test message') self.assertEqual(str(issue), u"test message") issue = FlaggedIssueFactory(content_object=partner, issue_id="321", message=u"R\xe4dda Barnen") self.assertEqual(str(issue), u"R\xe4dda Barnen")
def test_save_records_update_deleted_flag(self): """Check that partner organization record is updated, deleted_flag changed """ self.data["MARKED_FOR_DELETION"] = 'X' partner = PartnerFactory(name=self.data["VENDOR_NAME"], vendor_number=self.data["VENDOR_CODE"], deleted_flag=False) response = self.adapter._save_records([self.data]) self.assertEqual(response, 1) partner_updated = PartnerOrganization.objects.get(pk=partner.pk) self.assertTrue(partner_updated.deleted_flag)
def test_valid(self): partner = PartnerFactory() user = UserFactory() staff = PartnerStaffFactory(partner=partner, ) agreement = AgreementFactory( partner=partner, signed_by_unicef_date=datetime.date.today(), signed_by=user, signed_by_partner_date=datetime.date.today(), partner_manager=staff, ) self.assertTrue(agreements.signatures_valid(agreement))