Skip to content

Commit

Permalink
fix: cop_marine - handling of ids with points (#1364)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlahovnik authored Oct 31, 2024
1 parent 90da4f0 commit 441cefa
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 23 deletions.
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 @@ -2777,13 +2777,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 @@ -2973,32 +2973,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 @@ -3009,6 +3022,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

0 comments on commit 441cefa

Please sign in to comment.