44from django .contrib .auth .models import User
55
66from main .test_case import APITestCase
7- from eap .models import EAP , EarlyAction , EAPActivationReport , Action
7+ from eap .models import (
8+ EAP ,
9+ EarlyAction ,
10+ EAPActivationReport ,
11+ Action ,
12+ EarlyActionIndicator ,
13+ )
814
915from api .factories .country import CountryFactory
1016from api .factories .district import DistrictFactory
@@ -174,11 +180,19 @@ def setUp(self):
174180 "prepo_activities_achievements" : "test" ,
175181 "early_actions_achievements" : [
176182 {
177- "early_act_achievement" : "test"
183+ "early_act_achievement" : "test 1 "
178184 },
179185 {
180186 "early_act_achievement" : "test 2"
181187 }
188+ ],
189+ "indicators" : [
190+ {
191+ "indicator_value" : 200
192+ },
193+ {
194+ "indicator_value" : 300
195+ }
182196 ]
183197 },
184198 ]
@@ -264,12 +278,17 @@ def test_create_and_update_eap_activation_report(self):
264278 self .client .force_authenticate (user = self .user )
265279 # create eap
266280 with self .capture_on_commit_callbacks (execute = True ):
267- self .client .post ('/api/v2/eap/' , self .body , format = 'json' ).json ()
268- actions = Action .objects .all ().values_list ('id' , flat = True )
269- early_actions = EarlyAction .objects .all ().values_list ('id' , flat = True )
270- self .eap_act_report_body ['operational_plans' ][0 ]['early_action' ] = early_actions [0 ]
281+ eap_resp = self .client .post ('/api/v2/eap/' , self .body , format = 'json' ).json ()
282+ early_action = EarlyAction .objects .get (id = eap_resp ['early_actions' ][0 ]['id' ])
283+
284+ actions = list (Action .objects .filter (early_action = early_action ).values_list ('id' , flat = True ))
285+ actions_indicators = early_action .indicators .all ().values_list ('id' , flat = True )
286+ self .eap_act_report_body ['operational_plans' ][0 ]['early_action' ] = early_action .id
271287 self .eap_act_report_body ['operational_plans' ][0 ]['early_actions_achievements' ][0 ]['action' ] = actions [0 ]
272288 self .eap_act_report_body ['operational_plans' ][0 ]['early_actions_achievements' ][1 ]['action' ] = actions [1 ]
289+
290+ self .eap_act_report_body ['operational_plans' ][0 ]['indicators' ][0 ]['indicator' ] = actions_indicators [0 ]
291+ self .eap_act_report_body ['operational_plans' ][0 ]['indicators' ][1 ]['indicator' ] = actions_indicators [1 ]
273292 # create eap_report
274293 with self .capture_on_commit_callbacks (execute = True ):
275294 final_report_resp = self .client .post (
@@ -283,3 +302,54 @@ def test_create_and_update_eap_activation_report(self):
283302 self .assertEqual (final_report_resp ['ifrc_financial_report' ], self .document1 .id )
284303 self .assertEqual (len (final_report_resp ['documents' ]), 2 )
285304 self .assertEqual (len (final_report_resp ['operational_plans' ]), 1 )
305+ self .assertEqual (len (final_report_resp ['operational_plans' ][0 ]['early_actions_achievements' ]), 2 )
306+ self .assertEqual (len (final_report_resp ['operational_plans' ][0 ]['indicators' ]), 2 )
307+
308+ # update eap_report
309+ data = self .eap_act_report_body
310+ data ['description' ] = 'updated description'
311+ data ['documents' ] = [self .document1 .id ]
312+ data ['ifrc_financial_report' ] = self .document2 .id
313+ data ['operational_plans' ] = [
314+ {
315+ "budget" : 500000 ,
316+ "value" : 500 ,
317+ "no_of_people_reached" : 500 ,
318+ "readiness_activities_achievements" : "test updated" ,
319+ "prepo_activities_achievements" : "test updated" ,
320+ "early_actions_achievements" : [
321+ {
322+ 'action' : actions [0 ],
323+ "early_act_achievement" : "test updated"
324+ },
325+ {
326+ 'action' : actions [1 ],
327+ "early_act_achievement" : "test 2 updated"
328+ }
329+ ],
330+ "indicators" : [
331+ {
332+ "indicator" : actions_indicators [0 ],
333+ "indicator_value" : 500
334+ },
335+ {
336+ 'indicator' : actions_indicators [1 ],
337+ "indicator_value" : 500
338+ }
339+ ]
340+ },
341+ ]
342+ with self .capture_on_commit_callbacks (execute = True ):
343+ final_report_updated_resp = self .client .put (
344+ f'/api/v2/eap_activation_report/{ created .id } /' ,
345+ data ,
346+ format = 'json'
347+ ).json ()
348+ updated = EAPActivationReport .objects .get (id = final_report_updated_resp ['id' ])
349+ self .assertEqual (updated .created_by .id , self .user .id )
350+ self .assertEqual (final_report_updated_resp ['eap_activation' ], self .eap_activation .id )
351+ self .assertEqual (final_report_updated_resp ['ifrc_financial_report' ], self .document2 .id )
352+ self .assertEqual (len (final_report_updated_resp ['documents' ]), 1 )
353+ self .assertEqual (len (final_report_updated_resp ['operational_plans' ]), 1 )
354+ self .assertEqual (len (final_report_updated_resp ['operational_plans' ][0 ]['early_actions_achievements' ]), 2 )
355+ self .assertEqual (len (final_report_updated_resp ['operational_plans' ][0 ]['indicators' ]), 2 )
0 commit comments