Skip to content

Commit

Permalink
fix(plugins): raise error on failed empty stream_zip (#1475)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlahovnik authored Jan 21, 2025
1 parent 7bfe7fb commit f82f016
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion eodag/plugins/download/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,13 +772,17 @@ def _stream_download_dict(
)

else:
# get first chunk to check if it does not contain an error (if it does, that error will be raised)
first_chunks_tuple = next(chunks_tuples)
outputs_filename = (
sanitize(product.properties["title"])
if "title" in product.properties
else sanitize(product.properties.get("id", "download"))
)
return StreamResponse(
content=stream_zip(chunks_tuples),
content=stream_zip(
chain(iter([first_chunks_tuple]), chunks_tuples)
),
media_type="application/zip",
headers={
"content-disposition": f"attachment; filename={outputs_filename}.zip",
Expand Down
32 changes: 32 additions & 0 deletions tests/units/test_download_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,38 @@ def test_plugins_download_http_assets_interrupt(
)
)

@mock.patch(
"eodag.plugins.download.http.ProgressCallback.__call__",
autospec=True,
)
@mock.patch("eodag.plugins.download.http.requests.head", autospec=True)
@mock.patch("eodag.plugins.download.http.requests.get", autospec=True)
def test_plugins_download_http_assets_stream_zip_interrupt(
self, mock_requests_get, mock_requests_head, mock_progress_callback
):
"""HTTPDownload._stream_download_dict() must raise an error if an error is returned by the provider"""

plugin = self.get_download_plugin(self.product)
self.product.location = self.product.remote_location = "http://somewhere"
self.product.properties["id"] = "someproduct"
self.product.assets.clear()
self.product.assets.update({"foo": {"href": "http://somewhere/something"}})
self.product.assets.update({"any": {"href": "http://somewhere/anything"}})

# first asset returns error
mock_requests_get.return_value = MockResponse(status_code=404)
mock_requests_head.return_value.headers = {
"content-disposition": "",
"Content-length": "10",
}

with self.assertRaises(DownloadError):
plugin._stream_download_dict(self.product, output_dir=self.output_dir)
# Interrupted download
# Product location not changed
self.assertEqual(self.product.location, "http://somewhere")
self.assertEqual(self.product.remote_location, "http://somewhere")

@mock.patch("eodag.plugins.download.http.requests.head", autospec=True)
@mock.patch("eodag.plugins.download.http.requests.get", autospec=True)
def test_plugins_download_http_assets_resume(
Expand Down

0 comments on commit f82f016

Please sign in to comment.