Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugins): raise error on failed empty stream_zip #1475

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion eodag/plugins/download/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,13 +778,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
Loading