Skip to content

Commit

Permalink
tests: add tests for free text search of collections
Browse files Browse the repository at this point in the history
  • Loading branch information
dalpasso committed Nov 22, 2023
1 parent 4918896 commit 73ee524
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 97 deletions.
59 changes: 59 additions & 0 deletions tests/resources/ext_product_types_free_text_search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"astraea_eod": {
"providers_config": {
"foo": {
"productType": "foo",
"metadata_mapping": {
"cloudCover": "$.null"
}
},
"bar": {
"productType": "bar",
"metadata_mapping": {
"cloudCover": "$.null"
}
},
"foobar": {
"productType": "foobar",
"metadata_mapping": {
"cloudCover": "$.null"
}
}
},
"product_types_config": {
"foo": {
"abstract": "abstractFOO - This is FOO. FooAndBar",
"instrument": "Not Available",
"platform": "Not Available",
"platformSerialIdentifier": "Not Available",
"processingLevel": "Not Available",
"keywords": "suspendisse",
"license": "WTFPL",
"title": "titleFOO - Lorem FOO collection",
"missionStartDate": "2012-12-12T00:00:00.000Z"
},
"bar": {
"abstract": "abstractBAR - This is BAR",
"instrument": "Not Available",
"platform": "Not Available",
"platformSerialIdentifier": "Not Available",
"processingLevel": "Not Available",
"keywords": "lectus,lectus_bar_key",
"license": "WTFPL",
"title": "titleBAR - Lorem BAR collection (FooAndBar)",
"missionStartDate": "2012-12-12T00:00:00.000Z"
},
"foobar": {
"abstract": "abstract FOOBAR - This is FOOBAR",
"instrument": "Not Available",
"platform": "Not Available",
"platformSerialIdentifier": "Not Available",
"processingLevel": "Not Available",
"keywords": "tortor",
"license": "WTFPL",
"title": "titleFOOBAR - Lorem FOOBAR collection",
"missionStartDate": "2012-12-12T00:00:00.000Z"
}
}
}
}
63 changes: 63 additions & 0 deletions tests/units/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,69 @@ def test_list_product_types_fetch_providers(self, mock_fetch_product_types_list)
self.dag.list_product_types(provider="peps", fetch_providers=True)
mock_fetch_product_types_list.assert_called_once_with(self.dag, provider="peps")

def test_list_product_types_with_free_text_filter_ok(self):
"""Core api must correctly return the list of supported product types"""

product_types = self.dag.list_product_types(
fetch_providers=False, filter="ABSTRACTFOO"
)
self.assertIsInstance(product_types, list)
for product_type in product_types:
self.assertListProductTypesRightStructure(product_type)
# There should be no repeated product type in the output
self.assertEqual(len(product_types), len(set(pt["ID"] for pt in product_types)))

def test_list_product_types_with_free_text_filter(self):
"""Testing the search terms"""

with open(
os.path.join(TEST_RESOURCES_PATH, "ext_product_types_free_text_search.json")
) as f:
ext_product_types_conf = json.load(f)
self.dag.update_product_types_list(ext_product_types_conf)

# match in the abstract
product_types = self.dag.list_product_types(
fetch_providers=False, filter="ABSTRACTFOO"
)
product_types_ids = [r["ID"] for r in product_types or []]
self.assertListEqual(product_types_ids, ["foo"])

# passing the provider
product_types = self.dag.list_product_types(
provider="astraea_eod", fetch_providers=False, filter="ABSTRACTFOO"
)
product_types_ids = [r["ID"] for r in product_types or []]
self.assertListEqual(product_types_ids, ["foo"])

# match in the abstract
product_types = self.dag.list_product_types(
fetch_providers=False, filter=" FOO THIS IS "
)
product_types_ids = [r["ID"] for r in product_types or []]
self.assertListEqual(product_types_ids, ["foo"])

# match in the keywords
product_types = self.dag.list_product_types(
fetch_providers=False, filter="LECTUS_BAR_KEY"
)
product_types_ids = [r["ID"] for r in product_types or []]
self.assertListEqual(product_types_ids, ["bar"])

# match in the title
product_types = self.dag.list_product_types(
fetch_providers=False, filter="COLLECTION FOOBAR"
)
product_types_ids = [r["ID"] for r in product_types or []]
self.assertListEqual(product_types_ids, ["foobar"])

# multiple terms
product_types = self.dag.list_product_types(
fetch_providers=False, filter="FOOANDBAR,FOOBAR"
)
product_types_ids = [r["ID"] for r in product_types or []]
self.assertListEqual(product_types_ids, ["bar", "foo", "foobar"])

def test_update_product_types_list(self):
"""Core api.update_product_types_list must update eodag product types list"""
with open(os.path.join(TEST_RESOURCES_PATH, "ext_product_types.json")) as f:
Expand Down
101 changes: 4 additions & 97 deletions tests/units/test_http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,104 +1048,11 @@ def test_product_type_queryables_with_provider(self):
check_links=False,
)

@mock.patch(
"eodag.rest.utils.eodag_api.guess_product_type", autospec=True, return_value=[]
)
@mock.patch(
"eodag.rest.utils.eodag_api.list_product_types",
autospec=True,
return_value=[
{
"ID": "S2_MSI_L1C",
"abstract": "The Level-1C product is composed of 100x100 km2 tiles "
"(ortho-images in UTM/WGS84 projection). [...]",
"instrument": "MSI",
"platform": "SENTINEL2",
"platformSerialIdentifier": ["S2A", "S2B"],
"processingLevel": "L1",
"sensorType": "OPTICAL",
"title": "SENTINEL2 Level - 1C",
},
{
"ID": "S2_MSI_L2A",
"abstract": "The Level-2A product provides Bottom Of Atmosphere (BOA) "
"reflectance images derived from the associated Level-1C "
"products. [...]",
"instrument": "MSI",
"platform": "SENTINEL2",
"platformSerialIdentifier": ["S2A", "S2B"],
"processingLevel": "L2",
"sensorType": "OPTICAL",
"title": "SENTINEL2 Level-2A",
},
{
"ID": "L57_REFLECTANCE",
"abstract": "Landsat 5,7,8 L2A data (old format) distributed by Theia "
"(2014 to 2017-03-20) using MUSCATE prototype, Lamber 93 "
"projection.",
"instrument": ["OLI", "TIRS"],
"platform": "LANDSAT",
"platformSerialIdentifier": ["L5", "L7", "L8"],
"processingLevel": "L2A",
"sensorType": "OPTICAL",
"title": "Landsat 5,7,8 Level-2A",
},
],
)
def test_collection_free_text_search(self, list_pt, guess_pt):
@mock.patch("eodag.rest.utils.eodag_api.list_product_types", autospec=True)
def test_collection_free_text_search(self, list_pt):
"""Test STAC Collection free-text search"""

url = "/collections?q=NOT FOUND"
r = self.app.get(url)
self.assertTrue(guess_pt.called)
self.assertTrue(list_pt.called)
self.assertEqual(200, r.status_code)
self.assertFalse(
[
it["title"]
for it in json.loads(r.content.decode("utf-8")).get("links", [])
if it["rel"] == "child"
],
)

url = "/collections?q= LEVEL - 1C "
url = "/collections?q=TERM1,TERM2"
r = self.app.get(url)
self.assertTrue(guess_pt.called)
self.assertTrue(list_pt.called)
list_pt.assert_called_once_with(provider=None, filter="TERM1,TERM2")
self.assertEqual(200, r.status_code)
self.assertListEqual(
["S2_MSI_L1C"],
[
it["title"]
for it in json.loads(r.content.decode("utf-8")).get("links", [])
if it["rel"] == "child"
],
)

url = "/collections?q=projection,atmosphere"
r = self.app.get(url)
self.assertTrue(guess_pt.called)
self.assertTrue(list_pt.called)
self.assertEqual(200, r.status_code)
self.assertListEqual(
["S2_MSI_L1C", "S2_MSI_L2A", "L57_REFLECTANCE"],
[
it["title"]
for it in json.loads(r.content.decode("utf-8")).get("links", [])
if it["rel"] == "child"
],
)

url = "/collections?q=l7"
r = self.app.get(url)
self.assertTrue(guess_pt.called)
self.assertTrue(list_pt.called)
self.assertEqual(200, r.status_code)
self.assertListEqual(
["L57_REFLECTANCE"],
[
it["title"]
for it in json.loads(r.content.decode("utf-8")).get("links", [])
if it["rel"] == "child"
],
)

0 comments on commit 73ee524

Please sign in to comment.