Beispiel #1
0
 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,
     )
Beispiel #2
0
    def test_fail_transition_to_signed_start_and_end_dates(self):
        """Exercise transition to signed, and validation related to start and end dates."""
        agreement = AgreementFactory(agreement_type=Agreement.MOU,
                                     status=Agreement.DRAFT,
                                     signed_by_unicef_date=None,
                                     signed_by_partner_date=None)
        data = {
            "agreement": agreement,
            "status": Agreement.SIGNED,
        }
        serializer = AgreementCreateUpdateSerializer()
        # If I don't set serializer.instance, the validator gets confused. I guess (?) this is ordinarily set by DRF
        # during an update?
        serializer.instance = agreement
        serializer.context['request'] = self.fake_request
        # Should fail because start date is empty.
        with self.assertRaises(serializers.ValidationError) as context_manager:
            serializer.validate(data=data)

        self.assertSimpleExceptionFundamentals(
            context_manager,
            'Agreement cannot transition to signed until the start date is less than or equal to today'
        )

        # Populate start date, but with a date that's still invalid (in the future)
        agreement.start = self.today + datetime.timedelta(days=5)
        agreement.save()

        # Should fail because start date is in the future
        with self.assertRaises(serializers.ValidationError) as context_manager:
            serializer.validate(data=data)

        self.assertSimpleExceptionFundamentals(
            context_manager,
            'Agreement cannot transition to signed until the start date is less than or equal to today'
        )

        # Fix problem with start date, now allow blank end date to cause a failure.
        agreement.start = self.today - datetime.timedelta(days=5)
        agreement.save()

        with self.assertRaises(serializers.ValidationError) as context_manager:
            serializer.validate(data=data)

        self.assertSimpleExceptionFundamentals(
            context_manager,
            'Agreement cannot transition to signed unless the end date is defined'
        )

        # Populate end date with a date in the past - should pass validation for MOU's
        agreement.end = self.today - datetime.timedelta(days=3)
        self.assertTrue(serializer.validate(data=data))

        # Fix end date
        agreement.end = self.today
        agreement.save()

        # Should not raise an exception
        serializer.validate(data=data)