@@ -86,7 +86,10 @@ class TestGSRs(TestCase):
8686 def setUpTestData (cls ):
8787 create_test_gsrs (cls )
8888 test_user = User .objects .create_user ("user1" , "user" )
89- Group .objects .create (owner = test_user , name = "Penn Labs" , color = "blue" )
89+ with mock .patch (
90+ "gsr_booking.models.PennGroupsGSRBooker.is_seas" , return_value = False
91+ ), mock .patch ("gsr_booking.models.WhartonGSRBooker.is_wharton" , return_value = False ):
92+ Group .objects .create (owner = test_user , name = "Penn Labs" , color = "blue" )
9093
9194 def setUp (self ):
9295 # Clear cache to avoid stale data from previous tests
@@ -100,9 +103,22 @@ def setUp(self):
100103 @mock .patch ("gsr_booking.views.WhartonGSRBooker.is_wharton" , return_value = False )
101104 @mock .patch ("gsr_booking.views.PennGroupsGSRBooker.is_seas" , return_value = False )
102105 def test_get_location (self , mock_is_seas , mock_is_wharton ):
103- """Test that regular users do not see Wharton or PennGroups GSRs"""
104106 response = self .client .get (reverse ("locations" ))
105107 res_json = json .loads (response .content )
108+ for entry in res_json :
109+ if entry ["id" ] == 1 :
110+ self .assertEquals (entry ["name" ], "Huntsman" )
111+ if entry ["id" ] == 2 :
112+ self .assertEquals (entry ["name" ], "Amy Gutmann Hall" )
113+ if entry ["id" ] == 3 :
114+ self .assertEquals (entry ["name" ], "Weigle" )
115+
116+ @mock .patch ("gsr_booking.views.WhartonGSRBooker.is_wharton" , return_value = False )
117+ @mock .patch ("gsr_booking.views.PennGroupsGSRBooker.is_seas" , return_value = False )
118+ def test_get_user_location (self , mock_is_seas , mock_is_wharton ):
119+ """Test that regular users do not see Wharton or PennGroups GSRs"""
120+ response = self .client .get (reverse ("user-locations" ))
121+ res_json = json .loads (response .content )
106122
107123 gsr_ids = [entry ["id" ] for entry in res_json ]
108124
@@ -115,9 +131,9 @@ def test_get_location(self, mock_is_seas, mock_is_wharton):
115131
116132 @mock .patch ("gsr_booking.views.WhartonGSRBooker.is_wharton" , return_value = False )
117133 @mock .patch ("gsr_booking.views.PennGroupsGSRBooker.is_seas" , return_value = False )
118- def test_get_location_regular_user (self , mock_is_seas , mock_is_wharton ):
134+ def test_get_user_location_regular_user (self , mock_is_seas , mock_is_wharton ):
119135 """Test that regular users only see LibCal GSRs"""
120- response = self .client .get (reverse ("locations" ))
136+ response = self .client .get (reverse ("user- locations" ))
121137 res_json = json .loads (response .content )
122138
123139 # Regular users should only see LibCal GSRs
@@ -128,9 +144,9 @@ def test_get_location_regular_user(self, mock_is_seas, mock_is_wharton):
128144
129145 @mock .patch ("gsr_booking.views.WhartonGSRBooker.is_wharton" , return_value = True )
130146 @mock .patch ("gsr_booking.views.PennGroupsGSRBooker.is_seas" , return_value = False )
131- def test_get_location_wharton_user (self , mock_is_seas , mock_is_wharton ):
147+ def test_get_user_location_wharton_user (self , mock_is_seas , mock_is_wharton ):
132148 """Test that Wharton users see LibCal and Wharton GSRs"""
133- response = self .client .get (reverse ("locations" ))
149+ response = self .client .get (reverse ("user- locations" ))
134150 res_json = json .loads (response .content )
135151
136152 # Wharton users should see LibCal and Wharton GSRs
@@ -145,9 +161,9 @@ def test_get_location_wharton_user(self, mock_is_seas, mock_is_wharton):
145161
146162 @mock .patch ("gsr_booking.views.WhartonGSRBooker.is_wharton" , return_value = False )
147163 @mock .patch ("gsr_booking.views.PennGroupsGSRBooker.is_seas" , return_value = True )
148- def test_get_location_seas_user (self , mock_is_seas , mock_is_wharton ):
164+ def test_get_user_location_seas_user (self , mock_is_seas , mock_is_wharton ):
149165 """Test that SEAS users see LibCal and PennGroups GSRs"""
150- response = self .client .get (reverse ("locations" ))
166+ response = self .client .get (reverse ("user- locations" ))
151167 res_json = json .loads (response .content )
152168
153169 # SEAS users should see LibCal and PennGroups GSRs
@@ -162,9 +178,9 @@ def test_get_location_seas_user(self, mock_is_seas, mock_is_wharton):
162178
163179 @mock .patch ("gsr_booking.views.WhartonGSRBooker.is_wharton" , return_value = True )
164180 @mock .patch ("gsr_booking.views.PennGroupsGSRBooker.is_seas" , return_value = True )
165- def test_get_location_wharton_seas_user (self , mock_is_seas , mock_is_wharton ):
181+ def test_get_user_location_wharton_seas_user (self , mock_is_seas , mock_is_wharton ):
166182 """Test that users with both Wharton and SEAS access see all non-Penn Labs GSRs"""
167- response = self .client .get (reverse ("locations" ))
183+ response = self .client .get (reverse ("user- locations" ))
168184 res_json = json .loads (response .content )
169185
170186 # Users with both should see all kinds
@@ -177,15 +193,17 @@ def test_get_location_wharton_seas_user(self, mock_is_seas, mock_is_wharton):
177193 self .assertIn (GSR .KIND_WHARTON , kinds_seen )
178194 self .assertIn (GSR .KIND_PENNGROUPS , kinds_seen )
179195
180- def test_get_location_penn_labs_member (self ):
196+ @mock .patch ("gsr_booking.models.PennGroupsGSRBooker.is_seas" , return_value = False )
197+ @mock .patch ("gsr_booking.models.WhartonGSRBooker.is_wharton" , return_value = False )
198+ def test_get_user_location_penn_labs_member (self , mock_is_wharton , mock_is_seas ):
181199 """Test that Penn Labs members see all GSRs regardless of their individual status"""
182200 # Add user to Penn Labs group
183201 penn_labs_group = Group .objects .get (name = "Penn Labs" )
184202 GroupMembership .objects .create (
185203 user = self .user , group = penn_labs_group , accepted = True , type = GroupMembership .MEMBER
186204 )
187205
188- response = self .client .get (reverse ("locations" ))
206+ response = self .client .get (reverse ("user- locations" ))
189207 res_json = json .loads (response .content )
190208
191209 # Penn Labs members should see all GSRs
@@ -212,9 +230,9 @@ def test_get_location_penn_labs_member(self):
212230
213231 @mock .patch ("gsr_booking.views.WhartonGSRBooker.is_wharton" , return_value = False )
214232 @mock .patch ("gsr_booking.views.PennGroupsGSRBooker.is_seas" , return_value = False )
215- def test_get_location_api_error_handling (self , mock_is_seas , mock_is_wharton ):
233+ def test_get_user_location_api_error_handling (self , mock_is_seas , mock_is_wharton ):
216234 """Test that when permission checks return False, users only see LibCal GSRs"""
217- response = self .client .get (reverse ("locations" ))
235+ response = self .client .get (reverse ("user- locations" ))
218236 res_json = json .loads (response .content )
219237
220238 # When permission checks return False, users should only see LibCal GSRs
@@ -228,7 +246,10 @@ class TestGSRFunctions(TestCase):
228246 def setUpTestData (cls ):
229247 create_test_gsrs (cls )
230248 test_user = User .objects .create_user ("user1" , "user" )
231- Group .objects .create (owner = test_user , name = "Penn Labs" , color = "blue" )
249+ with mock .patch (
250+ "gsr_booking.models.PennGroupsGSRBooker.is_seas" , return_value = False
251+ ), mock .patch ("gsr_booking.models.WhartonGSRBooker.is_wharton" , return_value = False ):
252+ Group .objects .create (owner = test_user , name = "Penn Labs" , color = "blue" )
232253
233254 def setUp (self ):
234255 self .user = User .objects .create_user ("user" , "user@seas.upenn.edu" , "user" )
@@ -368,7 +389,10 @@ class TestSEASViews(TestCase):
368389 def setUpTestData (cls ):
369390 create_test_gsrs (cls )
370391 test_user = User .objects .create_user ("user1" , "user" )
371- Group .objects .create (owner = test_user , name = "Penn Labs" , color = "blue" )
392+ with mock .patch (
393+ "gsr_booking.models.PennGroupsGSRBooker.is_seas" , return_value = False
394+ ), mock .patch ("gsr_booking.models.WhartonGSRBooker.is_wharton" , return_value = False ):
395+ Group .objects .create (owner = test_user , name = "Penn Labs" , color = "blue" )
372396
373397 def setUp (self ):
374398 self .user = User .objects .create_user ("user" , "user@seas.upenn.edu" , "user" )
@@ -430,7 +454,10 @@ class TestPennGroupsViews(TestCase):
430454 def setUpTestData (cls ):
431455 create_test_gsrs (cls )
432456 test_user = User .objects .create_user ("user1" , "user" )
433- Group .objects .create (owner = test_user , name = "Penn Labs" , color = "blue" )
457+ with mock .patch (
458+ "gsr_booking.models.PennGroupsGSRBooker.is_seas" , return_value = False
459+ ), mock .patch ("gsr_booking.models.WhartonGSRBooker.is_wharton" , return_value = False ):
460+ Group .objects .create (owner = test_user , name = "Penn Labs" , color = "blue" )
434461
435462 def setUp (self ):
436463 self .user = User .objects .create_user ("user" , "user@seas.upenn.edu" , "user" )
0 commit comments