From 2950de38532816317882eb82e56dc160a5d4bf53 Mon Sep 17 00:00:00 2001 From: Ema Ciupe Date: Wed, 7 Jun 2023 15:38:42 +0300 Subject: [PATCH] validation and tests for unfunded toggle and capacity strenghtening unfunded cash --- .../partners/serializers/interventions_v2.py | 5 ++ .../partners/tests/test_v3_interventions.py | 55 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/etools/applications/partners/serializers/interventions_v2.py b/src/etools/applications/partners/serializers/interventions_v2.py index 30d4c74b9..dc9eb3ed2 100644 --- a/src/etools/applications/partners/serializers/interventions_v2.py +++ b/src/etools/applications/partners/serializers/interventions_v2.py @@ -97,6 +97,11 @@ class Meta: "total_supply" ) + def validate_unfunded_cash_local(self, value): + if value and not self.instance.has_unfunded_cash: + raise serializers.ValidationError(_('This programme document does not include unfunded amounts')) + return value + def get_intervention(self): return self.validated_data['intervention'] diff --git a/src/etools/applications/partners/tests/test_v3_interventions.py b/src/etools/applications/partners/tests/test_v3_interventions.py index 03f77a761..c15fb0545 100644 --- a/src/etools/applications/partners/tests/test_v3_interventions.py +++ b/src/etools/applications/partners/tests/test_v3_interventions.py @@ -813,6 +813,61 @@ def test_patch_currency(self): budget.refresh_from_db() self.assertEqual(budget.currency, "PEN") + def test_patch_has_unfunded_cash(self): + intervention = InterventionFactory() + intervention.unicef_focal_points.add(self.unicef_user) + budget = intervention.planned_budget + self.assertFalse(budget.has_unfunded_cash) + + response = self.forced_auth_req( + "patch", + reverse('pmp_v3:intervention-detail', args=[intervention.pk]), + user=self.unicef_user, + data={'planned_budget': { + "id": budget.pk, + "has_unfunded_cash": True, + }} + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + budget.refresh_from_db() + self.assertTrue(budget.has_unfunded_cash) + + def test_patch_unfunded_cash_local(self): + intervention = InterventionFactory() + intervention.unicef_focal_points.add(self.unicef_user) + budget = intervention.planned_budget + self.assertEqual(budget.unfunded_cash_local, 0) + + response = self.forced_auth_req( + "patch", + reverse('pmp_v3:intervention-detail', args=[intervention.pk]), + user=self.unicef_user, + data={'planned_budget': { + "id": budget.pk, + "unfunded_cash_local": 1234, + }} + ) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertIn( + 'This programme document does not include unfunded amounts', + response.data['planned_budget']['unfunded_cash_local'] + ) + budget.has_unfunded_cash = True + budget.save(update_fields=['has_unfunded_cash']) + + response = self.forced_auth_req( + "patch", + reverse('pmp_v3:intervention-detail', args=[intervention.pk]), + user=self.unicef_user, + data={'planned_budget': { + "id": budget.pk, + "unfunded_cash_local": 1234, + }} + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + budget.refresh_from_db() + self.assertEqual(budget.unfunded_cash_local, 1234) + def test_patch_country_programme(self): intervention = InterventionFactory() agreement = intervention.agreement