-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test cases for dref imminent and purposed_action
- Loading branch information
Showing
1 changed file
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,14 +7,21 @@ | |
from django.contrib.contenttypes.models import ContentType | ||
|
||
from api.models import Country, DisasterType, District, Region, RegionName | ||
from deployments.factories.project import SectorFactory | ||
from deployments.factories.user import UserFactory | ||
from dref.factories.dref import ( | ||
DrefFactory, | ||
DrefFileFactory, | ||
DrefFinalReportFactory, | ||
DrefOperationalUpdateFactory, | ||
) | ||
from dref.models import Dref, DrefFile, DrefFinalReport, DrefOperationalUpdate | ||
from dref.models import ( | ||
Dref, | ||
DrefFile, | ||
DrefFinalReport, | ||
DrefOperationalUpdate, | ||
ProposedAction, | ||
) | ||
from dref.tasks import send_dref_email | ||
from main.test_case import APITestCase | ||
|
||
|
@@ -1247,3 +1254,79 @@ def test_dref_share_users(self): | |
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(len(response.data["results"]), 1) | ||
self.assertEqual(set(response.data["results"][0]["users"]), set([user2.id, user3.id, user4.id])) | ||
|
||
def test_dref_imminent(self): | ||
old_count = Dref.objects.count() | ||
sct_1 = SectorFactory( | ||
title="shelter_housing_and_settlements", | ||
) | ||
sct_2 = SectorFactory( | ||
title="health", | ||
) | ||
national_society = Country.objects.create(name="abc") | ||
disaster_type = DisasterType.objects.create(name="abc") | ||
data = { | ||
"title": "Dref test title", | ||
"type_of_onset": Dref.OnsetType.SUDDEN.value, | ||
"type_of_dref": Dref.DrefType.IMMINENT, | ||
"disaster_category": Dref.DisasterCategory.YELLOW.value, | ||
"status": Dref.Status.IN_PROGRESS.value, | ||
"num_assisted": 5666, | ||
"num_affected": 23, | ||
"amount_requested": 127771111, | ||
"women": 344444, | ||
"men": 5666, | ||
"girls": 22, | ||
"boys": 344, | ||
"appeal_manager_name": "Test Name", | ||
"ifrc_emergency_email": "[email protected]", | ||
"is_surge_personnel_deployed": False, | ||
"originator_email": "[email protected]", | ||
"national_society": national_society.id, | ||
"disaster_type": disaster_type.id, | ||
"planned_interventions": [ | ||
{ | ||
"title": "shelter_housing_and_settlements", | ||
"description": "matrix", | ||
"budget": 23444, | ||
"male": 12222, | ||
"female": 2255, | ||
"indicators": [ | ||
{ | ||
"title": "test_title", | ||
"actual": 21232, | ||
"target": 44444, | ||
} | ||
], | ||
}, | ||
], | ||
"proposed_action": [ | ||
{ | ||
"proposed_type": ProposedAction.Action.EARLY_ACTION.value, | ||
"activity": sct_1.id, | ||
"budget": 70000, | ||
}, | ||
{ | ||
"proposed_type": ProposedAction.Action.EARLY_RESPONSE.value, | ||
"activity": sct_2.id, | ||
"budget": 5000, | ||
}, | ||
], | ||
"sub_total": 75000, | ||
"indirect_cost": 5000, | ||
"total": 80000, | ||
} | ||
url = "/api/v2/dref/" | ||
self.client.force_authenticate(self.user) | ||
response = self.client.post(url, data, format="json") | ||
self.assert_201(response) | ||
self.assertEqual(Dref.objects.count(), old_count + 1) | ||
|
||
# Checking for surge personnel deployed | ||
data["is_surge_personnel_deployed"] = True | ||
data["surge_deployment_cost"] = 10000 | ||
data["indirect_cost"] = 5800 | ||
data["total"] = 90800 | ||
response = self.client.post(url, data, format="json") | ||
self.assert_201(response) | ||
self.assertEqual(Dref.objects.count(), old_count + 2) |