@@ -681,21 +681,27 @@ async def test_get_camera_s3_unavailable_returns_null_url(
681681 camera_session : AsyncSession ,
682682 pose_session : AsyncSession ,
683683 mock_img : bytes ,
684- monkeypatch ,
685684):
686- cam_auth = pytest .get_token (
687- pytest .camera_table [0 ]["id" ], ["camera" ], pytest .camera_table [0 ]["organization_id" ]
688- )
685+ cam_auth = pytest .get_token (pytest .camera_table [0 ]["id" ], ["camera" ], pytest .camera_table [0 ]["organization_id" ])
689686 upload_response = await async_client .patch (
690687 "/cameras/image" , files = {"file" : ("img.png" , mock_img , "image/png" )}, headers = cam_auth
691688 )
692689 assert upload_response .status_code == 200
693-
694- monkeypatch .setattr ("app.services.storage.S3Bucket.check_file_existence" , lambda self , key : False )
690+ bucket_key = upload_response .json ()["last_image" ]
695691
696692 user_auth = pytest .get_token (
697- pytest .user_table [0 ]["id" ], pytest .user_table [0 ]["role" ].split (), pytest .user_table [0 ]["organization_id" ]
693+ pytest .user_table [1 ]["id" ], pytest .user_table [1 ]["role" ].split (), pytest .user_table [1 ]["organization_id" ]
698694 )
695+
696+ # Verify the URL is accessible before deletion
697+ response = await async_client .get ("/cameras/1" , headers = user_auth )
698+ assert response .status_code == 200
699+ assert response .json ()["last_image_url" ] is not None
700+
701+ # Delete the file from S3 then verify the endpoint handles it gracefully
702+ bucket = s3_service .get_bucket (s3_service .resolve_bucket_name (pytest .camera_table [0 ]["organization_id" ]))
703+ bucket .delete_file (bucket_key )
704+
699705 response = await async_client .get ("/cameras/1" , headers = user_auth )
700706 assert response .status_code == 200
701707 assert response .json ()["last_image_url" ] is None
@@ -708,9 +714,7 @@ async def test_fetch_cameras_s3_unavailable_returns_null_url(
708714 pose_session : AsyncSession ,
709715 mock_img : bytes ,
710716):
711- cam_auth = pytest .get_token (
712- pytest .camera_table [0 ]["id" ], ["camera" ], pytest .camera_table [0 ]["organization_id" ]
713- )
717+ cam_auth = pytest .get_token (pytest .camera_table [0 ]["id" ], ["camera" ], pytest .camera_table [0 ]["organization_id" ])
714718 upload_response = await async_client .patch (
715719 "/cameras/image" , files = {"file" : ("img.png" , mock_img , "image/png" )}, headers = cam_auth
716720 )
0 commit comments