def test_save_wbs(self): """If 'A0/99' in wbs mark country programme as invalid""" programme = CountryProgrammeFactory() self.assertFalse(programme.invalid) programme.wbs = "A0/99" programme.save() self.assertTrue(programme.invalid)
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_country_programme(self): instance = CountryProgrammeFactory.build(name='xyz', wbs='xyz') self.assertEqual(str(instance), u'xyz xyz') instance = CountryProgrammeFactory.build(name=u'\xccsland', wbs='xyz') self.assertEqual(str(instance), u'\xccsland xyz') instance = CountryProgrammeFactory.build(name=u'\xccsland', wbs=u'xyz') self.assertEqual(str(instance), u'\xccsland xyz')
def setUpTestData(cls): today = datetime.date.today() cls.programme_active = CountryProgrammeFactory( from_date=today - datetime.timedelta(days=1), to_date=today + datetime.timedelta(days=1), ) cls.programme_past = CountryProgrammeFactory( from_date=datetime.date(2001, 1, 1), to_date=datetime.date(2001, 12, 31), ) cls.programme_future = CountryProgrammeFactory( from_date=today + datetime.timedelta(days=2 * 30), to_date=today + datetime.timedelta(days=6 * 30), )
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)
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.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_update_activities_create(self): """If Result (of type activity) does not exist with WBS value, then create new Result with data provided """ CountryProgrammeFactory(wbs="C1") init_result_count = Result.objects.filter( result_type=self.result_type_activity ).count() result_qs = Result.objects.filter( name="Changed", result_type=self.result_type_activity ) today = datetime.date.today() self.assertFalse(result_qs.exists()) self.data["cp"] = "C1" self.data["activities"] = {"R1": { "name": "Changed", "from_date": today.strftime("%Y-%m-%d"), "to_date": (today + datetime.timedelta(days=30)).strftime("%Y-%m-%d"), "wbs": "R1", }} 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, 1) self.assertEqual(Result.objects.count(), init_result_count + 1) self.assertTrue(result_qs.exists())
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.outcome = ResultFactory( result_type=ResultTypeFactory(name=ResultType.OUTCOME), country_programme=cls.country_programme ) cls.url = reverse('reports:report-result-list')
def test_save_to_date(self): """If to_date changes for country programme, agreement to date needs to be updated as well """ programme = CountryProgrammeFactory(to_date=datetime.date(2001, 1, 1), ) agreement = AgreementFactory( country_programme=programme, agreement_type=Agreement.PCA, end=datetime.date(2001, 1, 1), ) self.assertFalse(programme.invalid) new_to_date = datetime.date(2002, 1, 1) programme.to_date = new_to_date programme.save() agreement_updated = Agreement.objects.get(pk=agreement.pk) self.assertEqual(agreement_updated.end, new_to_date)
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 test_update_cps_exists(self): """If CountryProgramme exists with WBS value, and attributes have NOT changed then no update """ CountryProgrammeFactory(name="New", wbs="C1") self.data["cps"] = {"C1": {"name": "New"}} self.adapter.data = self.data total_data, total_updated, length = self.adapter.update_cps() self.assertEqual(total_data, 1) self.assertEqual(total_updated, 0) self.assertEqual(length, 0)
def test_direct_cp(self): cp = CountryProgrammeFactory(to_date=self.lead_date) InterventionFactory( document_type=Intervention.PD, end=self.lead_date + datetime.timedelta(days=10), country_programme=cp, ) mock_send = Mock() with patch(self.send_path, mock_send): utils.send_pca_required_notifications() self.assertEqual(mock_send.call_count, 1)
def test_update_cps_updated(self): """If CountryProgramme exists with WBS value, and attributes have changed then update""" cp = CountryProgrammeFactory(name="New", wbs="C1") self.data["cps"] = {"C1": {"name": "Changed"}} self.adapter.data = self.data total_data, total_updated, length = self.adapter.update_cps() self.assertEqual(total_data, 1) self.assertEqual(total_updated, 1) self.assertEqual(length, 0) cp_updated = CountryProgramme.objects.get(pk=cp.pk) self.assertEqual(cp_updated.name, "Changed")
def test_save_model_create(self): self.assertFalse(Activity.objects.exists()) obj = Agreement(partner=self.partner, country_programme=CountryProgrammeFactory(), agreement_type=Agreement.PCA, reference_number_year=datetime.date.today().year) aa = AgreementAdmin(Agreement, self.site) aa.save_model(self.request, obj, {}, False) self.assertTrue( Activity.objects.filter(action=Activity.CREATE).exists()) activity = Activity.objects.first() self.assertEqual(activity.target, obj) self.assertEqual(activity.by_user, self.user) self.assertEqual(activity.change, {})
def test_command(self): send_path = "etools.applications.partners.utils.send_notification_with_template" lead_date = datetime.date.today() + datetime.timedelta( days=settings.PCA_REQUIRED_NOTIFICATION_LEAD) cp = CountryProgrammeFactory(to_date=lead_date) agreement = AgreementFactory(country_programme=cp) InterventionFactory( document_type=Intervention.PD, end=lead_date + datetime.timedelta(days=10), agreement=agreement, ) mock_send = Mock() with patch(send_path, mock_send): call_command("send_pca_required_notifications") self.assertEqual(mock_send.call_count, 1)
def setUpTestData(cls): cls.unicef_staff = UserFactory(is_staff=True) cls.partnership_manager_user = UserFactory(is_staff=True) cls.partnership_manager_user.groups.add(GroupFactory()) cls.partner1 = PartnerFactory( partner_type=PartnerType.CIVIL_SOCIETY_ORGANIZATION) cls.country_programme = CountryProgrammeFactory() cls.agreement1 = AgreementFactory( partner=cls.partner1, signed_by_unicef_date=datetime.date.today()) cls.intervention = InterventionFactory(agreement=cls.agreement1) cls.intervention_2 = InterventionFactory(agreement=cls.agreement1, document_type=Intervention.PD) cls.amendment = AgreementAmendment.objects.create( agreement=cls.agreement1, types=[AgreementAmendment.IP_NAME, AgreementAmendment.CLAUSE], number="001", signed_amendment="application/pdf", signed_date=datetime.date.today())
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 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('reports:report-result-list')
def test_command(self): send_path = "etools.applications.partners.utils.send_notification_using_email_template" date_past = datetime.date.today() - datetime.timedelta(days=10) date_future = datetime.date.today() + datetime.timedelta(days=10) partner = PartnerFactory() cp = CountryProgrammeFactory( from_date=date_past, to_date=datetime.date.today(), ) agreement = AgreementFactory( partner=partner, agreement_type=Agreement.PCA, country_programme=cp, ) InterventionFactory( document_type=Intervention.PD, start=date_past + datetime.timedelta(days=1), end=date_future, agreement=agreement, ) mock_send = Mock() with patch(send_path, mock_send): call_command("send_pca_missing_notifications") self.assertEqual(mock_send.call_count, 1)
def test_valid_entry_no_wbs(self): programme = CountryProgrammeFactory(wbs="WBS") result = ResultFactory(country_programme=programme) self.assertIsNone(result.valid_entry())
def setUp(self): this_year = self.today.year self.country_programme = CountryProgrammeFactory( from_date=datetime.date(this_year - 1, 1, 1), to_date=datetime.date(this_year + 1, 1, 1))
def test_valid_entry_no(self): programme = CountryProgrammeFactory(wbs="WBS") result = ResultFactory(wbs="SBW", country_programme=programme) self.assertFalse(result.valid_entry())