Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Jan 26, 2025
1 parent b517ebd commit 22db26d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
4 changes: 4 additions & 0 deletions pycsw/ogc/api/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,8 @@ def item(self, headers_, args, collection, item):
if 'json' in headers_['Content-Type']:
headers_['Content-Type'] = 'application/geo+json'

print("RESPONSE", response)

return self.get_response(200, headers_, response, 'item.html')

def manage_collection_item(self, headers_, action='create', item=None, data=None):
Expand Down Expand Up @@ -1366,6 +1368,8 @@ def record2json(record, url, collection, mode='ogcapi-records'):
if record.time_begin not in [None, '']:
begin, _ = to_rfc3339(record.time_begin)
end, _ = to_rfc3339(record.time_end)
print("BEFORE", record.time_begin, record.time_end)
print("AFTER", begin, end)
record_dict['time'] = {
'interval': [begin, end]
}
Expand Down
15 changes: 12 additions & 3 deletions pycsw/ogc/api/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ def json_serial(obj):
"""

if isinstance(obj, (datetime, date, time)):
if isinstance(obj, date):
print("1", obj)
print("1", type(obj))
if isinstance(obj, (datetime, time)):
print("DATETIME", obj)
return obj.strftime('%Y-%m-%dT%H:%M:%SZ')
else: # date
print("DATE", obj)
return obj.strftime('%Y-%m-%d')
else:
return obj.isoformat() + 'Z'
elif isinstance(obj, bytes):
try:
LOGGER.debug('Returning as UTF-8 decoded bytes')
Expand Down Expand Up @@ -237,6 +241,7 @@ def to_rfc3339(value: str) -> Union[tuple, None]:
:returns: `tuple` of `datetime` of RFC3339 value and date type
"""

print("VALUE", value)
try:
dt = dparse(value) # TODO TIMEZONE)
except Exception as err:
Expand All @@ -248,5 +253,9 @@ def to_rfc3339(value: str) -> Union[tuple, None]:
dt_type = 'date'
else:
dt_type = 'date-time'
dt_type = 'date-time'


print("DT", dt)
print("DT_TYPE", dt_type)
return dt, dt_type
1 change: 1 addition & 0 deletions pycsw/stac/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def item(self, headers_, args, collection, item):
headers_['Accept'] = 'application/geo+json'
headers, status, response = super().item(headers_, args, collection, item)

print("TOM", response)
if collection not in self.get_all_collections():
msg = 'Invalid collection'
LOGGER.exception(msg)
Expand Down
27 changes: 14 additions & 13 deletions tests/functionaltests/suites/stac_api/test_stac_api_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_collections(config):
assert status == 200
assert len(content['links']) == 3

assert len(content['collections']) == 0
assert len(content['collections']) == 4
assert len(content['collections']) == content['numberMatched']
assert len(content['collections']) == content['numberReturned']

Expand Down Expand Up @@ -179,36 +179,36 @@ def test_items(config):
assert content['numberReturned'] == 3
assert len(content['features']) == content['numberReturned']

params = {'filter': "title LIKE '%%sentinel%%'", 'q': 'iPsUm'}
params = {'filter': "title LIKE '%%sentinel%%'", 'q': 'specTral'}
content = json.loads(api.items({}, None, params)[2])
assert content['numberMatched'] == 2
assert content['numberReturned'] == 2
assert content['numberMatched'] == 3
assert content['numberReturned'] == 3
assert len(content['features']) == content['numberReturned']

# test POST JSON requests
content = json.loads(api.items({}, {'bbox': [-180, -90, 180, 90]}, {})[2])
assert len(content['features']) == 3
assert len(content['features']) == 10

content = json.loads(api.items({},
{'bbox': [-180, -90, 180, 90], 'datetime': '2006-03-26'}, # noqa
{'bbox': [-180, -90, 180, 90], 'datetime': '2019-09-10T09:50:29.024000Z'}, # noqa
{})[2])
assert len(content['features']) == 1
assert len(content['features']) == 10

content = json.loads(api.items({}, {'datetime': '2006-03-26'}, {})[2])
assert len(content['features']) == 1
content = json.loads(api.items({}, {'datetime': '2024-11-28T09:23:31.024000Z'}, {})[2]) # noqa
assert len(content['features']) == 2

content = json.loads(api.items({},
{'sortby': [{'field': 'title', 'direction': 'asc'}]}, # noqa
{})[2])

assert len(content['features']) == 10
assert content['features'][5]['properties']['title'] == 'Lorem ipsum'
assert content['features'][5]['properties']['title'] == 'S2B_MSIL1C_20190910T095029_N0208_R079_T33UWQ_20190910T120910.SAFE' # noqa

content = json.loads(api.items({},
{'sortby': [{'field': 'title', 'direction': 'desc'}]}, # noqa
{})[2])
assert len(content['features']) == 10
assert content['features'][5]['properties']['title'] == 'Lorem ipsum dolor sit amet' # noqa
assert content['features'][5]['properties']['title'] == 'S2B_MSIL2A_20190910T095029_N0500_R079_T33UXQ_20230430T083712.SAFE' # noqa

headers, status, content = api.items({}, None, {}, 'foo')
assert status == 400
Expand Down Expand Up @@ -254,11 +254,11 @@ def test_json_transaction(config, sample_collection, sample_item,

assert content['id'] == '20201211_223832_CS2'
assert content['geometry'] is None
assert content['properties']['datetime'] == '2020-12-11T22:38:32.125000Z'
assert content['properties']['datetime'] == '2020-12-11T22:38:32Z'
assert content['collection'] == 'metadata:main'

# update item
sample_item['properties']['datetime'] = '2021-12-11T22:38:32.125000Z'
sample_item['properties']['datetime'] = '2021-12-14T22:38:32Z'

headers, status, content = api.manage_collection_item(
request_headers, 'update', item='20201211_223832_CS2',
Expand All @@ -270,6 +270,7 @@ def test_json_transaction(config, sample_collection, sample_item,
content = json.loads(api.item({}, {}, 'metadata:main',
'20201211_223832_CS2')[2])

print("JJJ22222", content)
assert content['id'] == '20201211_223832_CS2'
assert content['properties']['datetime'] == sample_item['properties']['datetime']
assert content['collection'] == 'metadata:main'
Expand Down

0 comments on commit 22db26d

Please sign in to comment.