1313)
1414from app .services .processing import (
1515 create_processing_job ,
16+ get_job_result_url ,
1617 get_job_status ,
1718 get_processing_job_by_user_id ,
1819 get_processing_jobs_by_user_id ,
@@ -93,7 +94,7 @@ def test_get_processing_jobs_with_active_and_inactive_statuses(
9394 platform_job_id = "platform456" ,
9495 label = ProcessTypeEnum .OGC_API_PROCESS ,
9596 title = "Finished Job" ,
96- status = ProcessingStatusEnum .FINISHED ,
97+ status = ProcessingStatusEnum .FAILED ,
9798 service_record = json .dumps ({"foo" : "bar" }),
9899 )
99100 mock_get_jobs .return_value = [fake_processing_job_record , inactive_job ]
@@ -104,7 +105,7 @@ def test_get_processing_jobs_with_active_and_inactive_statuses(
104105 assert len (results ) == 2
105106 assert isinstance (results [0 ], ProcessingJobSummary )
106107 assert results [0 ].status == ProcessingStatusEnum .RUNNING
107- assert results [1 ].status == ProcessingStatusEnum .FINISHED
108+ assert results [1 ].status == ProcessingStatusEnum .FAILED
108109
109110 # Active job should be refreshed
110111 mock_get_job_status .assert_called_once_with (fake_processing_job_record )
@@ -136,6 +137,44 @@ def test_get_processing_jobs_no_updates(
136137 mock_update_job_status .assert_not_called ()
137138
138139
140+ @patch ("app.services.processing.update_job_result_by_id" )
141+ @patch ("app.services.processing.get_job_result_url" )
142+ @patch ("app.services.processing.get_jobs_by_user_id" )
143+ def test_get_processing_jobs_with_finished_statuses (
144+ mock_get_jobs , mock_get_jobs_results , mock_update_job_result , fake_db_session
145+ ):
146+ finished_job_no_result = ProcessingJobRecord (
147+ id = 2 ,
148+ platform_job_id = "platform456" ,
149+ label = ProcessTypeEnum .OGC_API_PROCESS ,
150+ title = "Finished Job" ,
151+ status = ProcessingStatusEnum .FINISHED ,
152+ service_record = json .dumps ({"foo" : "bar" }),
153+ )
154+ finished_job_result = ProcessingJobRecord (
155+ id = 3 ,
156+ platform_job_id = "platform456" ,
157+ label = ProcessTypeEnum .OGC_API_PROCESS ,
158+ title = "Finished Job" ,
159+ status = ProcessingStatusEnum .FINISHED ,
160+ service_record = json .dumps ({"foo" : "bar" }),
161+ result_link = "https://foo.bar" ,
162+ )
163+ mock_get_jobs .return_value = [finished_job_no_result , finished_job_result ]
164+ mock_get_jobs_results .return_value = "https://foo2.bar"
165+
166+ results = get_processing_jobs_by_user_id (fake_db_session , "user1" )
167+
168+ assert len (results ) == 2
169+ assert isinstance (results [0 ], ProcessingJobSummary )
170+
171+ # Active job should be refreshed
172+ mock_get_jobs_results .assert_called_once_with (finished_job_no_result )
173+ mock_update_job_result .assert_called_once_with (
174+ ANY , finished_job_no_result .id , "https://foo2.bar"
175+ )
176+
177+
139178@patch ("app.services.processing.get_processing_platform" )
140179def test_get_job_status_from_platform (mock_get_platform , fake_processing_job_record ):
141180
@@ -148,6 +187,18 @@ def test_get_job_status_from_platform(mock_get_platform, fake_processing_job_rec
148187 assert status == ProcessingStatusEnum .QUEUED
149188
150189
190+ @patch ("app.services.processing.get_processing_platform" )
191+ def test_get_job_result_from_platform (mock_get_platform , fake_processing_job_record ):
192+
193+ fake_platform = MagicMock ()
194+ fake_platform .get_job_result_url .return_value = "https://foo.bar"
195+ mock_get_platform .return_value = fake_platform
196+
197+ result = get_job_result_url (fake_processing_job_record )
198+
199+ assert result == "https://foo.bar"
200+
201+
151202@patch ("app.services.processing.get_job_by_user_id" )
152203def test_get_processing_job_by_user_id (mock_get_job , fake_db_session ):
153204
0 commit comments