Skip to content
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
1 change: 0 additions & 1 deletion pygeoapi/api/itemtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,6 @@ def get_collection_items(
if offset > 0:
prev_link = True

print(request.format)
if prev_link:
prev = max(0, offset - limit)
url = f'{uri}?offset={prev}{serialized_query_params}'
Expand Down
24 changes: 6 additions & 18 deletions pygeoapi/api/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,27 +327,12 @@ def get_jobs(api: API, request: APIRequest,
job_result_url = f"{api.base_url}/jobs/{job_['identifier']}/results" # noqa

job2['links'] = [{
'href': f'{job_result_url}?f={F_HTML}',
'href': job_result_url,
'rel': 'http://www.opengis.net/def/rel/ogc/1.0/results',
'type': FORMAT_TYPES[F_HTML],
'title': l10n.translate(f'Results of job as HTML', request.locale), # noqa
}, {
'href': f'{job_result_url}?f={F_JSON}',
'rel': 'http://www.opengis.net/def/rel/ogc/1.0/results',
'type': FORMAT_TYPES[F_JSON],
'title': l10n.translate(f'Results of job as JSON', request.locale), # noqa
'type': job_['mimetype'],
'title': f"Results of job {job_id} as {job_['mimetype']}"
}]

if job_['mimetype'] not in (FORMAT_TYPES[F_JSON],
FORMAT_TYPES[F_HTML]):

job2['links'].append({
'href': job_result_url,
'rel': 'http://www.opengis.net/def/rel/ogc/1.0/results', # noqa
'type': job_['mimetype'],
'title': f"Results of job {job_id} as {job_['mimetype']}" # noqa
})

serialized_jobs['jobs'].append(job2)

serialized_query_params = ''
Expand Down Expand Up @@ -528,7 +513,10 @@ def execute_process(api: API, request: APIRequest,
pretty_print_ = False
response2 = to_json(response, pretty_print_)
else:
pretty_print_ = False
response2 = response
if isinstance(response, (list, dict)):
response2 = to_json(response, pretty_print_)

if (headers.get('Preference-Applied', '') == RequestedProcessExecutionMode.respond_async.value): # noqa
LOGGER.debug('Asynchronous mode detected, returning statusInfo')
Expand Down
30 changes: 28 additions & 2 deletions pygeoapi/process/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Authors: Tom Kralidis <tomkralidis@gmail.com>
# Francesco Martinelli <francesco.martinelli@ingv.it>
#
# Copyright (c) 2022 Tom Kralidis
# Copyright (c) 2026 Tom Kralidis
# Copyright (c) 2024 Francesco Martinelli
#
# Permission is hereby granted, free of charge, to any person
Expand All @@ -29,6 +29,7 @@
#
# =================================================================

import json
import logging

from pygeoapi.process.base import BaseProcessor, ProcessorExecuteError
Expand Down Expand Up @@ -82,6 +83,28 @@
'minOccurs': 0,
'maxOccurs': 1,
'keywords': ['message']
},
'as_bytes': {
'title': 'As bytes',
'description': 'Whether to force return as bytes',
'schema': {
'type': 'bool',
'default': False
},
'minOccurs': 0,
'maxOccurs': 1,
'keywords': ['as_bytes']
},
'media_type': {
'title': 'Media type',
'description': 'Force a specific media type',
'schema': {
'type': 'string',
'default': 'application/json'
},
'minOccurs': 0,
'maxOccurs': 1,
'keywords': ['media_type']
}
},
'outputs': {
Expand Down Expand Up @@ -120,7 +143,7 @@ def __init__(self, processor_def):
self.supports_outputs = True

def execute(self, data, outputs=None):
mimetype = 'application/json'
mimetype = data.get('media_type', 'application/json')
name = data.get('name')

if name is None:
Expand All @@ -136,6 +159,9 @@ def execute(self, data, outputs=None):
'value': value
}

if data.get('as_bytes', False):
json.dumps(produced_outputs).encode('utf-8')

return mimetype, produced_outputs

def __repr__(self):
Expand Down
5 changes: 3 additions & 2 deletions pygeoapi/process/manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Ricardo Garcia Silva <ricardo.garcia.silva@geobeyond.it>
# Francesco Martinelli <francesco.martinelli@ingv.it>
#
# Copyright (c) 2024 Tom Kralidis
# Copyright (c) 2026 Tom Kralidis
# (c) 2023 Ricardo Garcia Silva
# (c) 2026 Francesco Martinelli
#
Expand Down Expand Up @@ -277,7 +277,8 @@ def _execute_handler_sync(self, p: BaseProcessor, job_id: str,
current_status = JobStatus.running
jfmt, outputs = p.execute(data_dict, **extra_execute_parameters)

if isinstance(outputs, bytes):
if isinstance(outputs, bytes) and outputs.isascii():
LOGGER.debug('output is ASCII; decoding utf-8')
outputs = outputs.decode('utf-8')

if requested_response == RequestedResponse.document.value:
Expand Down
1 change: 0 additions & 1 deletion tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,6 @@ def test_describe_collections(config, api_):
collections = json.loads(response)

assert len(collections) == 2
print(json.dumps(collections['collections']))
assert len(collections['collections']) == 10
assert len(collections['links']) == 3

Expand Down
27 changes: 26 additions & 1 deletion tests/api/test_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_describe_processes(config, api_):
assert process['title'] == 'Hello World'
assert len(process['keywords']) == 3
assert len(process['links']) == 6
assert len(process['inputs']) == 2
assert len(process['inputs']) == 4
assert len(process['outputs']) == 1
assert len(process['outputTransmission']) == 1
assert len(process['jobControlOptions']) == 2
Expand Down Expand Up @@ -242,6 +242,18 @@ def test_execute_process(config, api_):
'name': 'Test document'
}
}
req_body_10 = {
'inputs': {
'name': 'Test document as bytes response',
'as_bytes': True
}
}
req_body_11 = {
'inputs': {
'name': 'Test document as text/plain media type',
'media_type': 'text/plain'
}
}

cleanup_jobs = set()

Expand Down Expand Up @@ -410,6 +422,19 @@ def test_execute_process(config, api_):
response2 = '{"id":"echo","value":"Hello Test document!"}'
assert response == response2

req = mock_api_request(data=req_body_10)
rsp_headers, code, response = execute_process(api_, req, 'hello-world')

response2 = '{"id":"echo","value":"Hello Test document as bytes response!"}' # noqa
assert response == response2

req = mock_api_request(data=req_body_11)
rsp_headers, code, response = execute_process(api_, req, 'hello-world')

assert rsp_headers['Content-Type'] == 'text/plain'
response2 = '{"id":"echo","value":"Hello Test document as text/plain media type!"}' # noqa
assert response == response2

# Cleanup
time.sleep(2) # Allow time for any outstanding async jobs
for _, job_id in cleanup_jobs:
Expand Down
6 changes: 2 additions & 4 deletions tests/other/test_ogr_capabilities.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# =================================================================
#
# Authors: Just van den Broecke <justb4@gmail.com>
# Tom Kralidis <tomkralidis@gmail.com>
#
# Copyright (c) 2023 Just van den Broecke
# Copyright (c) 2026 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -50,7 +52,6 @@ def get_axis_order(coords):
def test_transforms():
version_num = int(gdal.VersionInfo('VERSION_NUM'))
assert version_num > 3000000, f'GDAL version={version_num} must be > 3.0.0'
print(f'GDAL Version num = {version_num}')

pyproj.show_versions()
FORCE_LON_LAT = osr.OAMS_TRADITIONAL_GIS_ORDER
Expand All @@ -68,7 +69,6 @@ def test_transforms():
}

for crs in CRS_DICT:
print(f'Testing CRS={crs}')
crs_entry = CRS_DICT[crs]
source = get_spatial_ref(28992, AUTH_COMPLIANT)
target = get_spatial_ref(crs_entry['epsg'], crs_entry['mapping'])
Expand All @@ -85,7 +85,6 @@ def test_transforms():
axis_order = get_axis_order(result)

# Axis order should match that of CRS
print(f'Transform result={result} Axis order={axis_order}')
crs_axis_order = crs_entry['order']
assert axis_order == crs_axis_order, f'Axis order for {crs} after Transform should be {crs_axis_order} result={result}' # noqa

Expand All @@ -106,7 +105,6 @@ def test_transforms():
# Determine Axis order after ExportToJson
coords = json_feature['geometry']['coordinates']
axis_order = get_axis_order(coords)
print(f'ExportToJson result={coords} Axis order={axis_order}')
assert axis_order == crs_axis_order, f'Axis order for {crs} after ExportToJson should be {crs_axis_order} coords={coords}' # noqa


Expand Down
Loading