Repository: CS-SI/eodag
Pull request #978 (2024-01-09 15:58:29)

fix(server): common queryables for given provider
In server-mode, fixes returned common queryables for a given provider (http://127.0.0.1:5000/queryables?provider=peps)

github-actions[bot]: ## Test Results
    4 files  ±0      4 suites  ±0   4m 9s :stopwatch: ±0s
  447 tests ±0    444 :white_check_mark: ±0   3 :zzz: ±0  0 :x: ±0 
1 788 runs  ±0  1 710 :white_check_mark: ±0  78 :zzz: ±0  0 :x: ±0 

Results for commit caaa1a53. ± Comparison against base commit bf9b8e94.

[test-results]:data:application/gzip;base64,H4sIAPJtnWUC/03MyQ7CIBSF4VdpWLvgMgj4MoapCbEthmFlfHcRW+zy/+7NeaE5LD6j28QuE8o1lBGuJl1C3FoSphq0U+lHJo6652ptJ/anR3g2ogNmHZYGeIBPKaZdUt2+myCk3OvYBAF40G9TjJ/TZu/zpI3rGkoLZLXWoDkF6rjEjAtLqSLgDAZLqPFXgxXDCtD7Aw4YxfEIAQAA

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

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

_Minimum allowed coverage is `70%`_

<p align="right">Generated by :monkey: cobertura-action against caaa1a5313d580457c33921db01c23be6b094091 </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 caaa1a5313d580457c33921db01c23be6b094091 </p>

Patch:
diff --git a/eodag/rest/server.py b/eodag/rest/server.py
index d079c867..7d711148 100755
--- a/eodag/rest/server.py
+++ b/eodag/rest/server.py
@@ -676,7 +676,9 @@ def list_queryables(request: Request, provider: Optional[str] = None) -> Any:
     logger.debug(f"URL: {request.url}")
     queryables = StacQueryables(q_id=request.state.url)
     if provider:
-        queryables = fetch_collection_queryable_properties(None, provider)
+        queryables.properties.update(
+            fetch_collection_queryable_properties(None, provider)
+        )
 
     return jsonable_encoder(queryables)
 


Test patch:
diff --git a/tests/units/test_http_server.py b/tests/units/test_http_server.py
index 20aac0ea..36f51cc5 100644
--- a/tests/units/test_http_server.py
+++ b/tests/units/test_http_server.py
@@ -1037,11 +1037,37 @@ class RequestTestCase(unittest.TestCase):
 
     def test_queryables(self):
         """Request to /queryables should return a valid response."""
-        self._request_valid("queryables", check_links=False)
+        resp = self._request_valid("queryables", check_links=False)
+        self.assertListEqual(
+            list(resp.keys()),
+            [
+                "$schema",
+                "$id",
+                "type",
+                "title",
+                "description",
+                "properties",
+                "additionalProperties",
+            ],
+        )
 
     @mock.patch("eodag.plugins.search.qssearch.requests.get", autospec=True)
     def test_queryables_with_provider(self, mock_requests_get):
-        self._request_valid("queryables?provider=planetary_computer", check_links=False)
+        resp = self._request_valid(
+            "queryables?provider=planetary_computer", check_links=False
+        )
+        self.assertListEqual(
+            list(resp.keys()),
+            [
+                "$schema",
+                "$id",
+                "type",
+                "title",
+                "description",
+                "properties",
+                "additionalProperties",
+            ],
+        )
         mock_requests_get.assert_called_once_with(
             url="https://planetarycomputer.microsoft.com/api/stac/v1/search/../queryables",
             timeout=HTTP_REQ_TIMEOUT,
@@ -1050,9 +1076,21 @@ class RequestTestCase(unittest.TestCase):
 
     def test_product_type_queryables(self):
         """Request to /collections/{collection_id}/queryables should return a valid response."""
-        self._request_valid(
+        resp = self._request_valid(
             f"collections/{self.tested_product_type}/queryables", check_links=False
         )
+        self.assertListEqual(
+            list(resp.keys()),
+            [
+                "$schema",
+                "$id",
+                "type",
+                "title",
+                "description",
+                "properties",
+                "additionalProperties",
+            ],
+        )
 
     @mock.patch("eodag.plugins.search.qssearch.requests.get", autospec=True)
     def test_product_type_queryables_with_provider(self, mock_requests_get):
@@ -1076,6 +1114,18 @@ class RequestTestCase(unittest.TestCase):
             headers=USER_AGENT,
         )
         # returned queryables
+        self.assertListEqual(
+            list(res_no_provider.keys()),
+            [
+                "$schema",
+                "$id",
+                "type",
+                "title",
+                "description",
+                "properties",
+                "additionalProperties",
+            ],
+        )
         self.assertListEqual(
             list(res_no_provider["properties"].keys()),
             ["id", "collection", "geometry", "bbox", "datetime", "collections"],
@@ -1096,6 +1146,18 @@ class RequestTestCase(unittest.TestCase):
             timeout=HTTP_REQ_TIMEOUT,
             headers=USER_AGENT,
         )
+        self.assertListEqual(
+            list(res.keys()),
+            [
+                "$schema",
+                "$id",
+                "type",
+                "title",
+                "description",
+                "properties",
+                "additionalProperties",
+            ],
+        )
         # property added from provider queryables
         self.assertIn("s1:processing_level", res["properties"])
         # property updated with info from provider queryables