@@ -1274,6 +1274,8 @@ def test_status_transition(self):
12741274 response = self .client .post (self .url , data , format = "json" )
12751275 self .assertEqual (response .status_code , 200 , response .data )
12761276 self .assertEqual (response .data ["status" ], EAPStatus .UNDER_REVIEW )
1277+ simplified_eap .refresh_from_db ()
1278+ self .assertTrue (simplified_eap .is_locked )
12771279
12781280 # NOTE: Check if the NS can update after changing to UNDER_REVIEW
12791281 # FAILS: As simplified EAP is in UNDER_REVIEW, cannot update
@@ -1283,6 +1285,7 @@ def test_status_transition(self):
12831285 "readiness_budget" : 5000 ,
12841286 "pre_positioning_budget" : 5000 ,
12851287 "early_action_budget" : 5000 ,
1288+ "modified_at" : datetime .now (),
12861289 }
12871290 url = f"/api/v2/simplified-eap/{ simplified_eap .id } /"
12881291 response = self .client .patch (url , update_data , format = "json" )
@@ -1321,12 +1324,25 @@ def test_status_transition(self):
13211324 self .eap_registration .latest_simplified_eap .review_checklist_file ,
13221325 )
13231326
1327+ # Fails, As NS has to revise the EAP before transitioning to UNDER_REVIEW.
1328+ status_data = {
1329+ "status" : EAPStatus .UNDER_REVIEW ,
1330+ }
1331+ response = self .client .post (self .url , status_data )
1332+ self .assertEqual (response .status_code , 400 , response .data )
1333+
1334+ # Fails, As User only can revise after NS_ADDRESSING_COMMENTS, cannot update directly as it's locked
1335+ update_data ["modified_at" ] = datetime .now ()
1336+ response = self .client .patch (url , update_data , format = "json" )
1337+ self .assertEqual (response .status_code , 400 , response .data )
1338+
13241339 # NOTE: NS revise which creates a snapshot of simplified eap
13251340 # updates the latest simplified eap with updated checklist file. So, there should be two snapshots of SimplifiedEAP now.
13261341 revise_url = f"/api/v2/simplified-eap/{ simplified_eap .id } /revise/"
13271342 self .authenticate (self .country_admin )
13281343 response = self .client .post (revise_url )
1329- self .assertEqual (response .status_code , 200 )
1344+ self .assertEqual (response .status_code , 200 , response .data )
1345+ self .assertFalse (response .data ["is_locked" ], response .data )
13301346
13311347 # NOTE: Check if snapshot is created or not
13321348 # First SimplifedEAP should be locked
@@ -1371,13 +1387,21 @@ def test_status_transition(self):
13711387 self .eap_registration .latest_simplified_eap .id ,
13721388 second_snapshot .id ,
13731389 )
1390+ # Second snapshot should not be locked.
1391+ self .assertFalse (second_snapshot .is_locked , "Latest snapshot shouldn't be locked." ),
13741392
1375- # NOTE: Cannot create another snapshot from locked snapshot
1393+ # NOTE: Cannot create revise as this eap has already been revised once.
13761394 revise_url = f"/api/v2/simplified-eap/{ simplified_eap .id } /revise/"
13771395 self .authenticate (self .country_admin )
13781396 response = self .client .post (revise_url )
13791397 self .assertEqual (response .status_code , 400 , response .data )
13801398
1399+ # NOTE: Cannot update in previous snapshot
1400+ url = f"/api/v2/simplified-eap/{ simplified_eap .id } /"
1401+ update_data ["modified_at" ] = datetime .now ()
1402+ response = self .client .patch (url , update_data , format = "json" )
1403+ self .assertEqual (response .status_code , 400 , response .data )
1404+
13811405 # NOTE: Transition to UNDER_REVIEW
13821406 # NS_ADDRESSING_COMMENTS -> UNDER_REVIEW
13831407 data = {
@@ -1411,6 +1435,8 @@ def test_status_transition(self):
14111435 response = self .client .post (self .url , data , format = "json" )
14121436 self .assertEqual (response .status_code , 200 , response .data )
14131437 self .assertEqual (response .data ["status" ], EAPStatus .UNDER_REVIEW )
1438+ second_snapshot .refresh_from_db ()
1439+ self .assertTrue (second_snapshot .is_locked , "Should be locked after transition to UNDER_REVIEW." )
14141440
14151441 # AGAIN NOTE: Transition to NS_ADDRESSING_COMMENTS
14161442 # UNDER_REVIEW -> NS_ADDRESSING_COMMENTS
@@ -1433,10 +1459,23 @@ def test_status_transition(self):
14331459 self .assertEqual (response .status_code , 200 , response .data )
14341460 self .assertEqual (response .data ["status" ], EAPStatus .NS_ADDRESSING_COMMENTS )
14351461
1462+ # Fails, As NS has to revise the EAP before transitioning to UNDER_REVIEW.
1463+ status_data = {
1464+ "status" : EAPStatus .UNDER_REVIEW ,
1465+ }
1466+ response = self .client .post (self .url , status_data )
1467+ self .assertEqual (response .status_code , 400 , response .data )
1468+
1469+ # Cannot update as it is in NS_ADDRESSING_COMMENTS, only revise is allowed
1470+ update_data ["modified_at" ] = datetime .now ()
1471+ response = self .client .patch (url , update_data , format = "json" )
1472+ self .assertEqual (response .status_code , 400 , response .data )
1473+
14361474 revise_url = f"/api/v2/simplified-eap/{ second_snapshot .id } /revise/"
14371475 self .authenticate (self .country_admin )
14381476 response = self .client .post (revise_url )
1439- self .assertEqual (response .status_code , 200 )
1477+ self .assertEqual (response .status_code , 200 , response .data )
1478+ self .assertFalse (response .data ["is_locked" ])
14401479
14411480 # Check if three snapshots are created now
14421481 self .eap_registration .refresh_from_db ()
@@ -1482,12 +1521,18 @@ def test_status_transition(self):
14821521 third_snapshot .id ,
14831522 )
14841523
1485- # NOTE: Cannot create another snapshot from locked snapshot
1524+ # NOTE: Cannot create another snapshot as this eap has already been revised
14861525 revise_url = f"/api/v2/simplified-eap/{ second_snapshot .id } /revise/"
14871526 self .authenticate (self .country_admin )
14881527 response = self .client .post (revise_url )
14891528 self .assertEqual (response .status_code , 400 , response .data )
14901529
1530+ # NOTE: Cannot update the previous snapshot
1531+ url = f"/api/v2/simplified-eap/{ second_snapshot .id } /"
1532+ update_data ["modified_at" ] = datetime .now ()
1533+ response = self .client .patch (url , update_data , format = "json" )
1534+ self .assertEqual (response .status_code , 400 , response .data )
1535+
14911536 # NOTE: Again Transition to UNDER_REVIEW
14921537 # NS_ADDRESSING_COMMENTS -> UNDER_REVIEW
14931538 data = {
@@ -1556,6 +1601,13 @@ def test_status_transition(self):
15561601 self .assertEqual (response .status_code , 200 , response .data )
15571602 self .assertEqual (response .data ["status" ], EAPStatus .NS_ADDRESSING_COMMENTS )
15581603
1604+ # Fails, As NS has to revise the EAP before transitioning to UNDER_REVIEW.
1605+ status_data = {
1606+ "status" : EAPStatus .UNDER_REVIEW ,
1607+ }
1608+ response = self .client .post (self .url , status_data )
1609+ self .assertEqual (response .status_code , 400 , response .data )
1610+
15591611 revise_url = f"/api/v2/simplified-eap/{ third_snapshot .id } /revise/"
15601612 self .authenticate (self .country_admin )
15611613 response = self .client .post (revise_url )
@@ -1706,7 +1758,7 @@ def test_status_transition(self):
17061758 # FAILS As simplified EAP is in PENDING_PFA, cannot updated
17071759 url = f"/api/v2/simplified-eap/{ simplified_eap .id } /"
17081760 response = self .client .patch (url , update_data , format = "json" )
1709- self .assertEqual (response .status_code , 400 )
1761+ self .assertEqual (response .status_code , 400 , response . data )
17101762
17111763 # NOTE: Transition to APPROVED
17121764 # PENDING_PFA -> APPROVED
@@ -1736,7 +1788,7 @@ def test_status_transition(self):
17361788 self .authenticate (self .country_admin )
17371789 url = f"/api/v2/simplified-eap/{ simplified_eap .id } /"
17381790 response = self .client .patch (url , update_data , format = "json" )
1739- self .assertEqual (response .status_code , 400 )
1791+ self .assertEqual (response .status_code , 400 , response . data )
17401792
17411793 @mock .patch ("eap.serializers.generate_export_eap_pdf" )
17421794 @mock .patch ("eap.serializers.group" )
0 commit comments