@@ -897,3 +897,77 @@ def test_refresh_bearer_token_before_start(
897897 # Because of proactive+throttled token refreshing,
898898 # we should have 2 additional token requests now
899899 assert len (oidc_mock .grant_request_history ) == 4
900+
901+ def test_on_job_done_boolean_download (
902+ self , tmp_path , job_manager_root_dir , requests_mock
903+ ):
904+ """Test that job results are only downloaded when download_results=True"""
905+
906+ # Setup backend and connection
907+ backend = "http://foo.test"
908+ job_id = "job-test-123"
909+
910+ requests_mock .get (backend , json = {"api_version" : "1.1.0" })
911+ requests_mock .get (f"{ backend } /jobs/{ job_id } " , json = {
912+ "id" : job_id ,
913+ "status" : "finished" ,
914+ "title" : "Test Job"
915+ })
916+ requests_mock .get (f"{ backend } /jobs/{ job_id } /results" , json = {
917+ "assets" : {
918+ "result.tif" : {
919+ "href" : f"{ backend } /jobs/{ job_id } /results/result.tif" ,
920+ "type" : "image/tiff"
921+ }
922+ }
923+ })
924+ # Mock the actual file download
925+ requests_mock .head (f"{ backend } /jobs/{ job_id } /results/result.tif" , headers = {"Content-Length" : "100" })
926+ requests_mock .get (f"{ backend } /jobs/{ job_id } /results/result.tif" , content = b"fake_tiff_data" )
927+
928+ # Test with auto_download_results=False
929+ manager_no_download = MultiBackendJobManager (
930+ root_dir = job_manager_root_dir ,
931+ download_results = False
932+ )
933+ connection = openeo .connect (backend )
934+ manager_no_download .add_backend ("foo" , connection = connection )
935+
936+ df = pd .DataFrame ({"year" : [2020 ]})
937+ job = BatchJob (job_id = job_id , connection = connection )
938+ row = df .loc [0 ]
939+
940+ # Call on_job_done
941+ manager_no_download .on_job_done (job = job , row = row )
942+
943+ # Verify no files were downloaded and no directory was created
944+ job_dir = manager_no_download .get_job_dir (job_id )
945+ metadata_path = manager_no_download .get_job_metadata_path (job_id )
946+
947+ assert not job_dir .exists (), "Job directory should not exist when auto_download_results=False"
948+ assert not metadata_path .exists (), "Metadata file should not exist when auto_download_results=False"
949+
950+ # Now test with auto_download_results=True
951+ manager_with_download = MultiBackendJobManager (
952+ root_dir = job_manager_root_dir ,
953+ download_results = True
954+ )
955+ manager_with_download .add_backend ("foo" , connection = connection )
956+
957+ # Call on_job_done
958+ manager_with_download .on_job_done (job = job , row = row )
959+
960+ # Verify files were downloaded and directory was created
961+ assert job_dir .exists (), "Job directory should exist when auto_download_results=True"
962+ assert metadata_path .exists (), "Metadata file should exist when auto_download_results=True"
963+
964+ # Verify metadata content
965+ with metadata_path .open ("r" , encoding = "utf-8" ) as f :
966+ metadata = json .load (f )
967+ assert metadata ["id" ] == job_id
968+ assert metadata ["status" ] == "finished"
969+
970+ # Verify result file was downloaded
971+ result_file = job_dir / "result.tif"
972+ assert result_file .exists (), "Result file should be downloaded"
973+ assert result_file .read_bytes () == b"fake_tiff_data"
0 commit comments