Skip to content

Commit

Permalink
Merge pull request #642 from omnivector-solutions/tucker/PENG-2526--a…
Browse files Browse the repository at this point in the history
…dd-upload-by-url-endpoints-to-jobbergate-api

PENG-2426 Fixed error code when user supplies bad url
  • Loading branch information
dusktreader authored Oct 28, 2024
2 parents 14e31fc + 4d6292b commit 4279931
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion jobbergate-api/jobbergate_api/apps/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ async def _get_file_data_from_url(self, file_url: AnyUrl) -> io.BytesIO:
with handle_errors(
f"Failed to download file from {file_url}",
raise_exc_class=ServiceError,
raise_kwargs=dict(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR),
raise_kwargs=dict(status_code=status.HTTP_400_BAD_REQUEST),
):
response = httpx.get(file_url_string)
response.raise_for_status()
Expand Down
8 changes: 4 additions & 4 deletions jobbergate-api/tests/apps/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,23 +810,23 @@ async def test__get_file_data_from_url__s3_success(self, file_content, dummy_fil
file_obj = await dummy_file_service._get_file_data_from_url(AnyUrl(s3_url))
assert file_obj.read() == file_content

async def test__get_file_data_from_url__raises_500_if_download_fails(
async def test__get_file_data_from_url__raises_400_if_download_fails(
self, dummy_file_service, respx_mock
):
"""
Test that the ``_get_file_data_from_url()`` method raises a 500 error if the download fails.
Test that the ``_get_file_data_from_url()`` method raises a 400 error if the download fails.
"""
file_url = "https://dummy-domain.com/dummy-file.txt"

respx_mock.get(file_url).mock(return_value=httpx.Response(httpx.codes.IM_A_TEAPOT))
with pytest.raises(ServiceError, match="Failed to download") as exc_info:
await dummy_file_service._get_file_data_from_url(AnyUrl(file_url))
assert exc_info.value.status_code == 500
assert exc_info.value.status_code == 400

respx_mock.get(file_url).mock(side_effect=RuntimeError)
with pytest.raises(ServiceError, match="Failed to download") as exc_info:
await dummy_file_service._get_file_data_from_url(AnyUrl(file_url))
assert exc_info.value.status_code == 500
assert exc_info.value.status_code == 400

@pytest.mark.parametrize(
"file_url,error_stub",
Expand Down

0 comments on commit 4279931

Please sign in to comment.