Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
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)
     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()
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 def test_save_model_update(self):
     self.assertFalse(Activity.objects.exists())
     sa = PartnerStaffMemberAdmin(PartnerStaffMember, self.site)
     obj = PartnerStaffFactory(partner=self.partner)
     email_before = obj.email
     obj.email = "*****@*****.**"
     sa.save_model(self.request, obj, {}, True)
     self.assertTrue(
         Activity.objects.filter(action=Activity.UPDATE).exists())
     activity = Activity.objects.first()
     self.assertEqual(activity.target, obj)
     self.assertEqual(activity.by_user, self.user)
     self.assertDictEqual(
         activity.change,
         {"email": {
             "before": email_before,
             "after": "*****@*****.**"
         }})
Ejemplo n.º 6
0
 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())
Ejemplo n.º 7
0
 def test_save_model_update(self):
     self.assertFalse(Activity.objects.exists())
     sa = PartnerStaffMemberAdmin(PartnerStaffMember, self.site)
     obj = PartnerStaffFactory(partner=self.partner)
     email_before = obj.email
     obj.email = "*****@*****.**"
     sa.save_model(self.request, obj, {}, True)
     self.assertTrue(
         Activity.objects.filter(action=Activity.UPDATE).exists()
     )
     activity = Activity.objects.first()
     self.assertEqual(activity.target, obj)
     self.assertEqual(activity.by_user, self.user)
     self.assertDictEqual(activity.change, {
         "email": {
             "before": email_before,
             "after": "*****@*****.**"
         }
     })
Ejemplo n.º 8
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=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, )
Ejemplo n.º 9
0
 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())
Ejemplo n.º 10
0
 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))
Ejemplo n.º 11
0
 def test_clean_email_change(self):
     """Email address may not be changed"""
     self.data["email"] = "*****@*****.**"
     partner = PartnerFactory()
     staff = PartnerStaffFactory(
         partner=partner,
         email="*****@*****.**",
     )
     form = forms.PartnerStaffMemberForm(self.data, instance=staff)
     self.assertFalse(form.is_valid())
     self.assertIn(
         "User emails cannot be changed, please remove the user and add another one: [email protected]",
         form.errors["__all__"])
Ejemplo n.º 12
0
 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.partner_staff = PartnerStaffFactory(partner=cls.partner)
     cls.partnership_manager_user = UserFactory(is_staff=True)
     cls.partnership_manager_user.groups.add(GroupFactory())
     cls.partnership_manager_user.profile.partner_staff_member = cls.partner_staff.id
     cls.partnership_manager_user.save()
Ejemplo n.º 13
0
 def test_clean_activate_invalid(self):
     """If staff member made active, invalid if user already associated
     with another partner
     """
     profile = ProfileFactory(partner_staff_member=10, )
     partner = PartnerFactory()
     staff = PartnerStaffFactory(partner=partner,
                                 email=profile.user.email,
                                 active=False)
     self.data["email"] = profile.user.email
     form = forms.PartnerStaffMemberForm(self.data, instance=staff)
     self.assertFalse(form.is_valid())
     self.assertIn(
         "The Partner Staff member you are trying to activate is associated with a different partnership",
         form.errors["active"])
Ejemplo n.º 14
0
    def test_invalid(self):
        tomorrow = datetime.date.today() + datetime.timedelta(days=1)
        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=tomorrow,
            partner_manager=staff,
        )

        with self.assertRaises(BasicValidationError):
            self.assertFalse(agreements.signatures_valid(agreement))
Ejemplo n.º 15
0
 def test_jsonify_unicode(self):
     staff = PartnerStaffFactory(first_name=u'R\xe4dda')
     agreement = AgreementFactory(agreement_type=u'R\xe4dda')
     agreement.authorized_officers.add(staff)
     j = utils.jsonify(model_to_dict(agreement))
     self.assertEqual(j["agreement_type"], agreement.agreement_type)
 def setUpTestData(cls):
     cls.unicef_user = UserFactory()
     cls.partner_user = PartnerStaffFactory()
     cls.future_date = datetime.date.today() + datetime.timedelta(days=2)
Ejemplo n.º 17
0
    def test_create_ok_and_fail_due_to_signatures_non_SSFA(self):
        """Ensure signature validation works correctly for non-SSFA types"""
        signatory = UserFactory()
        partner_signatory = PartnerStaffFactory(partner=self.partner)

        # This should succeed; it's OK to have only one set of signatures (UNICEF)
        data = {
            "agreement_type": Agreement.MOU,
            "partner": self.partner.id,
            "signed_by_unicef_date": self.today,
            "signed_by": signatory.id,
            "reference_number_year": datetime.date.today().year
        }
        serializer = AgreementCreateUpdateSerializer(data=data)
        serializer.context['request'] = self.fake_request

        self.assertTrue(serializer.is_valid(raise_exception=True))

        # This should succeed; it's OK to have only one set of signatures (partner)
        data = {
            "agreement_type": Agreement.MOU,
            "partner": self.partner.id,
            "signed_by_partner_date": self.today,
            "signed_by": signatory.id,
            "partner_manager": partner_signatory.id,
            "reference_number_year": datetime.date.today().year
        }
        serializer = AgreementCreateUpdateSerializer(data=data)
        serializer.context['request'] = self.fake_request

        self.assertTrue(serializer.is_valid(raise_exception=True))

        # This should succeed; it's OK to have both sets of signatures (UNICEF & partner)
        data = {
            "agreement_type": Agreement.MOU,
            "partner": self.partner.id,
            "signed_by_unicef_date": self.today,
            "signed_by": signatory.id,
            "signed_by_partner_date": self.today,
            "partner_manager": partner_signatory.id,
            "reference_number_year": datetime.date.today().year
        }
        serializer = AgreementCreateUpdateSerializer(data=data)
        serializer.context['request'] = self.fake_request

        self.assertTrue(serializer.is_valid(raise_exception=True))

        # This should fail because signed_by_unicef_date and signed_by are both set, but the signed by date is
        # in the future.
        data = {
            "agreement_type": Agreement.MOU,
            "partner": self.partner,
            "signed_by_unicef_date": self.today + datetime.timedelta(days=5),
            "signed_by": signatory,
            "reference_number_year": datetime.date.today().year
        }

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

        self.assertSimpleExceptionFundamentals(
            context_manager,
            'None of the signatures can be dated in the future')

        # This should fail because signed_by_partner_date and partner_manager are both set, but the signed by date is
        # in the future.
        data = {
            "agreement_type": Agreement.MOU,
            "partner": self.partner,
            "signed_by_partner_date": self.today + datetime.timedelta(days=5),
            "partner_manager": partner_signatory,
            "reference_number_year": datetime.date.today().year
        }

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

        self.assertSimpleExceptionFundamentals(
            context_manager,
            'None of the signatures can be dated in the future')