Repository: CS-SI/eodag
Pull request #797 (2023-08-28 09:42:36)

fix(server): missing intersects parameter in request body model
Fixes server mode missing `intersects` parameter in pydantic request model. This caused lacking geometry filtering using this parameter

github-actions[bot]: ## Test Results
    1 files   -        3      1 suites   - 3   1m 10s [:stopwatch:](https://github.com/EnricoMi/publish-unit-test-result-action/blob/v2.9.0/README.md#the-symbols "duration of all tests") - 3m 55s
408 tests +       1  403 [:heavy_check_mark:](https://github.com/EnricoMi/publish-unit-test-result-action/blob/v2.9.0/README.md#the-symbols "passed tests")  -        2  2 [:zzz:](https://github.com/EnricoMi/publish-unit-test-result-action/blob/v2.9.0/README.md#the-symbols "skipped / disabled tests") ±  0  3 [:x:](https://github.com/EnricoMi/publish-unit-test-result-action/blob/v2.9.0/README.md#the-symbols "failed tests") +3 
408 runs   - 1 220  403 [:heavy_check_mark:](https://github.com/EnricoMi/publish-unit-test-result-action/blob/v2.9.0/README.md#the-symbols "passed tests")  - 1 159  2 [:zzz:](https://github.com/EnricoMi/publish-unit-test-result-action/blob/v2.9.0/README.md#the-symbols "skipped / disabled tests")  - 64  3 [:x:](https://github.com/EnricoMi/publish-unit-test-result-action/blob/v2.9.0/README.md#the-symbols "failed tests") +3 

For more details on these failures, see [this check](https://github.com/CS-SI/eodag/runs/16266249179).

Results for commit b8e31459. ± Comparison against base commit 03c72bcf.

[test-results]:data:application/gzip;base64,H4sIAMts7GQC/1WMwQ7CIBAFf6Xh7KFACeDPGNyyCbEthsLJ+O8uGEs9zryXeTEMi9/ZdeCXge0l5APmklwOcSPUIzEtuW7TaH502wtAU7KrR3iSEodAFxYS/eFTiolMjaay9WaF/+TX9GLjU7DxuQdxXUMmYHfjJZ+UBS6MdNZJtNw4UMJKadTsEDUIrZC9P8x0egEEAQAA

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 b8e31459c1283a9a3f918ac5293385daff7c275f </p>
github-actions[bot]: <strong>Code Coverage (Windows)</strong>

| File | Coverage |   |
| - | :-: | :-: |
| **All files** | `36%` | :x: |

_Minimum allowed coverage is `70%`_

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

Patch:
diff --git a/eodag/rest/server.py b/eodag/rest/server.py
index 541da3a8..057fb863 100755
--- a/eodag/rest/server.py
+++ b/eodag/rest/server.py
@@ -288,6 +288,7 @@ class SearchBody(BaseModel):
     collections: Union[List[str], str]
     datetime: Union[str, None] = None
     bbox: Union[list, str, None] = None
+    intersects: Union[dict, None] = None
     limit: Union[int, None] = 20
     page: Union[int, None] = 1
     query: Union[dict, None] = None
diff --git a/eodag/rest/utils.py b/eodag/rest/utils.py
index 76ab874c..64a7fb6c 100644
--- a/eodag/rest/utils.py
+++ b/eodag/rest/utils.py
@@ -263,13 +263,13 @@ def get_geometry(arguments):
             )
         )
 
-    if "intersects" in arguments and geom:
+    if "intersects" in arguments and arguments["intersects"] is not None and geom:
         new_geom = shape(arguments.pop("intersects"))
         if new_geom.intersects(geom):
             geom = new_geom.intersection(geom)
         else:
             geom = new_geom
-    elif "intersects" in arguments:
+    elif "intersects" in arguments and arguments["intersects"] is not None:
         geom = shape(arguments.pop("intersects"))
 
     if "geom" in arguments and geom:


Test patch:
diff --git a/tests/units/test_http_server.py b/tests/units/test_http_server.py
index 8cfe0926..f0ae711f 100644
--- a/tests/units/test_http_server.py
+++ b/tests/units/test_http_server.py
@@ -546,6 +546,28 @@ class RequestTestCase(unittest.TestCase):
             ),
         )
 
+    def test_intersects_post_search(self):
+        """POST search with intersects filtering through eodag server should return a valid response"""
+        self._request_valid(
+            "search",
+            protocol="POST",
+            post_data={
+                "collections": [self.tested_product_type],
+                "intersects": {
+                    "type": "Polygon",
+                    "coordinates": [[[0, 43], [0, 44], [1, 44], [1, 43], [0, 43]]],
+                },
+            },
+            expected_search_kwargs=dict(
+                provider="peps",
+                productType=self.tested_product_type,
+                page=1,
+                items_per_page=DEFAULT_ITEMS_PER_PAGE,
+                raise_errors=True,
+                geom=box(0, 43, 1, 44, ccw=False),
+            ),
+        )
+
     def test_ids_post_search(self):
         """POST search with ids filtering through eodag server should return a valid response"""
         self._request_valid(