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='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.planned_visit = InterventionPlannedVisitsFactory( intervention=cls.intervention, ) cls.attachment = InterventionAttachmentFactory( intervention=cls.intervention, )
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 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_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_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, ) 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 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.url = reverse('report-result-detail', args=[cls.result1.pk])
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): 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('report-result-list')
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 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) )