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: orderLink in build_search plugins #1082

Merged
merged 2 commits into from
Apr 3, 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
6 changes: 4 additions & 2 deletions eodag/plugins/search/build_search_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import geojson
import orjson
from jsonpath_ng import Fields
from jsonpath_ng import Child, Fields, Root

from eodag.api.product import EOProduct
from eodag.api.product.metadata_mapping import properties_from_json
Expand Down Expand Up @@ -171,8 +171,10 @@ def normalize_results(
parsed_properties["_dc_qs"] = quote_plus(qs)

# parse metadata needing downloadLink
dl_path = Fields("downloadLink")
dl_path_from_root = Child(Root(), dl_path)
for param, mapping in self.config.metadata_mapping.items():
if Fields("downloadLink") in mapping:
if dl_path in mapping or dl_path_from_root in mapping:
parsed_properties.update(
properties_from_json(parsed_properties, {param: mapping})
)
Expand Down
2 changes: 1 addition & 1 deletion eodag/resources/providers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3510,7 +3510,7 @@
timeIntervalsAlignment:
- '{{"timeIntervalsAlignment": {timeIntervalsAlignment#to_geojson} }}'
- '$.timeIntervalsAlignment'
orderLink: '{downloadLink#replace_str(r"^(.*)(\")(queries\")(.)",r"\1\2runOnJobQueue\2\4 true, \2\3\4")}'
orderLink: '{$.downloadLink#replace_str(r"^(.*)(\")(queries\")(.)",r"\1\2runOnJobQueue\2\4 true, \2\3\4")}'
products:
NEMSGLOBAL_TCDC:
queries: [{'domain':'NEMSGLOBAL','gapFillDomain':null,'timeResolution':'daily','codes':[{'code':71,'level':'sfc','aggregation':'mean'}]}]
Expand Down
26 changes: 25 additions & 1 deletion tests/units/test_search_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,8 @@ class TestSearchPluginBuildPostSearchResult(BaseSearchPluginTest):
@mock.patch("eodag.plugins.authentication.qsauth.requests.get", autospec=True)
def setUp(self, mock_requests_get):
super(TestSearchPluginBuildPostSearchResult, self).setUp()
# enable long diffs in test reports
self.maxDiff = None
# One of the providers that has a BuildPostSearchResult Search plugin
provider = "meteoblue"
self.search_plugin = self.get_search_plugin(provider=provider)
Expand All @@ -1385,8 +1387,10 @@ def test_plugins_search_buildpostsearchresult_count_and_search(
):
"""A query with a BuildPostSearchResult must return a single result"""

# custom query for meteoblue
custom_query = {"queries": {"foo": "bar"}}
products, estimate = self.search_plugin.query(
auth=self.auth_plugin,
auth=self.auth_plugin, **custom_query
)

mock_requests_post.assert_called_with(
Expand All @@ -1399,6 +1403,26 @@ def test_plugins_search_buildpostsearchresult_count_and_search(
)
self.assertEqual(estimate, 1)
self.assertIsInstance(products[0], EOProduct)
endpoint = "https://my.meteoblue.com/dataset/query"
default_geom = {
"coordinates": [
[[180, -90], [180, 90], [-180, 90], [-180, -90], [180, -90]]
],
"type": "Polygon",
}
# check downloadLink
self.assertEqual(
products[0].properties["downloadLink"],
f"{endpoint}?" + json.dumps({"geometry": default_geom, **custom_query}),
)
# check orderLink
self.assertEqual(
products[0].properties["orderLink"],
f"{endpoint}?"
+ json.dumps(
{"geometry": default_geom, "runOnJobQueue": True, **custom_query}
),
)


class MockResponse:
Expand Down
Loading