Repository: CS-SI/eodag
Pull request #840 (2023-09-21 13:22:55)

fix: default dates on wekeo
Default dates usage fix on `wekeo`

github-actions[bot]: ## Test Results
       4 files  ±0         4 suites  ±0   7m 9s [:stopwatch:](https://github.com/EnricoMi/publish-unit-test-result-action/blob/v2.9.0/README.md#the-symbols "duration of all tests") -15s
   431 tests +1     428 [:heavy_check_mark:](https://github.com/EnricoMi/publish-unit-test-result-action/blob/v2.9.0/README.md#the-symbols "passed tests") +1    3 [:zzz:](https://github.com/EnricoMi/publish-unit-test-result-action/blob/v2.9.0/README.md#the-symbols "skipped / disabled tests") ±0  0 [:x:](https://github.com/EnricoMi/publish-unit-test-result-action/blob/v2.9.0/README.md#the-symbols "failed tests") ±0 
1 724 runs  +4  1 648 [:heavy_check_mark:](https://github.com/EnricoMi/publish-unit-test-result-action/blob/v2.9.0/README.md#the-symbols "passed tests") +4  76 [:zzz:](https://github.com/EnricoMi/publish-unit-test-result-action/blob/v2.9.0/README.md#the-symbols "skipped / disabled tests") ±0  0 [:x:](https://github.com/EnricoMi/publish-unit-test-result-action/blob/v2.9.0/README.md#the-symbols "failed tests") ±0 

Results for commit 65966c8a. ± Comparison against base commit fefce060.

[test-results]:data:application/gzip;base64,H4sIAPdEDGUC/03MQQ6DIBCF4asY1l0AwgC9TIMICalKg7BqevciFery/2by3sj5xe7oPrDbgPbsU485R5182I6kqkA5pXocSavHno2pD/JPT/8qNHZw2i8FcAcbY4inxLwdm0RQdlbbJMBkp9+mgAaXzdrXSRPW1acSCLgCMFIzSowTCk9qokRwC1JSixUmbAbDGUWfLz/JVG8IAQAA

github-actions[bot]: <strong>Code Coverage (Ubuntu)</strong>

| File | Coverage |   |
| - | :-: | :-: |
| **All files** | `82%` | :white_check_mark: |

_Minimum allowed coverage is `70%`_

<p align="right">Generated by :monkey: cobertura-action against 65966c8a421cf790b9b2175e6882e09014d6c542 </p>
github-actions[bot]: <strong>Code Coverage (Windows)</strong>

| File | Coverage |   |
| - | :-: | :-: |
| **All files** | `76%` | :white_check_mark: |

_Minimum allowed coverage is `70%`_

<p align="right">Generated by :monkey: cobertura-action against 65966c8a421cf790b9b2175e6882e09014d6c542 </p>

Patch:
diff --git a/eodag/plugins/search/data_request_search.py b/eodag/plugins/search/data_request_search.py
index 4b83cd30..99523aab 100644
--- a/eodag/plugins/search/data_request_search.py
+++ b/eodag/plugins/search/data_request_search.py
@@ -1,5 +1,6 @@
 import logging
 import time
+from datetime import datetime
 
 import requests
 
@@ -11,6 +12,7 @@ from eodag.api.product.metadata_mapping import (
     properties_from_json,
 )
 from eodag.plugins.search.base import Search
+from eodag.rest.stac import DEFAULT_MISSION_START_DATE
 from eodag.utils import (
     GENERIC_PRODUCT_TYPE,
     deepcopy,
@@ -171,6 +173,17 @@ class DataRequestSearch(Search):
             }
         )
 
+        # update dates if needed
+        if getattr(self.config, "dates_required", True):
+            if not keywords.get("startTimeFromAscendingNode", None):
+                keywords["startTimeFromAscendingNode"] = getattr(
+                    self.config, "product_type_config", {}
+                ).get("missionStartDate", DEFAULT_MISSION_START_DATE)
+            if not keywords.get("completionTimeFromAscendingNode", None):
+                keywords["completionTimeFromAscendingNode"] = getattr(
+                    self.config, "product_type_config", {}
+                ).get("missionEndDate", datetime.utcnow().isoformat())
+
         # ask for data_request_id if not set (it must exist when iterating over pages)
         if not self.data_request_id:
             data_request_id = self._create_data_request(
diff --git a/eodag/resources/providers.yml b/eodag/resources/providers.yml
index 866731f4..068a77bf 100644
--- a/eodag/resources/providers.yml
+++ b/eodag/resources/providers.yml
@@ -3749,6 +3749,7 @@
     auth_error_code: 401
     results_entry: content
     two_passes_id_search: true
+    dates_required: true
     pagination:
       start_page: 0
       max_items_per_page: 20
@@ -3785,8 +3786,6 @@
     S2_MSI_L1C:
       productType: EO:ESA:DAT:SENTINEL-2:MSI
       processingLevel: S2MSI1C
-      startTimeFromAscendingNode: "2015-07-16T00:00:00.000Z"
-      completionTimeFromAscendingNode: "2015-07-17T00:00:00.000Z"
       metadata_mapping:
         id:
           - '{{"stringInputValues": [{{"name": "productIdentifier", "value": "{id}"}}]}}'
@@ -3800,8 +3799,6 @@
     S2_MSI_L2A:
       productType: EO:ESA:DAT:SENTINEL-2:MSI
       processingLevel: S2MSI2A
-      startTimeFromAscendingNode: "2018-03-26T00:00:00Z"
-      completionTimeFromAscendingNode: "2018-03-27T00:00:00Z"
       metadata_mapping:
         id:
           - '{{"stringInputValues": [{{"name": "productIdentifier", "value": "{id}"}}]}}'
@@ -4098,8 +4095,6 @@
         geometry: '-180 -90 180 90' # geometry is not available for this product type
     CLMS_GLO_FCOVER_333M:
       productType: EO:CLMS:DAT:CGLS_GLOBAL_FCOVER300_V1_333M
-      startTimeFromAscendingNode: "2014-01-10T00:00"
-      completionTimeFromAscendingNode: "2014-01-10T00:00"
       metadata_mapping:
         id: '{$.productInfo.product#remove_extension}'
         startTimeFromAscendingNode:
@@ -4111,8 +4106,6 @@
         geometry: '-180 -90 180 90' # geometry is not available for this product type
     CLMS_GLO_NDVI_333M:
       productType: EO:CLMS:DAT:CGLS_GLOBAL_NDVI300_V1_333M
-      startTimeFromAscendingNode: "2014-01-01T00:00"
-      completionTimeFromAscendingNode: "2014-01-01T00:00"
       metadata_mapping:
         id: '{$.productInfo.product#remove_extension}'
         startTimeFromAscendingNode:
@@ -4124,8 +4117,6 @@
         geometry: '-180 -90 180 90' # geometry is not available for this product type
     CLMS_GLO_NDVI_1KM_LTS:
       productType: EO:CLMS:DAT:CGLS_GLOBAL_NDVI_V2_1KM_LTS
-      startTimeFromAscendingNode: "1999-01-01T00:00"
-      completionTimeFromAscendingNode: "1999-01-01T00:00"
       metadata_mapping:
         id: '{$.productInfo.product#remove_extension}'
         startTimeFromAscendingNode:
@@ -4137,8 +4128,6 @@
         geometry: '-180 -90 180 90' # geometry is not available for this product type
     CLMS_GLO_DMP_333M:
       productType: EO:CLMS:DAT:CGLS_GLOBAL_DMP300_V1_333M
-      startTimeFromAscendingNode: "2014-01-10T00:00"
-      completionTimeFromAscendingNode: "2014-01-10T00:00"
       metadata_mapping:
         id: '{$.productInfo.product#remove_extension}'
         startTimeFromAscendingNode:
@@ -4150,8 +4139,6 @@
         geometry: '-180 -90 180 90' # geometry is not available for this product type
     CLMS_GLO_GDMP_333M:
       productType: EO:CLMS:DAT:CGLS_GLOBAL_GDMP300_V1_333M
-      startTimeFromAscendingNode: "2014-01-10T00:00"
-      completionTimeFromAscendingNode: "2014-01-10T00:00"
       metadata_mapping:
         id: '{$.productInfo.product#remove_extension}'
         startTimeFromAscendingNode:
@@ -4163,8 +4150,6 @@
         geometry: '-180 -90 180 90' # geometry is not available for this product type
     CLMS_GLO_LAI_333M:
       productType: EO:CLMS:DAT:CGLS_GLOBAL_LAI300_V1_333M
-      startTimeFromAscendingNode: "2014-01-10T00:00"
-      completionTimeFromAscendingNode: "2014-01-10T00:00"
       metadata_mapping:
         id: '{$.productInfo.product#remove_extension}'
         startTimeFromAscendingNode:
@@ -4176,8 +4161,6 @@
         geometry: '-180 -90 180 90' # geometry is not available for this product type
     CLMS_GLO_FAPAR_333M:
       productType: EO:CLMS:DAT:CGLS_GLOBAL_FAPAR300_V1_333M
-      startTimeFromAscendingNode: "2014-01-10T00:00"
-      completionTimeFromAscendingNode: "2014-01-10T00:00"
       metadata_mapping:
         id: '{$.productInfo.product#remove_extension}'
         startTimeFromAscendingNode:
@@ -4189,8 +4172,6 @@
         geometry: '-180 -90 180 90' # geometry is not available for this product type
     EEA_DAILY_SWI_1KM:
       productType: EO:EEA:DAT:VEGETATION:DAILY_SWI_1KM_EUROPE_V1
-      startTimeFromAscendingNode: "2015-01-01T00:00"
-      completionTimeFromAscendingNode: "2015-01-01T00:00"
       metadata_mapping:
         id: '{$.productInfo.product#remove_extension}'
         startTimeFromAscendingNode:
@@ -4202,8 +4183,6 @@
         geometry: '-180 -90 180 90' # geometry is not available for this product type
     EEA_DAILY_SSM_1KM:
       productType: EO:EEA:DAT:VEGETATION:DAILY_SSM_1KM_EUROPE_V1
-      startTimeFromAscendingNode: "2015-01-01T00:00"
-      completionTimeFromAscendingNode: "2015-01-01T00:00"
       metadata_mapping:
         id: '{$.productInfo.product#remove_extension}'
         startTimeFromAscendingNode:
@@ -4304,7 +4283,6 @@
         - "950"
         - "975"
         - "1000"
-      startTimeFromAscendingNode: "2023-01-01T00:00"
       format: grib # netcdf format may fail
       metadata_mapping:
         id: '$.productInfo.product'
@@ -4391,7 +4369,6 @@
         - "950"
         - "975"
         - "1000"
-      startTimeFromAscendingNode: "2023-01-01T00:00"
       format: grib # netcdf format may fail
       metadata_mapping:
         id: '$.productInfo.product'
@@ -4450,7 +4427,6 @@
         - total_precipitation
         - leaf_area_index_high_vegetation
         - leaf_area_index_low_vegetation
-      startTimeFromAscendingNode: "2023-01-01T00:00"
       format: grib # netcdf format may fail
       metadata_mapping:
         id: '$.productInfo.product'
@@ -4506,7 +4482,6 @@
         - total_precipitation
         - leaf_area_index_high_vegetation
         - leaf_area_index_low_vegetation
-      startTimeFromAscendingNode: "2023-01-01T00:00"
       format: grib # netcdf format may fail
       metadata_mapping:
         id: '$.productInfo.product'
@@ -4547,7 +4522,6 @@
         - significant_height_of_combined_wind_waves_and_swell
         - surface_pressure
         - total_precipitation
-      startTimeFromAscendingNode: "2023-01-01T00:00"
       format: grib # netcdf format may fail
       metadata_mapping:
         id: '$.productInfo.product'
@@ -4588,7 +4562,6 @@
         - significant_height_of_combined_wind_waves_and_swell
         - surface_pressure
         - total_precipitation
-      startTimeFromAscendingNode: "2023-01-01T00:00"
       format: grib # netcdf format may fail
       metadata_mapping:
         id: '$.productInfo.product'
@@ -4614,7 +4587,6 @@
       productType: EO:ECMWF:DAT:REANALYSIS_UERRA_EUROPE_SINGLE_LEVELS
       variable: total_cloud_cover
       origin: uerra_harmonie
-      startTimeFromAscendingNode: "2019-01-01T00:00"
       format: grib # netcdf format may fail
       metadata_mapping:
         id: '$.productInfo.product'
@@ -4647,7 +4619,6 @@
       storeDownloadUrl: True
     SATELLITE_SEA_LEVEL_BLACK_SEA:
       productType: EO:ECMWF:DAT:SATELLITE_SEA_LEVEL_BLACK_SEA
-      startTimeFromAscendingNode: "1993-01-01T00:00"
       variable: all
       format: zip
       variable: all
@@ -4738,7 +4709,6 @@
         - ignition_component
       version:
         - "4.0"
-      startTimeFromAscendingNode: "2020-01-01T00:00"
       metadata_mapping:
         providerProductType:
           - '{{ "multiStringSelectValues": [ {{"name": "product_type", "value": {providerProductType} }} ] }}'
@@ -4805,7 +4775,6 @@
       providerProductType:
         - control_forecast
       format: grib
-      startTimeFromAscendingNode: "2023-01-01T00:00"
       metadata_mapping:
         providerProductType:
           - '{{ "multiStringSelectValues": [ {{"name": "product_type", "value": {providerProductType} }} ] }}'
@@ -4848,7 +4817,6 @@
       providerProductType:
         - consolidated
       format: grib
-      startTimeFromAscendingNode: "2023-01-01T00:00"
       metadata_mapping:
         providerProductType:
           - '{{ "multiStringSelectValues": [ {{"name": "product_type", "value": {providerProductType} }} ] }}'
@@ -4938,7 +4906,6 @@
       hydrological_model:
         - lisflood
       format: grib
-      startTimeFromAscendingNode: "1999-01-03T00:00"
       metadata_mapping:
         providerProductType:
           - '{{ "multiStringSelectValues": [ {{"name": "product_type", "value": {providerProductType} }} ] }}'
@@ -4989,7 +4956,6 @@
         - "120"
         - "144"
       format: grib
-      startTimeFromAscendingNode: "2020-12-01T00:00"
       metadata_mapping:
         variable:
           - '{{ "multiStringSelectValues": [ {{"name": "variable", "value": {variable} }} ] }}'
@@ -5031,7 +4997,6 @@
       leadtime_hour:
         - "24"
       format: grib
-      startTimeFromAscendingNode: "2016-01-01T00:00"
       metadata_mapping:
         variable:
           - '{{ "multiStringSelectValues": [ {{"name": "variable", "value": {variable} }} ] }}'
@@ -5134,7 +5099,6 @@
       variable: volumetric_soil_moisture
       model_levels: soil_levels
       format: grib.zip
-      startTimeFromAscendingNode: "2023-01-01T00:00"
       metadata_mapping:
         providerProductType:
           - '{{ "multiStringSelectValues": [ {{"name": "product_type", "value": {providerProductType} }} ] }}'
@@ -5174,7 +5138,6 @@
       productType: EO:ECMWF:DAT:EFAS_HISTORICAL
       soil_level:
         - "1"
-      startTimeFromAscendingNode: "2023-01-01T00:00"
       system_version: version_4_0
       variable: volumetric_soil_moisture
       model_levels: soil_levels
@@ -5248,7 +5211,6 @@
         - "186"
         - "192"
         - "198"
-      startTimeFromAscendingNode: "1999-01-03T00:00:00Z"
       variable: volumetric_soil_moisture
       model_levels: soil_levels
       format: grib.zip
@@ -5296,7 +5258,6 @@
         - "144"
         - "168"
         - "192"
-      startTimeFromAscendingNode: "2020-12-01T00:00"
       variable: volumetric_soil_moisture
       model_levels: soil_levels
       format: grib.zip
@@ -5340,7 +5301,6 @@
         - "144"
         - "168"
         - "192"
-      startTimeFromAscendingNode: "2020-01-01T00:00"
       variable: volumetric_soil_moisture
       model_levels: soil_levels
       format: grib.zip
@@ -5377,7 +5337,6 @@
         - level_2
       version:
         - "4.0"
-      startTimeFromAscendingNode: "2002-10-01T00:00"
       variable: xco2
       sensor_and_algorithm: sciamachy_wfmd
       format: zip
@@ -5415,7 +5374,6 @@
         - level_2
       version:
         - "4.0"
-      startTimeFromAscendingNode: "2002-10-01T00:00"
       variable: xch4
       sensor_and_algorithm: sciamachy_wfmd
       format: zip
@@ -5472,7 +5430,6 @@
         - "1000"
       leadtime_month:
         - "1"
-      startTimeFromAscendingNode: "2017-01-01T00:00:00Z"
       originating_centre: ecmwf
       system: "5"
       format: grib
@@ -5523,7 +5480,6 @@
         - 10m_wind_speed_anomaly
       leadtime_month:
         - "1"
-      startTimeFromAscendingNode: "2023-01-01T00:00:00Z"
       originating_centre: ecmwf
       system: "51"
       format: grib
@@ -5601,7 +5557,6 @@
         - "186"
         - "192"
         - "198"
-      startTimeFromAscendingNode: "2023-01-01T00:00:00Z"
       originating_centre: ecmwf
       system: "51"
       format: grib
@@ -5674,7 +5629,6 @@
         - "168"
         - "180"
         - "192"
-      startTimeFromAscendingNode: "2023-01-01T00:00:00Z"
       originating_centre: ecmwf
       system: "51"
       format: grib
@@ -5734,7 +5688,6 @@
         - "850"
         - "925"
         - "1000"
-      startTimeFromAscendingNode: "2023-01-01T00:00:00Z"
       originating_centre: ecmwf
       system: "51"
       format: grib
@@ -5784,7 +5737,6 @@
         - ensemble_mean
       leadtime_month:
         - "1"
-      startTimeFromAscendingNode: "2023-01-01T00:00:00Z"
       originating_centre: ecmwf
       system: "51"
       format: grib


Test patch:
diff --git a/tests/units/test_search_plugins.py b/tests/units/test_search_plugins.py
index de7c155a..f293fa1b 100644
--- a/tests/units/test_search_plugins.py
+++ b/tests/units/test_search_plugins.py
@@ -15,17 +15,19 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-
 import json
 import re
 import unittest
+from datetime import datetime, timedelta, timezone
 from pathlib import Path
 from unittest import mock
 
+import dateutil
 import responses
 from requests import RequestException
 
 from tests.context import (
+    DEFAULT_MISSION_START_DATE,
     HTTP_REQ_TIMEOUT,
     TEST_RESOURCES_PATH,
     USER_AGENT,
@@ -1277,43 +1279,125 @@ class TestSearchPluginDataRequestSearch(BaseSearchPluginTest):
             headers=getattr(self.search_plugin.auth, "headers", ""),
         )
 
-    @mock.patch("eodag.plugins.search.data_request_search.requests.get", autospec=True)
-    def test_plugins_search_datareq_distinct_product_type_mtd_mapping(
-        self, mock__request
-    ):
+    def test_plugins_search_datareq_distinct_product_type_mtd_mapping(self):
         """The metadata mapping for data_request_search should not mix specific product-types metadata-mapping"""
         geojson_geometry = self.search_criteria_s2_msi_l1c["geometry"].__geo_interface__
-        mock__request.return_value = mock.Mock()
         result = {
-            "context": {"matched": 1},
-            "features": [
+            "totItems": 1,
+            "content": [
                 {
-                    "id": "foo",
-                    "geometry": geojson_geometry,
+                    "productInfo": {"product": "FOO_BAR_BAZ_QUX_QUUX_CORGE"},
+                    "extraInformation": {"footprint": geojson_geometry},
+                    "url": "http://foo.bar",
                 },
             ],
         }
-        mock__request.return_value.json.side_effect = [result, result]
-        search_plugin = self.get_search_plugin("wekeo")
 
-        # update metadata_mapping only for S1_SAR_GRD
-        search_plugin.config.products["S1_SAR_GRD"]["metadata_mapping"]["bar"] = (
-            None,
-            "baz",
-        )
-        products, estimate = search_plugin.query(
-            productType="S1_SAR_GRD",
-            auth=None,
-        )
-        self.assertIn("bar", products[0].properties)
-        self.assertEqual(products[0].properties["bar"], "baz")
+        @responses.activate(registry=responses.registries.FirstMatchRegistry)
+        def run():
+            responses.add(
+                responses.POST,
+                self.search_plugin.config.data_request_url,
+                status=200,
+                json={"jobId": "123"},
+            )
+            responses.add(
+                responses.GET,
+                self.search_plugin.config.status_url + "123",
+                json={"status": "completed"},
+            )
+            responses.add(
+                responses.GET,
+                self.search_plugin.config.result_url.format(
+                    jobId=123, items_per_page=20, page=0
+                ),
+                json=result,
+            )
 
-        # search with another product type
-        self.assertNotIn(
-            "bar", search_plugin.config.products["S1_SAR_SLC"]["metadata_mapping"]
-        )
-        products, estimate = search_plugin.query(
-            productType="S1_SAR_SLC",
-            auth=None,
-        )
-        self.assertNotIn("bar", products[0].properties)
+            # update metadata_mapping only for S1_SAR_GRD
+            self.search_plugin.config.products["S1_SAR_GRD"]["metadata_mapping"][
+                "bar"
+            ] = (
+                None,
+                "baz",
+            )
+            products, estimate = self.search_plugin.query(
+                productType="S1_SAR_GRD",
+                auth=None,
+            )
+            self.assertIn("bar", products[0].properties)
+            self.assertEqual(products[0].properties["bar"], "baz")
+
+            # search with another product type
+            self.assertNotIn(
+                "bar",
+                self.search_plugin.config.products["S1_SAR_SLC"]["metadata_mapping"],
+            )
+            products, estimate = self.search_plugin.query(
+                productType="S1_SAR_SLC",
+                auth=None,
+            )
+            self.assertNotIn("bar", products[0].properties)
+
+        run()
+
+    def test_plugins_search_datareq_dates_required(self):
+        """data_request_search query should use default dates if required"""
+        geojson_geometry = self.search_criteria_s2_msi_l1c["geometry"].__geo_interface__
+        result = {
+            "totItems": 1,
+            "content": [
+                {
+                    "productInfo": {"product": "FOO_BAR_BAZ_QUX_QUUX_CORGE"},
+                    "extraInformation": {"footprint": geojson_geometry},
+                    "url": "http://foo.bar",
+                },
+            ],
+        }
+
+        @responses.activate(registry=responses.registries.FirstMatchRegistry)
+        def run():
+            responses.add(
+                responses.POST,
+                self.search_plugin.config.data_request_url,
+                status=200,
+                json={"jobId": "123"},
+            )
+            responses.add(
+                responses.GET,
+                self.search_plugin.config.status_url + "123",
+                json={"status": "completed"},
+            )
+            responses.add(
+                responses.GET,
+                self.search_plugin.config.result_url.format(
+                    jobId=123, items_per_page=20, page=0
+                ),
+                json=result,
+            )
+
+            self.assertTrue(self.search_plugin.config.dates_required)
+
+            products, estimate = self.search_plugin.query(
+                productType="S1_SAR_GRD",
+                auth=None,
+            )
+
+            request_dict = json.loads(responses.calls[0].request.body)
+
+            self.assertEqual(request_dict["datasetId"], "EO:ESA:DAT:SENTINEL-1:SAR")
+            self.assertEqual(
+                dateutil.parser.parse(
+                    request_dict["dateRangeSelectValues"][0]["start"]
+                ),
+                dateutil.parser.parse(DEFAULT_MISSION_START_DATE),
+            )
+            self.assertLess(
+                datetime.now(timezone.utc)
+                - dateutil.parser.parse(
+                    request_dict["dateRangeSelectValues"][0]["end"]
+                ),
+                timedelta(minutes=1),
+            )
+
+        run()