Skip to content

Commit 28e59da

Browse files
committed
fix(eap): Replace update checklist file to EAPFile
1 parent b9cd852 commit 28e59da

4 files changed

Lines changed: 75 additions & 36 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Generated by Django 4.2.26 on 2025-12-15 06:33
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
("eap", "0010_eapaction_eapimpact_indicator_and_more"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="fulleap",
15+
name="updated_checklist_file",
16+
field=models.ForeignKey(
17+
blank=True,
18+
null=True,
19+
on_delete=django.db.models.deletion.SET_NULL,
20+
to="eap.eapfile",
21+
verbose_name="Updated Review Checklist File",
22+
),
23+
),
24+
migrations.AlterField(
25+
model_name="simplifiedeap",
26+
name="updated_checklist_file",
27+
field=models.ForeignKey(
28+
blank=True,
29+
null=True,
30+
on_delete=django.db.models.deletion.SET_NULL,
31+
to="eap.eapfile",
32+
verbose_name="Updated Review Checklist File",
33+
),
34+
),
35+
]

eap/models.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -879,9 +879,10 @@ class CommonEAPFields(models.Model):
879879
)
880880

881881
# Review Checklist
882-
updated_checklist_file = SecureFileField(
883-
verbose_name=_("Updated Checklist File"),
884-
upload_to="eap/files/",
882+
updated_checklist_file = models.ForeignKey[EAPFile | None, EAPFile | None](
883+
EAPFile,
884+
on_delete=models.SET_NULL,
885+
verbose_name=_("Updated Review Checklist File"),
885886
null=True,
886887
blank=True,
887888
)

eap/serializers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,8 @@ def validate_updated_checklist_file(self, file):
427427
if file is None:
428428
return
429429

430-
validate_file_extention(file.name, ALLOWED_FILE_EXTENTIONS)
431-
validate_file_type(file)
430+
validate_file_extention(file.file.name, ALLOWED_FILE_EXTENTIONS)
431+
validate_file_type(file.file)
432432
return file
433433

434434
def validate_images_field(self, field_name, images):

eap/test_views.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ def test_status_transition(self):
12451245
)
12461246
# Snapshot Shouldn't have the updated checklist file
12471247
self.assertFalse(
1248-
second_snapshot.updated_checklist_file.name,
1248+
second_snapshot.updated_checklist_file,
12491249
"Latest Snapshot shouldn't have the updated checklist file.",
12501250
)
12511251
# Check if the latest_simplified_eap is updated in EAPRegistration
@@ -1268,14 +1268,18 @@ def test_status_transition(self):
12681268
# Upload updated checklist file
12691269
# UPDATES on the second snapshot
12701270
url = f"/api/v2/simplified-eap/{second_snapshot.id}/"
1271-
with tempfile.NamedTemporaryFile(suffix=".xlsx") as tmp_file:
1272-
tmp_file.write(b"Updated Test content")
1273-
tmp_file.seek(0)
1274-
1275-
file_data = {"eap_registration": second_snapshot.eap_registration_id, "updated_checklist_file": tmp_file}
1271+
checklist_file_instance = EAPFileFactory._create_file(
1272+
created_by=self.country_admin,
1273+
modified_by=self.country_admin,
1274+
)
1275+
file_data = {
1276+
"prioritized_hazard_and_impact": "Floods with potential heavy impact.",
1277+
"eap_registration": second_snapshot.eap_registration_id,
1278+
"updated_checklist_file": checklist_file_instance.id,
1279+
}
12761280

1277-
response = self.client.patch(url, file_data, format="multipart")
1278-
self.assertEqual(response.status_code, 200, response.data)
1281+
response = self.client.patch(url, file_data, format="json")
1282+
self.assertEqual(response.status_code, 200, response.data)
12791283

12801284
# SUCCESS:
12811285
self.authenticate(self.country_admin)
@@ -1336,7 +1340,7 @@ def test_status_transition(self):
13361340
self.assertTrue(second_snapshot.is_locked)
13371341
# Snapshot Shouldn't have the updated checklist file
13381342
self.assertFalse(
1339-
third_snapshot.updated_checklist_file.name,
1343+
third_snapshot.updated_checklist_file,
13401344
"Latest snapshot shouldn't have the updated checklist file.",
13411345
)
13421346

@@ -1356,14 +1360,17 @@ def test_status_transition(self):
13561360
# Upload updated checklist file
13571361
# UPDATES on the second snapshot
13581362
url = f"/api/v2/simplified-eap/{third_snapshot.id}/"
1359-
with tempfile.NamedTemporaryFile(suffix=".xlsx") as tmp_file:
1360-
tmp_file.write(b"Updated Test content")
1361-
tmp_file.seek(0)
1362-
1363-
file_data = {"eap_registration": third_snapshot.eap_registration_id, "updated_checklist_file": tmp_file}
1363+
file_data = {
1364+
"prioritized_hazard_and_impact": "Floods with potential heavy impact.",
1365+
"risks_selected_protocols": "Protocol A and Protocol B.",
1366+
"selected_early_actions": "The early actions selected.",
1367+
"overall_objective_intervention": "To reduce risks through early actions.",
1368+
"eap_registration": third_snapshot.eap_registration_id,
1369+
"updated_checklist_file": checklist_file_instance.id,
1370+
}
13641371

1365-
response = self.client.patch(url, file_data, format="multipart")
1366-
self.assertEqual(response.status_code, 200)
1372+
response = self.client.patch(url, file_data, format="json")
1373+
self.assertEqual(response.status_code, 200)
13671374

13681375
# SUCCESS:
13691376
self.authenticate(self.country_admin)
@@ -1444,7 +1451,7 @@ def test_status_transition(self):
14441451
self.assertTrue(third_snapshot.is_locked)
14451452
# Snapshot Shouldn't have the updated checklist file
14461453
self.assertFalse(
1447-
fourth_snapshot.updated_checklist_file.name,
1454+
fourth_snapshot.updated_checklist_file,
14481455
"Latest snapshot shouldn't have the updated checklist file.",
14491456
)
14501457

@@ -1466,21 +1473,17 @@ def test_status_transition(self):
14661473
# Upload updated checklist file
14671474
# UPDATES on the second snapshot
14681475
url = f"/api/v2/simplified-eap/{fourth_snapshot.id}/"
1469-
with tempfile.NamedTemporaryFile(suffix=".xlsx") as tmp_file:
1470-
tmp_file.write(b"Updated Test content")
1471-
tmp_file.seek(0)
1476+
file_data = {
1477+
"prioritized_hazard_and_impact": "Floods with potential heavy impact.",
1478+
"risks_selected_protocols": "Protocol A and Protocol B.",
1479+
"selected_early_actions": "The early actions selected.",
1480+
"overall_objective_intervention": "To reduce risks through early actions.",
1481+
"eap_registration": third_snapshot.eap_registration_id,
1482+
"updated_checklist_file": checklist_file_instance.id,
1483+
}
14721484

1473-
file_data = {
1474-
"prioritized_hazard_and_impact": "Floods with potential heavy impact.",
1475-
"risks_selected_protocols": "Protocol A and Protocol B.",
1476-
"selected_early_actions": "The early actions selected.",
1477-
"overall_objective_intervention": "To reduce risks through early actions.",
1478-
"eap_registration": third_snapshot.eap_registration_id,
1479-
"updated_checklist_file": tmp_file,
1480-
}
1481-
1482-
response = self.client.patch(url, file_data, format="multipart")
1483-
self.assertEqual(response.status_code, 200)
1485+
response = self.client.patch(url, file_data, format="json")
1486+
self.assertEqual(response.status_code, 200)
14841487

14851488
# SUCCESS:
14861489
self.authenticate(self.country_admin)

0 commit comments

Comments
 (0)