@@ -226,7 +226,7 @@ async def test_get_jobs_endpoint(mocker, set_db_env_var, staging_client): # pyl
226226 (
227227 {"identifier" : "non_existing_id" },
228228 HTTP_404_NOT_FOUND ,
229- {"title" : "No Such Job" , "detail" : "Job with ID non_existing_id not found. " },
229+ {"title" : "No Such Job" , "detail" : "Job with ID non_existing_id not found" },
230230 ),
231231 (
232232 {"identifier" : "trigger_500" },
@@ -266,14 +266,14 @@ async def test_get_job(
266266 # Mock app.extra to ensure 'db_table' exists
267267 mock_db_table = mocker .MagicMock ()
268268
269+ # Simulate JobNotFoundError for non-existing jobs (HTTP 404)
269270 if expected_status == HTTP_404_NOT_FOUND :
270- # Simulate JobNotFoundError for non-existing jobs (HTTP 404)
271271 mock_db_table .get_job .side_effect = JobNotFoundError
272+ # Simulate an unexpected exception (HTTP 500)
272273 elif expected_status == HTTP_500_INTERNAL_SERVER_ERROR :
273- # Simulate an unexpected exception (HTTP 500)
274274 mock_db_table .get_job .side_effect = Exception ("Unexpected error occurred" )
275+ # Return an existing job normally (HTTP 200)
275276 else :
276- # Return an existing job normally (HTTP 200)
277277 mock_db_table .get_job .return_value = next (
278278 job for job in mock_jobs if job ["identifier" ] == expected_job ["identifier" ]
279279 )
@@ -296,7 +296,7 @@ async def test_get_job(
296296 (
297297 {"identifier" : "non_existing_id" },
298298 HTTP_404_NOT_FOUND ,
299- {"title" : "No Such Job" , "detail" : "Job with ID non_existing_id not found. " },
299+ {"title" : "No Such Job" , "detail" : "Job with ID non_existing_id not found" },
300300 ),
301301 (
302302 {"identifier" : "trigger_500" },
@@ -336,14 +336,14 @@ async def test_get_job_result(
336336 # Mock app.extra to ensure 'db_table' exists
337337 mock_db_table = mocker .MagicMock ()
338338
339+ # Simulate JobNotFoundError for non-existing jobs (HTTP 404)
339340 if expected_status == HTTP_404_NOT_FOUND :
340- # Simulate JobNotFoundError for non-existing jobs (HTTP 404)
341341 mock_db_table .get_job .side_effect = JobNotFoundError
342+ # Simulate an unexpected exception (HTTP 500)
342343 elif expected_status == HTTP_500_INTERNAL_SERVER_ERROR :
343- # Simulate an unexpected exception (HTTP 500)
344344 mock_db_table .get_job .side_effect = Exception ("Unexpected error occurred" )
345+ # Return an existing job normally (HTTP 200)
345346 else :
346- # Return an existing job normally (HTTP 200)
347347 mock_db_table .get_job .return_value = next (
348348 job for job in mock_jobs if job ["identifier" ] == expected_job ["identifier" ]
349349 )
@@ -367,7 +367,7 @@ async def test_get_job_result(
367367 (
368368 {"identifier" : "non_existing_id" },
369369 HTTP_404_NOT_FOUND ,
370- {"title" : "No Such Job" , "detail" : "Job with ID non_existing_id not found. " },
370+ {"title" : "No Such Job" , "detail" : "Job with ID non_existing_id not found" },
371371 ),
372372 (
373373 {"identifier" : "trigger_500" },
@@ -399,25 +399,29 @@ async def test_delete_job_endpoint(
399399 Args:
400400 mocker: A mocker object used to create mocks and patches for testing.
401401 staging_client: A test client for making requests to the FastAPI application.
402+ mock_jobs: Fixture used to mock output of tiny db jobs
402403 expected_job (dict): The expected job dictionary containing job_id,
403404 status, progress, and message for the job to be deleted.
405+ expected_status: response HTTP status code
406+ expected_response: response body (JSON object)
404407
405408 Assertions:
406409 - Asserts that the response status code is 200 if the job is successfully deleted.
407410 - Asserts that the response status code is 404 if the job does not exist.
411+ - Asserts that the response status code is 500 if other exception occurs.
408412 """
409413 # Mock app.extra to ensure 'db_table' exists
410414 mock_db_table = mocker .MagicMock ()
411415
416+ # Simulate JobNotFoundError for non-existing jobs (HTTP 404)
412417 if expected_status == HTTP_404_NOT_FOUND :
413- # Simulate JobNotFoundError for non-existing jobs (HTTP 404)
414- mock_db_table . get_job . side_effect = JobNotFoundError
418+ mock_db_table . delete_job . side_effect = JobNotFoundError
419+ # Simulate an unexpected exception (HTTP 500)
415420 elif expected_status == HTTP_500_INTERNAL_SERVER_ERROR :
416- # Simulate an unexpected exception (HTTP 500 )
417- mock_db_table . get_job . side_effect = Exception ( "Unexpected error occurred" )
421+ mock_db_table . delete_job . side_effect = Exception ( "Unexpected error occurred" )
422+ # Return an existing job normally (HTTP 200 )
418423 else :
419- # Return an existing job normally (HTTP 200)
420- mock_db_table .get_job .return_value = next (
424+ mock_db_table .delete_job .return_value = next (
421425 job for job in mock_jobs if job ["identifier" ] == expected_job ["identifier" ]
422426 )
423427
0 commit comments