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): cop_marine - handling of ids with points #1364

Merged
merged 1 commit into from
Oct 31, 2024
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
5 changes: 3 additions & 2 deletions eodag/plugins/search/cop_marine.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import copy
import logging
import os
import re
from datetime import datetime
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, cast
Expand Down Expand Up @@ -202,7 +203,7 @@ def _create_product(
use_dataset_dates: bool = False,
) -> Optional[EOProduct]:

item_id = item_key.split("/")[-1].split(".")[0]
item_id = os.path.splitext(item_key.split("/")[-1])[0]
download_url = s3_url + "/" + item_key
properties = {
"id": item_id,
Expand Down Expand Up @@ -391,7 +392,7 @@ def query(

for obj in s3_objects["Contents"]:
item_key = obj["Key"]
item_id = item_key.split("/")[-1].split(".")[0]
item_id = os.path.splitext(item_key.split("/")[-1])[0]
# filter according to date(s) in item id
item_dates = re.findall(r"(\d{4})(0[1-9]|1[0-2])([0-3]\d)", item_id)
if not item_dates:
Expand Down
64 changes: 43 additions & 21 deletions tests/units/test_search_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2776,13 +2776,13 @@ def setUp(self):
self.list_objects_response1 = {
"Contents": [
{
"Key": "native/PRODUCT_A/dataset-number-one/item_20200102_20200103_hdkIFEKFNEDNF_20210101.nc"
"Key": "native/PRODUCT_A/dataset-number-one/item_20200102_20200103_hdkIFE.KFNEDNF_20210101.nc"
},
{
"Key": "native/PRODUCT_A/dataset-number-one/item_20200104_20200105_hdkIFEKFNEDNF_20210101.nc"
},
{
"Key": "native/PRODUCT_A/dataset-number-one/item_20200302_20200303_hdkIFEKFNEDNF_20210101.nc"
"Key": "native/PRODUCT_A/dataset-number-one/item_20200302_20200303_hdkIFEKFNEDN_20210101.nc"
},
]
}
Expand Down Expand Up @@ -2972,32 +2972,45 @@ def test_plugins_search_cop_marine_query_with_id(self, mock_requests_get):
self.product_data,
self.dataset1_data,
self.dataset2_data,
self.product_data,
self.dataset1_data,
self.dataset2_data,
]

search_plugin = self.get_search_plugin("PRODUCT_A", self.provider)

with mock.patch("eodag.plugins.search.cop_marine._get_s3_client") as s3_stub:
s3_stub.return_value = self.s3
stubber = Stubber(self.s3)
stubber.add_response(
"list_objects",
self.list_objects_response1,
{"Bucket": "bucket1", "Prefix": "native/PRODUCT_A/dataset-number-one"},
)
stubber.add_response(
"list_objects",
{},
{
"Bucket": "bucket1",
"Marker": "native/PRODUCT_A/dataset-number-one/item_20200302_20200303_hdkIFEKFNEDNF_20210101.nc",
"Prefix": "native/PRODUCT_A/dataset-number-one",
},
)
stubber.add_response(
"list_objects",
self.list_objects_response2,
{"Bucket": "bucket1", "Prefix": "native/PRODUCT_A/dataset-number-two"},
)
for i in [
0,
1,
]: # add responses twice because 2 search requests will be executed
stubber.add_response(
"list_objects",
self.list_objects_response1,
{
"Bucket": "bucket1",
"Prefix": "native/PRODUCT_A/dataset-number-one",
},
)
stubber.add_response(
"list_objects",
{},
{
"Bucket": "bucket1",
"Marker": "native/PRODUCT_A/dataset-number-one/item_20200302_20200303_hdkIFEKFNEDN_20210101.nc",
"Prefix": "native/PRODUCT_A/dataset-number-one",
},
)
stubber.add_response(
"list_objects",
self.list_objects_response2,
{
"Bucket": "bucket1",
"Prefix": "native/PRODUCT_A/dataset-number-two",
},
)
stubber.activate()
result, num_total = search_plugin.query(
productType="PRODUCT_A",
Expand All @@ -3008,6 +3021,15 @@ def test_plugins_search_cop_marine_query_with_id(self, mock_requests_get):
"item_20200204_20200205_niznjvnqkrf_20210101",
result[0].properties["id"],
)
result, num_total = search_plugin.query(
productType="PRODUCT_A",
id="item_20200102_20200103_hdkIFE.KFNEDNF_20210101",
)
self.assertEqual(1, num_total)
self.assertEqual(
"item_20200102_20200103_hdkIFE.KFNEDNF_20210101",
result[0].properties["id"],
)

@mock.patch("eodag.plugins.search.cop_marine.requests.get")
def test_plugins_search_cop_marine_with_errors(self, mock_requests_get):
Expand Down