Skip to content

Commit 665d257

Browse files
astanga-csastanga-cs
authored andcommitted
Added pytests
1 parent c139a02 commit 665d257

File tree

5 files changed

+179
-7
lines changed

5 files changed

+179
-7
lines changed

services/common/rs_server_common/utils/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ def odata_to_stac(
260260
continue
261261
if stac_key == "geometry":
262262
feature_template["geometry"] = value
263-
feature_template["bbox"] = _bbox_from_geometry(feature_template["geometry"])
263+
if feature_template["geometry"]:
264+
feature_template["bbox"] = _bbox_from_geometry(feature_template["geometry"])
264265
continue
265266
if stac_key in feature_template["assets"]["file"]:
266267
feature_template["assets"]["file"][stac_key] = value

tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,15 @@ def prip_feature():
567567
return json.loads(f.read())
568568

569569

570+
@pytest.fixture(name="prip_feature_no_geom")
571+
@lru_cache(maxsize=1)
572+
def prip_feature_no_geom():
573+
"""Expected STAC Item for PRIP mapping test."""
574+
data_json = RESOURCES_FOLDER / "endpoints" / "prip_feature_no_geometry.json"
575+
with open(data_json, encoding="utf-8") as f:
576+
return json.loads(f.read())
577+
578+
570579
@pytest.fixture(name="prip_response")
571580
@lru_cache(maxsize=1)
572581
def prip_pickup_response():
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"stac_version": "1.1.0",
3+
"stac_extensions": [
4+
"https://stac-extensions.github.io/sat/v1.1.0/schema.json",
5+
"https://stac-extensions.github.io/product/v1.0.0/schema.json",
6+
"https://stac-extensions.github.io/processing/v1.2.0/schema.json",
7+
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
8+
"https://stac-extensions.github.io/eo/v2.0.0/schema.json",
9+
"https://stac-extensions.github.io/grid/v1.1.0/schema.json",
10+
"https://stac-extensions.github.io/view/v1.1.0/schema.json",
11+
"https://stac-extensions.github.io/sar/v1.3.0/schema.json",
12+
"https://cs-si.github.io/eopf-stac-extension/v1.2.0/schema.json",
13+
"https://stac-extensions.github.io/timestamps/v1.1.0/schema.json",
14+
"https://stac-extensions.github.io/authentication/v1.1.0/schema.json"
15+
],
16+
"type": "Feature",
17+
"id": "WITHOUT-GEOFOOTPRINT",
18+
"geometry": null,
19+
"properties": {
20+
"prip:id": "21111111-2222-3333-4444-555555555555",
21+
"published": "2024-08-01T00:00:00Z",
22+
"expires": "2024-08-08T00:00:00Z",
23+
"eopf:origin_datetime": "2024-08-01T00:00:00Z",
24+
"product:type": "S01SIWRAW",
25+
"sar:instrument_mode": "IW",
26+
"platform": "sentinel-1a",
27+
"processing:level": "RAW",
28+
"product:timeliness": null,
29+
"product:timeliness_category": null,
30+
"constellation": "sentinel-1",
31+
"datetime": "2024-08-01T00:00:00Z",
32+
"start_datetime": "2024-08-01T00:00:00Z",
33+
"end_datetime": "2024-08-01T00:06:00Z"
34+
},
35+
"assets": {
36+
"WITHOUT-GEOFOOTPRINT": {
37+
"href": "http://127.0.0.1:5000/Products(21111111-2222-3333-4444-555555555555)/$value",
38+
"type": "application/octet-stream",
39+
"roles": [
40+
"data",
41+
"metadata"
42+
],
43+
"file:size": 1234567,
44+
"file:checksum": "8277e0910d750195b448797616e091ad",
45+
"eviction_datetime": "2024-08-08T00:00:00Z"
46+
}
47+
},
48+
"links": [
49+
{
50+
"rel": "collection",
51+
"type": "application/json",
52+
"href": "http://testserver/prip/collections/S1A_L0_IW_RAW",
53+
"title": "WITHOUT-GEOFOOTPRINT"
54+
},
55+
{
56+
"rel": "parent",
57+
"type": "application/json",
58+
"href": "http://testserver/prip/collections/S1A_L0_IW_RAW",
59+
"title": "Parent Catalog"
60+
},
61+
{
62+
"rel": "root",
63+
"type": "application/json",
64+
"href": "http://testserver/prip/",
65+
"title": "STAC Root Catalog"
66+
},
67+
{
68+
"rel": "self",
69+
"type": "application/geo+json",
70+
"href": "http://testserver/prip/collections/S1A_L0_IW_RAW/items/WITHOUT-GEOFOOTPRINT",
71+
"title": "This collection"
72+
}
73+
],
74+
"collection": "S1A_L0_IW_RAW"
75+
}

tests/resources/endpoints/prip_pickup_response.json

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,85 @@
88
"OriginDate": "2024-08-01T00:00:00Z",
99
"PublicationDate": "2024-08-01T00:00:00Z",
1010
"EvictionDate": "2024-08-08T00:00:00Z",
11-
1211
"ContentDate": {
1312
"Start": "2024-08-01T00:00:00Z",
14-
"End": "2024-08-01T00:06:00Z"
13+
"End": "2024-08-01T00:06:00Z"
1514
},
16-
1715
"GeoFootprint": {
1816
"type": "Polygon",
1917
"coordinates": [
20-
[[-1.0, 51.0], [-1.0, 52.0], [0.0, 52.0], [0.0, 51.0], [-1.0, 51.0]]
18+
[
19+
[
20+
-1.0,
21+
51.0
22+
],
23+
[
24+
-1.0,
25+
52.0
26+
],
27+
[
28+
0.0,
29+
52.0
30+
],
31+
[
32+
0.0,
33+
51.0
34+
],
35+
[
36+
-1.0,
37+
51.0
38+
]
39+
]
2140
]
2241
},
23-
2442
"Checksum": [
2543
{
2644
"Algorithm": "MD5",
2745
"Value": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
2846
"ChecksumDate": "2024-08-01T00:00:00Z"
2947
}
3048
],
31-
49+
"Attributes": [
50+
{
51+
"@odata.type": "#OData.CSC.StringAttribute",
52+
"Name": "productType",
53+
"ValueType": "String",
54+
"Value": "IW_RAW__0N"
55+
},
56+
{
57+
"@odata.type": "#OData.CSC.StringAttribute",
58+
"Name": "platformShortName",
59+
"ValueType": "String",
60+
"Value": "SENTINEL-1"
61+
},
62+
{
63+
"@odata.type": "#OData.CSC.StringAttribute",
64+
"Name": "platformSerialIdentifier",
65+
"ValueType": "String",
66+
"Value": "A"
67+
}
68+
]
69+
},
70+
{
71+
"Id": "21111111-2222-3333-4444-555555555555",
72+
"Name": "WITHOUT-GEOFOOTPRINT",
73+
"ContentType": "application/octet-stream",
74+
"ContentLength": "1234567",
75+
"OriginDate": "2024-08-01T00:00:00Z",
76+
"PublicationDate": "2024-08-01T00:00:00Z",
77+
"EvictionDate": "2024-08-08T00:00:00Z",
78+
"ContentDate": {
79+
"Start": "2024-08-01T00:00:00Z",
80+
"End": "2024-08-01T00:06:00Z"
81+
},
82+
"GeoFootprint": null,
83+
"Checksum": [
84+
{
85+
"Algorithm": "MD5",
86+
"Value": "8277e0910d750195b448797616e091ad",
87+
"ChecksumDate": "2024-08-01T00:00:00Z"
88+
}
89+
],
3290
"Attributes": [
3391
{
3492
"@odata.type": "#OData.CSC.StringAttribute",

tests/test_search_endpoint.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,35 @@ def test_cadip_invalid_item_mapping(
721721
assert response.status_code == status.HTTP_404_NOT_FOUND
722722
assert response.json() == response_body
723723

724+
@pytest.mark.unit
725+
@responses.activate
726+
@pytest.mark.parametrize("fastapi_app", [ROUTER_PREFIX_PRIP], indirect=["fastapi_app"])
727+
def test_prip_feature_mapping_no_geometry(
728+
self,
729+
client: TestClient,
730+
prip_feature_no_geom,
731+
prip_response,
732+
):
733+
"""Test mapping of an prip reponse with expanded attributes"""
734+
responses.add(
735+
responses.GET,
736+
"http://127.0.0.1:5000/Products?$filter=contains(Name, "
737+
"'WITHOUT-GEOFOOTPRINT') and Attributes/OData.CSC.StringAttribute/any(att:att/Name eq 'productType' "
738+
"and att/OData.CSC.StringAttribute/Value eq 'IW_RAW__0N')"
739+
"&$orderby=PublicationDate desc&$top=1&$skip=0&$expand=Attributes",
740+
json={"value": [prip_response["value"][1]]},
741+
status=200,
742+
)
743+
response: Response = client.get("/prip/collections/S1A_L0_IW_RAW/items/WITHOUT-GEOFOOTPRINT")
744+
745+
returned_feature = response.json()
746+
assert returned_feature == prip_feature_no_geom, "Features don't match"
747+
748+
# geometry is None or missing → bbox should not be added
749+
assert returned_feature.get("geometry") is None, "Expected geometry to be None"
750+
751+
assert "bbox" not in returned_feature, "Expected bbox to be absent when geometry is missing"
752+
724753

725754
class TestFeatureCollectionOdataStacMapping:
726755
"""Class that group unittests for /*/collections/{collection-id}/items mapping from odata to stac."""

0 commit comments

Comments
 (0)