Skip to content

Commit 89c9064

Browse files
authored
STAC updates (#1105)
* STAC: use asset keys if they exist; update native STAC item response media type evaluation * fix test
1 parent 3a1de2e commit 89c9064

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

pycsw/core/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ def _parse_stac_resource(context, repos, record):
18901890
}
18911891

18921892
if link.get('title') is not None:
1893-
new_link['name'] = link.get('title')
1893+
new_link['name'] = key
18941894
new_link['description'] = link.get('title')
18951895
if link.get('type') is not None:
18961896
new_link['protocol'] = link.get('type')

pycsw/ogc/api/records.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ def record2json(record, url, collection, mode='ogcapi-records'):
11281128
:returns: `dict` of record GeoJSON
11291129
"""
11301130

1131-
if record.metadata_type == 'application/json':
1131+
if record.metadata_type in ['application/json', 'application/geo+json']:
11321132
rec = json.loads(record.metadata)
11331133
if rec.get('stac_version') is not None and rec['type'] == 'Feature' and mode == 'stac-api':
11341134
LOGGER.debug('Returning native STAC representation')

pycsw/stac/api.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,12 @@ def links2stacassets(collection, record):
565565
if 'assets' not in record:
566566
record['assets'] = {}
567567

568-
for count, value in enumerate(links_assets):
569-
record['assets'][count] = value
568+
for count, asset in enumerate(links_assets):
569+
if 'name' in asset:
570+
asset_key = asset.pop('name')
571+
else:
572+
asset_key = count
573+
574+
record['assets'][asset_key] = asset
570575

571576
return record

tests/functionaltests/suites/stac_api/test_stac_api_functional.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ def test_item(config):
247247
assert content['stac_version'] == '1.0.0'
248248
assert content['collection'] == 'S2MSI2A'
249249

250+
assert content['geometry']['coordinates'][0][0][0] == 16.33660021997006
251+
252+
assert 'assets' in content
253+
assert 'B02' in content['assets']
254+
assert 'product-metadata' in content['assets']
255+
250256
for link in content['links']:
251257
assert 'href' in link
252258
assert 'rel' in link
@@ -275,7 +281,7 @@ def test_json_transaction(config, sample_collection, sample_item,
275281

276282
assert content['id'] == '20201211_223832_CS2'
277283
assert content['geometry'] is None
278-
assert content['properties']['datetime'] == '2020-12-11T22:38:32Z'
284+
assert content['properties']['datetime'] == '2020-12-11T22:38:32.125000Z'
279285
assert content['collection'] == 'metadata:main'
280286

281287
# update item

tests/unittests/test_util.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# =================================================================
22
#
33
# Authors: Ricardo Garcia Silva <[email protected]>
4+
# Authors: Tom Kralidis
45
#
56
# Copyright (c) 2017 Ricardo Garcia Silva
7+
# Copyright (c) 2025 Tom Kralidis
68
#
79
# Permission is hereby granted, free of charge, to any person
810
# obtaining a copy of this software and associated documentation
@@ -148,7 +150,7 @@ def test_wkt2geom(wkt, bounds, expected):
148150
"-10.0, 10.0, 30.0, 15.0",
149151
"POLYGON((-10.00 10.00, -10.00 15.00, 30.00 15.00, "
150152
"30.00 10.00, -10.00 10.00))"
151-
),
153+
)
152154
])
153155
def test_bbox2wktpolygon(bbox, expected):
154156
result = util.bbox2wktpolygon(bbox)
@@ -367,6 +369,20 @@ def test_programmatic_import_with_invalid_path(invalid_import_path):
367369
result = util.programmatic_import(invalid_import_path)
368370
assert result is None
369371

372+
370373
def test_sanitize_url():
371374
result = util.sanitize_db_connect("postgresql://username:password@localhost/pycsw")
372375
assert result == "postgresql://***:***@localhost/pycsw"
376+
377+
378+
def test_str2bool():
379+
assert util.str2bool('true')
380+
assert util.str2bool(True)
381+
assert util.str2bool('1')
382+
assert util.str2bool('yes')
383+
assert util.str2bool('on')
384+
assert not util.str2bool('0')
385+
assert not util.str2bool('false')
386+
assert not util.str2bool(False)
387+
assert not util.str2bool('off')
388+
assert not util.str2bool('no')

0 commit comments

Comments
 (0)