@@ -31,9 +31,11 @@ def setUp(self):
3131 go_user_profile .save ()
3232
3333 # Create public field reports
34- FieldReportFactory .create_batch (4 , visibility = VisibilityChoices .PUBLIC )
34+ event_pub = EventFactory .create (visibility = VisibilityChoices .PUBLIC , parent_event = None )
35+ FieldReportFactory .create_batch (4 , event = event_pub , visibility = VisibilityChoices .PUBLIC )
3536 # Create non-public field reports
36- FieldReportFactory .create_batch (5 , visibility = VisibilityChoices .IFRC )
37+ event_non_pub = EventFactory .create (visibility = VisibilityChoices .IFRC , parent_event = None )
38+ FieldReportFactory .create_batch (5 , event = event_non_pub , visibility = VisibilityChoices .IFRC )
3739
3840 def test_guest_user_permission (self ):
3941 body = {}
@@ -50,6 +52,7 @@ def test_guest_user_permission(self):
5052 f"/api/v2/field-report/{ id } /" ,
5153 "/api/v2/language/" ,
5254 f"/api/v2/language/{ id } /" ,
55+ "/api/v2/event/" ,
5356 ]
5457
5558 go_post_apis = [
@@ -159,6 +162,11 @@ def _failure_check(response, check_json_error_code=True):
159162 field_report_pub_response = self .client .post ("/api/v2/field-report/" , json = body )
160163 _failure_check (field_report_pub_response , check_json_error_code = False )
161164
165+ # Unauthenticated user should be able to view public events
166+ event_pub_response = self .client .get ("/api/v2/event/" )
167+ _success_check (event_pub_response )
168+ self .assertEqual (len (event_pub_response .json ()["results" ]), 1 )
169+
162170 # authenticate guest user
163171 self .authenticate (user = self .guest_user )
164172
@@ -194,6 +202,11 @@ def _failure_check(response, check_json_error_code=True):
194202 _success_check (field_report_pub_response )
195203 self .assertEqual (len (field_report_pub_response .json ()["results" ]), 4 )
196204
205+ # Guest user should be able to view public events
206+ event_pub_response = self .client .get ("/api/v2/event/" )
207+ _success_check (event_pub_response )
208+ self .assertEqual (len (event_pub_response .json ()["results" ]), 1 )
209+
197210 # authenticate ifrc go user
198211 # Go user should be able to access go_post_apis
199212 self .authenticate (user = self .go_user )
@@ -210,6 +223,11 @@ def _failure_check(response, check_json_error_code=True):
210223 _success_check (field_report_response )
211224 self .assertEqual (len (field_report_response .json ()["results" ]), 9 )
212225
226+ # Go user should be able to view both public + non-pubic events
227+ event_response = self .client .get ("/api/v2/event/" )
228+ _success_check (event_response )
229+ self .assertEqual (len (event_response .json ()["results" ]), 2 )
230+
213231
214232class AuthTokenTest (APITestCase ):
215233 def setUp (self ):
0 commit comments