Skip to content

Commit 4782d36

Browse files
committed
feat(dref): Add test cases for new final report changes
1 parent 4af5a08 commit 4782d36

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

dref/serializers.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,16 @@ def create(self, validated_data):
12321232
DrefOperationalUpdate.objects.filter(dref=dref, is_published=True).order_by("-operational_update_number").first()
12331233
)
12341234
validated_data["created_by"] = self.context["request"].user
1235+
# NOTE: Checks and common fields for the new dref final reports of new dref imminents
1236+
if dref.type_of_dref == Dref.DrefType.IMMINENT and dref.is_dref_imminent_v2:
1237+
validated_data["is_dref_imminent_v2"] = True
1238+
validated_data["sub_total_cost"] = dref.sub_total_cost
1239+
validated_data["surge_deployment_cost"] = dref.surge_deployment_cost
1240+
validated_data["surge_deployment_expenditure_cost"] = dref.surge_deployment_cost
1241+
validated_data["indirect_cost"] = dref.indirect_cost
1242+
validated_data["indirect_expenditure_cost"] = dref.indirect_cost
1243+
validated_data["total_cost"] = dref.total_cost
1244+
12351245
if dref_operational_update:
12361246
validated_data["title"] = dref_operational_update.title
12371247
validated_data["title_prefix"] = dref_operational_update.title_prefix
@@ -1360,6 +1370,8 @@ def create(self, validated_data):
13601370
dref_final_report.risk_security.add(*dref_operational_update.risk_security.all())
13611371
dref_final_report.users.add(*dref_operational_update.users.all())
13621372
dref_final_report.source_information.add(*dref_operational_update.source_information.all())
1373+
if dref_final_report.is_dref_imminent_v2:
1374+
dref_final_report.proposed_action.add(*dref.proposed_action.all())
13631375
else:
13641376
validated_data["title"] = dref.title
13651377
validated_data["title_prefix"] = dref.title_prefix
@@ -1456,15 +1468,6 @@ def create(self, validated_data):
14561468
raise serializers.ValidationError(
14571469
gettext("Can't create final report for dref type %s" % Dref.DrefType.LOAN.label)
14581470
)
1459-
# NOTE: Checks for the new dref final reports of new dref imminents
1460-
if validated_data["type_of_dref"] == Dref.DrefType.IMMINENT and dref.is_dref_imminent_v2:
1461-
validated_data["is_dref_imminent_v2"] = True
1462-
validated_data["sub_total_cost"] = dref.sub_total_cost
1463-
validated_data["surge_deployment_cost"] = dref.surge_deployment_cost
1464-
validated_data["surge_deployment_expenditure_cost"] = dref.surge_deployment_cost
1465-
validated_data["indirect_cost"] = dref.indirect_cost
1466-
validated_data["indirect_expenditure_cost"] = dref.indirect_cost
1467-
validated_data["total_cost"] = dref.total_cost
14681471

14691472
# NOTE: Checks for the new dref final reports of new dref imminents
14701473
if validated_data["type_of_dref"] == Dref.DrefType.IMMINENT and dref.is_dref_imminent_v2:

dref/test_views.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,8 +1640,10 @@ def test_dref_imminent_v2_final_report(self):
16401640
is_published=True,
16411641
is_dref_imminent_v2=True,
16421642
sub_total_cost=75000,
1643-
indirect_cost=5000,
1644-
total_cost=80000,
1643+
indirect_cost=5800,
1644+
is_surge_personnel_deployed=True,
1645+
surge_deployment_cost=10000,
1646+
total_cost=90800,
16451647
)
16461648
dref1.proposed_action.set([proposed_action_1, proposed_action_2])
16471649
url = "/api/v2/dref-final-report/"
@@ -1663,11 +1665,15 @@ def test_dref_imminent_v2_final_report(self):
16631665
response.data["sub_total_cost"],
16641666
response.data["indirect_cost"],
16651667
response.data["total_cost"],
1668+
response.data["surge_deployment_expenditure_cost"],
1669+
response.data["indirect_expenditure_cost"],
16661670
},
16671671
{
16681672
dref1.sub_total_cost,
16691673
dref1.indirect_cost,
16701674
dref1.total_cost,
1675+
dref1.surge_deployment_cost,
1676+
dref1.indirect_cost,
16711677
},
16721678
)
16731679

@@ -1688,8 +1694,8 @@ def test_dref_imminent_v2_final_report(self):
16881694
],
16891695
"sub_total_expenditure_cost": 55000,
16901696
"surge_deployment_expenditure_cost": 10000,
1691-
"indirect_expenditure_cost": 5000,
1692-
"total_expenditure_cost": 60000,
1697+
"indirect_expenditure_cost": 5800,
1698+
"total_expenditure_cost": 70800,
16931699
}
16941700
url = f"/api/v2/dref-final-report/{response.data['id']}/"
16951701
response = self.client.patch(url, data=data)
@@ -1761,6 +1767,27 @@ def test_dref_imminent_v2_final_report(self):
17611767
self.assert_201(response)
17621768
self.assertEqual(response.data["type_of_dref"], Dref.DrefType.IMMINENT)
17631769

1770+
# Update existing dref final report
1771+
url = f"/api/v2/dref-final-report/{response.data['id']}/"
1772+
data = {
1773+
"title": "Old Title",
1774+
"modified_at": datetime.now(),
1775+
}
1776+
response = self.client.patch(url, data=data)
1777+
self.assert_200(response)
1778+
self.assertEqual(
1779+
{
1780+
response.data["title"],
1781+
response.data["type_of_dref"],
1782+
response.data["is_dref_imminent_v2"],
1783+
},
1784+
{
1785+
data["title"],
1786+
Dref.DrefType.IMMINENT,
1787+
False, # is_dref_imminent_v2 should be False for existing Dref of type IMMINENT
1788+
},
1789+
)
1790+
17641791

17651792
User = get_user_model()
17661793

0 commit comments

Comments
 (0)