Skip to content

Commit

Permalink
fix(plugins): raise error if no data available on AwsDownload (#1257)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicola Dalpasso <nicola.dalpasso@csgroup.de>
  • Loading branch information
alambare and dalpasso authored Sep 12, 2024
1 parent 0deebef commit dc24261
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
6 changes: 5 additions & 1 deletion eodag/plugins/download/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
AuthenticationError,
DownloadError,
MisconfiguredError,
NoMatchingProductType,
NotAvailableError,
TimeOutError,
)
Expand Down Expand Up @@ -611,6 +612,10 @@ def _get_unique_products(
raise NotAvailableError(
rf"No file basename matching re.fullmatch(r'{asset_filter}') was found in {product.remote_location}"
)

if not unique_product_chunks:
raise NoMatchingProductType("No product found to download.")

return unique_product_chunks

def _raise_if_auth_error(self, exception: ClientError) -> None:
Expand Down Expand Up @@ -751,7 +756,6 @@ def get_chunk_parts(
product_chunk: Any, progress_callback: ProgressCallback
) -> Any:
try:

chunk_start = 0
chunk_end = chunk_start + chunk_size - 1

Expand Down
56 changes: 42 additions & 14 deletions tests/units/test_download_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

from eodag.api.product.metadata_mapping import DEFAULT_METADATA_MAPPING
from eodag.utils import ProgressCallback
from eodag.utils.exceptions import DownloadError
from eodag.utils.exceptions import DownloadError, NoMatchingProductType
from tests import TEST_RESOURCES_PATH
from tests.context import (
DEFAULT_STREAM_REQUESTS_TIMEOUT,
Expand Down Expand Up @@ -96,7 +96,7 @@ def tearDown(self):
super(BaseDownloadPluginTest, self).tearDown()
self.tmp_dir.cleanup()

def get_download_plugin(self, product):
def get_download_plugin(self, product: EOProduct):
return self.plugins_manager.get_download_plugin(product)

def get_auth_plugin(self, provider):
Expand Down Expand Up @@ -1482,6 +1482,9 @@ def test_plugins_download_aws_get_bucket_prefix(self):
)
self.assertEqual((bucket, prefix), ("default_bucket", "somewhere/else"))

@mock.patch(
"eodag.plugins.download.aws.AwsDownload._get_unique_products", autospec=True
)
@mock.patch("eodag.plugins.download.aws.flatten_top_directories", autospec=True)
@mock.patch(
"eodag.plugins.download.aws.AwsDownload.check_manifest_file_list", autospec=True
Expand All @@ -1499,12 +1502,13 @@ def test_plugins_download_aws_get_bucket_prefix(self):
@mock.patch("eodag.plugins.download.aws.requests.get", autospec=True)
def test_plugins_download_aws_no_safe_build_no_flatten_top_dirs(
self,
mock_requests_get,
mock_get_authenticated_objects,
mock_get_chunk_dest_path,
mock_finalize_s2_safe_product,
mock_check_manifest_file_list,
mock_flatten_top_directories,
mock_requests_get: mock.Mock,
mock_get_authenticated_objects: mock.Mock,
mock_get_chunk_dest_path: mock.Mock,
mock_finalize_s2_safe_product: mock.Mock,
mock_check_manifest_file_list: mock.Mock,
mock_flatten_top_directories: mock.Mock,
mock__get_unique_products: mock.Mock,
):
"""AwsDownload.download() must not call safe build methods if not needed"""

Expand All @@ -1525,6 +1529,9 @@ def test_plugins_download_aws_no_safe_build_no_flatten_top_dirs(
self.assertEqual(mock_check_manifest_file_list.call_count, 0)
self.assertEqual(mock_flatten_top_directories.call_count, 0)

@mock.patch(
"eodag.plugins.download.aws.AwsDownload._get_unique_products", autospec=True
)
@mock.patch("eodag.plugins.download.aws.flatten_top_directories", autospec=True)
@mock.patch(
"eodag.plugins.download.aws.AwsDownload.check_manifest_file_list", autospec=True
Expand All @@ -1542,12 +1549,13 @@ def test_plugins_download_aws_no_safe_build_no_flatten_top_dirs(
@mock.patch("eodag.plugins.download.aws.requests.get", autospec=True)
def test_plugins_download_aws_no_safe_build_flatten_top_dirs(
self,
mock_requests_get,
mock_get_authenticated_objects,
mock_get_chunk_dest_path,
mock_finalize_s2_safe_product,
mock_check_manifest_file_list,
mock_flatten_top_directories,
mock_requests_get: mock.Mock,
mock_get_authenticated_objects: mock.Mock,
mock_get_chunk_dest_path: mock.Mock,
mock_finalize_s2_safe_product: mock.Mock,
mock_check_manifest_file_list: mock.Mock,
mock_flatten_top_directories: mock.Mock,
mock__get_unique_products: mock.Mock,
):
"""AwsDownload.download() must not call safe build methods if not needed"""

Expand Down Expand Up @@ -1729,6 +1737,26 @@ def test_plugins_download_aws_safe_build_assets(
# 3 additional calls
self.assertEqual(7, mock_get_chunk_dest_path.call_count)

@mock.patch(
"eodag.plugins.download.aws.AwsDownload.get_authenticated_objects",
autospec=True,
)
def test_plugins_download_aws_no_matching_product_type(
self,
mock_get_authenticated_objects: mock.Mock,
):
"""AwsDownload.download() must fail if no product chunk is available"""

plugin = self.get_download_plugin(self.product)
self.product.properties["tileInfo"] = "http://example.com/tileInfo.json"

# no SAFE build and flatten_top_dirs
plugin.config.products[self.product.product_type]["build_safe"] = False
plugin.config.flatten_top_dirs = True

with self.assertRaises(NoMatchingProductType):
plugin.download(self.product, outputs_prefix=self.output_dir)


class TestDownloadPluginS3Rest(BaseDownloadPluginTest):
def setUp(self):
Expand Down

0 comments on commit dc24261

Please sign in to comment.