Ejemplo n.º 1
0
    def test_update_with_due_to_amendments_signed_date(self):
        """Ensure agreement update fails if amendments don't have a signed_date or if it's in the future,
        and that update succeeds when the amendments signatures meet criteria.

        I don't think it's possible to supply amendments when creating via the serializer, so this only tests update.
        """
        agreement = AgreementFactory(agreement_type=Agreement.MOU,
                                     signed_by_unicef_date=None,
                                     signed_by_partner_date=None)

        amendment = AgreementAmendmentFactory(agreement=agreement)
        # I need to give amendment.signed_amendment a name to exercise the date part of the amendment validator.
        amendment.signed_amendment.name = 'fake_amendment.pdf'
        amendment.save()
        data = {
            'agreement': agreement,
            'amendments': [amendment],
        }
        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

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

        self.assertAmendmentExceptionFundamentals(
            context_manager,
            'Please check that the Document is attached and signatures are not in the future'
        )

        # Set the signed date, but set it to the future which should cause a failure.
        amendment.signed_date = self.today + datetime.timedelta(days=5)
        amendment.save()

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

        self.assertAmendmentExceptionFundamentals(
            context_manager,
            'Please check that the Document is attached and signatures are not in the future'
        )

        # Change the amendment so it will pass validation.
        amendment.signed_date = self.today
        amendment.save()

        # Should not raise an error.
        serializer.validate(data=data)
Ejemplo n.º 2
0
    def test_update_fail_due_to_amendments_unsigned(self):
        """Ensure agreement update fails if amendments aren't signed.

        I don't think it's possible to supply amendments when creating via the serializer, so this only tests update.
        """
        agreement = AgreementFactory(agreement_type=Agreement.MOU,
                                     signed_by_unicef_date=None,
                                     signed_by_partner_date=None)

        amendment = AgreementAmendmentFactory(agreement=agreement)
        data = {
            'agreement': agreement,
            'amendments': [amendment],
        }
        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

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

        self.assertAmendmentExceptionFundamentals(
            context_manager,
            'Please check that the Document is attached and signatures are not in the future'
        )
Ejemplo n.º 3
0
 def get_fixtures(self):
     agreement = AgreementFactory(signed_by_unicef_date=datetime.date.today())
     agreement_amendment = AgreementAmendmentFactory(agreement=agreement)
     return {
         'agreement': agreement,
         'agreement_amendment': agreement_amendment,
     }
Ejemplo n.º 4
0
 def setUp(self):
     super(TestAgreementAmendmentModelExport, self).setUp()
     self.amendment = AgreementAmendmentFactory(
         agreement=self.agreement,
         signed_amendment="fake_attachment.pdf",
         signed_date=datetime.date.today(),
     )
Ejemplo n.º 5
0
 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")
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
 def test_valid(self):
     agreement = AgreementFactory()
     AgreementAmendmentFactory(
         agreement=agreement,
         signed_amendment='fake.pdf',
         signed_date=datetime.date.today(),
     )
     self.assertTrue(agreements.amendments_valid(agreement))
Ejemplo n.º 8
0
    def test_update_with_due_to_amendments_signed_date(self):
        """Ensure agreement update fails if amendments don't have a signed_date or if it's in the future,
        and that update succeeds when the amendments signatures meet criteria.

        I don't think it's possible to supply amendments when creating via the serializer, so this only tests update.
        """
        agreement = AgreementFactory(agreement_type=Agreement.MOU,
                                     signed_by_unicef_date=None,
                                     signed_by_partner_date=None)

        amendment = AgreementAmendmentFactory(agreement=agreement)
        # I need to give amendment.signed_amendment a name to exercise the date part of the amendment validator.
        amendment.signed_amendment.name = 'fake_amendment.pdf'
        amendment.save()
        data = {
            'agreement': agreement,
            'amendments': [amendment],
        }
        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

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

        self.assertAmendmentExceptionFundamentals(
            context_manager,
            'Please check that the Document is attached and signatures are not in the future'
        )

        # Set the signed date, but set it to the future which should cause a failure.
        amendment.signed_date = self.today + datetime.timedelta(days=5)
        amendment.save()

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

        self.assertAmendmentExceptionFundamentals(
            context_manager,
            'Please check that the Document is attached and signatures are not in the future'
        )

        # Change the amendment so it will pass validation.
        amendment.signed_date = self.today
        amendment.save()

        # Should not raise an error.
        serializer.validate(data=data)
Ejemplo n.º 9
0
 def test_no_issue(self):
     """Check that if agreement has signed amendment
     then issue is NOT raised
     """
     amendment = AgreementAmendmentFactory(signed_amendment="random.pdf")
     self.assertTrue(amendment.signed_amendment)
     self.assertFalse(self.qs_issue.exists())
     checks.bootstrap_checks(default_is_active=True)
     checks.run_all_checks()
     self.assertFalse(self.qs_issue.exists())
Ejemplo n.º 10
0
 def test_no_signed_amendment(self):
     """Check that if agreement has no signed amendment
     then issue is raised
     """
     amendment = AgreementAmendmentFactory(signed_amendment=None)
     self.assertFalse(amendment.signed_amendment)
     self.assertFalse(self.qs_issue.exists())
     checks.bootstrap_checks(default_is_active=True)
     checks.run_all_checks()
     self.assertTrue(self.qs_issue.exists())
     issue = self.qs_issue.first()
     self.assertIn("has missing amendment file", issue.message)
Ejemplo n.º 11
0
 def test_agreement_amendment(self):
     amendment = AgreementAmendmentFactory(agreement=self.agreement)
     attachment = AttachmentFactory(content_object=amendment)
     file_path = models.generate_file_path(attachment, "test.pdf")
     self.assert_file_path(file_path, [
         str(self.partner.pk),
         "agreements",
         self.agreement.base_number.strip("/"),
         "amendments",
         str(amendment.number),
         "test.pdf"
     ], "agreementamendment")
     # check against old file path function
     # except new paths do not have '//'
     file_path_old = partner_models.get_agreement_amd_file_path(
         amendment,
         "test.pdf"
     )
     self.assertEqual(file_path, file_path_old.replace("//", "/"))
Ejemplo n.º 12
0
 def test_invalid_date(self):
     agreement = AgreementFactory()
     AgreementAmendmentFactory(agreement=agreement,
                               signed_amendment='fake.pdf')
     self.assertFalse(agreements.amendments_valid(agreement))
Ejemplo n.º 13
0
 def test_invalid_name(self):
     agreement = AgreementFactory()
     AgreementAmendmentFactory(agreement=agreement, )
     self.assertFalse(agreements.amendments_valid(agreement))