@@ -324,3 +324,80 @@ async def test_update_image(
324324 assert {k : v for k , v in response .json ().items () if k not in {"last_active_at" , "last_image" }} == {
325325 k : v for k , v in pytest .camera_table [cam_idx ].items () if k not in {"last_active_at" , "last_image" }
326326 }
327+
328+
329+ @pytest .mark .parametrize (
330+ ("user_idx" , "payload" , "status_code" , "status_detail" ),
331+ [
332+ (
333+ None ,
334+ {
335+ "elevation" : 30.0 ,
336+ "lat" : 3.5 ,
337+ "lon" : 7.8 ,
338+ },
339+ 401 ,
340+ "Not authenticated" ,
341+ ),
342+ (
343+ 0 ,
344+ {"elevation" : 30.0 , "lat" : 3.5 },
345+ 422 ,
346+ None ,
347+ ),
348+ (
349+ 0 ,
350+ {
351+ "elevation" : 30.0 ,
352+ "lat" : 3.5 ,
353+ "lon" : 7.8 ,
354+ },
355+ 200 ,
356+ None ,
357+ ),
358+ (
359+ 1 ,
360+ {
361+ "elevation" : 30.0 ,
362+ "lat" : 3.5 ,
363+ "lon" : 7.8 ,
364+ },
365+ 403 ,
366+ "Incompatible token scope." ,
367+ ),
368+ (
369+ 2 ,
370+ {
371+ "elevation" : 30.0 ,
372+ "lat" : 3.5 ,
373+ "lon" : 7.8 ,
374+ },
375+ 403 ,
376+ "Incompatible token scope." ,
377+ ),
378+ ],
379+ )
380+ @pytest .mark .asyncio
381+ async def test_update_camera_location (
382+ async_client : AsyncClient ,
383+ camera_session : AsyncSession ,
384+ user_idx : Union [int , None ],
385+ cam_id : int ,
386+ payload : Dict [str , Any ],
387+ status_code : int ,
388+ status_detail : Union [str , None ],
389+ ):
390+ auth = None
391+ if isinstance (user_idx , int ):
392+ auth = pytest .get_token (
393+ pytest .user_table [user_idx ]["id" ],
394+ pytest .user_table [user_idx ]["role" ].split (),
395+ pytest .user_table [user_idx ]["organization_id" ],
396+ )
397+
398+ response = await async_client .patch (f"/cameras/{ cam_id } /location" , json = payload , headers = auth )
399+ assert response .status_code == status_code , print (response .__dict__ )
400+ if isinstance (status_detail , str ):
401+ assert response .json ()["detail" ] == status_detail
402+ if response .status_code // 100 == 2 :
403+ assert {k : v for k , v in response .json ().items () if k in {"lat" , "lon" , "elevation" }} == payload
0 commit comments