@@ -139,7 +139,7 @@ async def test__post_officer_terms(client: AsyncClient):
139139 }])
140140 assert response .status_code == 422
141141
142- async def test__patch_officer_terms (client : AsyncClient ):
142+ async def test__patch_officer_term (client : AsyncClient ):
143143 # Only admins can update new terms
144144 response = await client .patch ("officers/info/abc11" , json = {
145145 "legal_name" : "fancy name" ,
@@ -183,7 +183,7 @@ async def test__get_all_officers_admin(admin_client):
183183 assert len (response .json ()) == 9
184184 assert response .json ()[1 ]["phone_number" ] == "1234567890"
185185
186- async def test__get_officer_term (admin_client ):
186+ async def test__get_officer_term_admin (admin_client ):
187187 response = await admin_client .get (f"/officers/terms/{ load_test_db .SYSADMIN_COMPUTING_ID } ?include_future_terms=false" )
188188 assert response .status_code == 200
189189 assert response .json () != []
@@ -194,6 +194,11 @@ async def test__get_officer_term(admin_client):
194194 assert response .json () != []
195195 assert len (response .json ()) == 3
196196
197+ response = await admin_client .get ("/officers/terms/ehbc12?include_future_terms=true" )
198+ assert response .status_code == 200
199+ assert response .json () == []
200+
201+ async def test__get_officer_info_admin (admin_client ):
197202 response = await admin_client .get ("/officers/info/abc11" )
198203 assert response .status_code == 200
199204 assert response .json () != {}
@@ -204,23 +209,21 @@ async def test__get_officer_term(admin_client):
204209 response = await admin_client .get ("/officers/info/balargho" )
205210 assert response .status_code == 404
206211
207- response = await admin_client .get ("/officers/terms/ehbc12?include_future_terms=true" )
208- assert response .status_code == 200
209- assert response .json () == []
210-
211- response = await admin_client .post ("officers/term" , content = json .dumps ([{
212+ async def test__post_officer_term_admin (admin_client ):
213+ response = await admin_client .post ("officers/term" , json = [{
212214 "computing_id" : "ehbc12" ,
213215 "position" : OfficerPositionEnum .DIRECTOR_OF_MULTIMEDIA ,
214216 "start_date" : "2025-12-29" ,
215217 "legal_name" : "Eh Bc"
216- }]))
218+ }])
217219 assert response .status_code == 200
218220
219221 response = await admin_client .get ("/officers/terms/ehbc12?include_future_terms=true" )
220222 assert response .status_code == 200
221223 assert response .json () != []
222224 assert len (response .json ()) == 1
223225
226+ async def test__patch_officer_info_admin (admin_client ):
224227 response = await admin_client .patch ("officers/info/abc11" , content = json .dumps ({
225228 "legal_name" : "Person A2" ,
226229 "phone_number" : "12345asdab67890" ,
@@ -245,7 +248,9 @@ async def test__get_officer_term(admin_client):
245248 }))
246249 assert response .status_code == 404
247250
248- response = await admin_client .patch ("officers/term/1" , content = json .dumps ({
251+ async def test__patch_officer_term_admin (admin_client ):
252+ target_id = 1
253+ response = await admin_client .patch (f"officers/term/{ target_id } " , json = {
249254 "position" : OfficerPositionEnum .TREASURER ,
250255 "start_date" : (date .today () - timedelta (days = 365 )).isoformat (),
251256 "end_date" : (date .today () - timedelta (days = 1 )).isoformat (),
@@ -255,25 +260,41 @@ async def test__get_officer_term(admin_client):
255260 "favourite_pl_0" : "4" ,
256261 "favourite_pl_1" : "5" ,
257262 "biography" : "hello o77"
258- }))
263+ })
259264 assert response .status_code == 200
260265
261266 response = await admin_client .get ("/officers/terms/abc11?include_future_terms=true" )
262267 assert response .status_code == 200
263- resJson = response .json ()
264- assert resJson [1 ]["position" ] == OfficerPositionEnum .TREASURER
265- assert resJson [1 ]["start_date" ] == (date .today () - timedelta (days = 365 )).isoformat ()
266- assert resJson [1 ]["end_date" ] == (date .today () - timedelta (days = 1 )).isoformat ()
267- assert resJson [1 ]["nickname" ] != "1"
268- assert resJson [1 ]["favourite_course_0" ] != "2"
269- assert resJson [1 ]["favourite_course_1" ] != "3"
270- assert resJson [1 ]["favourite_pl_0" ] != "4"
271- assert resJson [1 ]["favourite_pl_1" ] != "5"
272- assert resJson [1 ]["biography" ] == "hello o77"
273-
274- async with database_setup .session () as db_session :
275- all_terms = await all_officers (db_session , include_future_terms = True )
276- assert len (all_terms ) == 10
268+ modifiedTerm = next ((item for item in response .json () if item ["id" ] == target_id ), None )
269+ print (modifiedTerm )
270+ assert modifiedTerm is not None
271+ assert modifiedTerm ["position" ] == OfficerPositionEnum .TREASURER
272+ assert modifiedTerm ["start_date" ] == (date .today () - timedelta (days = 365 )).isoformat ()
273+ assert modifiedTerm ["end_date" ] == (date .today () - timedelta (days = 1 )).isoformat ()
274+ assert modifiedTerm ["nickname" ] == "1"
275+ assert modifiedTerm ["favourite_course_0" ] == "2"
276+ assert modifiedTerm ["favourite_course_1" ] == "3"
277+ assert modifiedTerm ["favourite_pl_0" ] == "4"
278+ assert modifiedTerm ["favourite_pl_1" ] == "5"
279+ assert modifiedTerm ["biography" ] == "hello o77"
280+
281+ # other one shouldn't be modified
282+ assert response .status_code == 200
283+ modifiedTerm = next ((item for item in response .json () if item ["id" ] == target_id + 1 ), None )
284+ print (modifiedTerm )
285+ assert modifiedTerm is not None
286+ assert modifiedTerm ["position" ] == OfficerPositionEnum .EXECUTIVE_AT_LARGE
287+ assert modifiedTerm ["start_date" ] != (date .today () - timedelta (days = 365 )).isoformat ()
288+ assert modifiedTerm ["end_date" ] != (date .today () - timedelta (days = 1 )).isoformat ()
289+ assert modifiedTerm ["nickname" ] != "1"
290+ assert modifiedTerm ["favourite_course_0" ] != "2"
291+ assert modifiedTerm ["favourite_course_1" ] != "3"
292+ assert modifiedTerm ["favourite_pl_0" ] != "4"
293+ assert modifiedTerm ["favourite_pl_1" ] != "5"
294+ assert modifiedTerm ["biography" ] != "hello o77"
295+
296+ response = await admin_client .get ("officers/all?include_future_terms=True" )
297+ assert len (response .json ()) == 10
277298
278299 response = await admin_client .delete ("officers/term/1" )
279300 assert response .status_code == 200
@@ -284,6 +305,5 @@ async def test__get_officer_term(admin_client):
284305 response = await admin_client .delete ("officers/term/4" )
285306 assert response .status_code == 200
286307
287- async with database_setup .session () as db_session :
288- all_terms = await all_officers (db_session , include_private_data = True , include_future_terms = True )
289- assert len (all_terms ) == (8 - 4 )
308+ response = await admin_client .get ("officers/all?include_future_terms=True" )
309+ assert len (response .json ()) == 6
0 commit comments