Skip to content

Commit

Permalink
validation and tests for unfunded toggle and capacity strenghtening u…
Browse files Browse the repository at this point in the history
…nfunded cash
  • Loading branch information
emaciupe committed Jun 7, 2023
1 parent a2dd41f commit 2950de3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
55 changes: 55 additions & 0 deletions src/etools/applications/partners/tests/test_v3_interventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2950de3

Please sign in to comment.