From 04b4423078e672029fc8fd2295d41dc33df052d2 Mon Sep 17 00:00:00 2001 From: Colin Blackburn Date: Wed, 5 Oct 2022 17:55:05 +0100 Subject: [PATCH 1/3] Add format to next/prev links --- pygeoapi/api.py | 8 ++++---- tests/test_api.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pygeoapi/api.py b/pygeoapi/api.py index 00f1160de..8da9a56d5 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -1524,9 +1524,9 @@ def get_collection_items( 'type': 'application/geo+json', 'rel': 'prev', 'title': 'items (prev)', - 'href': '{}?offset={}{}' + 'href': '{}?f={}&offset={}{}' .format( - uri, prev, serialized_query_params) + uri, F_JSON, prev, serialized_query_params) }) if len(content['features']) == limit: @@ -1536,9 +1536,9 @@ def get_collection_items( 'type': 'application/geo+json', 'rel': 'next', 'title': 'items (next)', - 'href': '{}?offset={}{}' + 'href': '{}?f={}&offset={}{}' .format( - uri, next_, serialized_query_params) + uri, F_JSON, next_, serialized_query_params) }) content['links'].append( diff --git a/tests/test_api.py b/tests/test_api.py index ea2ae3c8c..8ed758d9f 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -670,7 +670,7 @@ def test_get_collection_items(config, api_): assert links[1]['rel'] == 'alternate' assert '/collections/obs/items?f=html' in links[2]['href'] assert links[2]['rel'] == 'alternate' - assert '/collections/obs/items?offset=2&limit=2' in links[3]['href'] + assert '/collections/obs/items?f=json&offset=2&limit=2' in links[3]['href'] assert links[3]['rel'] == 'next' assert '/collections/obs' in links[4]['href'] assert links[4]['rel'] == 'collection' @@ -697,7 +697,7 @@ def test_get_collection_items(config, api_): assert links[1]['rel'] == 'alternate' assert '/collections/obs/items?f=html' in links[2]['href'] assert links[2]['rel'] == 'alternate' - assert '/collections/obs/items?offset=0' in links[3]['href'] + assert '/collections/obs/items?f=json&offset=0' in links[3]['href'] assert links[3]['rel'] == 'prev' assert '/collections/obs' in links[4]['href'] assert links[4]['rel'] == 'collection' @@ -723,10 +723,10 @@ def test_get_collection_items(config, api_): assert '/collections/obs/items?f=html&limit=1&bbox=-180,90,180,90' in \ links[2]['href'] assert links[2]['rel'] == 'alternate' - assert '/collections/obs/items?offset=0&limit=1&bbox=-180,90,180,90' \ + assert '/collections/obs/items?f=json&offset=0&limit=1&bbox=-180,90,180,90' \ in links[3]['href'] assert links[3]['rel'] == 'prev' - assert '/collections/obs/items?offset=2&limit=1&bbox=-180,90,180,90' \ + assert '/collections/obs/items?f=json&offset=2&limit=1&bbox=-180,90,180,90' \ in links[4]['href'] assert links[4]['rel'] == 'next' assert '/collections/obs' in links[5]['href'] From 3ecbd46e81c08b8a1b03b78b633c8cb87cbe1d18 Mon Sep 17 00:00:00 2001 From: Colin Blackburn Date: Wed, 5 Oct 2022 18:26:49 +0100 Subject: [PATCH 2/3] Test explicitly for json --- pygeoapi/api.py | 4 ++-- tests/test_api.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pygeoapi/api.py b/pygeoapi/api.py index 8da9a56d5..0241529df 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -1526,7 +1526,7 @@ def get_collection_items( 'title': 'items (prev)', 'href': '{}?f={}&offset={}{}' .format( - uri, F_JSON, prev, serialized_query_params) + uri, request.format, prev, serialized_query_params) }) if len(content['features']) == limit: @@ -1538,7 +1538,7 @@ def get_collection_items( 'title': 'items (next)', 'href': '{}?f={}&offset={}{}' .format( - uri, F_JSON, next_, serialized_query_params) + uri, request.format, next_, serialized_query_params) }) content['links'].append( diff --git a/tests/test_api.py b/tests/test_api.py index 8ed758d9f..40190bebb 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -655,7 +655,7 @@ def test_get_collection_items(config, api_): assert len(features['features']) == 1 assert features['numberMatched'] == 1 - req = mock_request({'limit': 2}) + req = mock_request({'f': 'json', 'limit': 2}) rsp_headers, code, response = api_.get_collection_items(req, 'obs') features = json.loads(response) @@ -682,7 +682,7 @@ def test_get_collection_items(config, api_): assert code == 400 - req = mock_request({'offset': 2}) + req = mock_request({'f': 'json', 'offset': 2}) rsp_headers, code, response = api_.get_collection_items(req, 'obs') features = json.loads(response) @@ -703,6 +703,7 @@ def test_get_collection_items(config, api_): assert links[4]['rel'] == 'collection' req = mock_request({ + 'f': 'json', 'offset': 1, 'limit': 1, 'bbox': '-180,90,180,90' From 5fdaf3f1de736297b932e07e0f1b388848a8cddb Mon Sep 17 00:00:00 2001 From: Colin Blackburn Date: Wed, 5 Oct 2022 18:27:12 +0100 Subject: [PATCH 3/3] Fix long lines in tests --- tests/test_api.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index 40190bebb..945f0be5f 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -724,11 +724,11 @@ def test_get_collection_items(config, api_): assert '/collections/obs/items?f=html&limit=1&bbox=-180,90,180,90' in \ links[2]['href'] assert links[2]['rel'] == 'alternate' - assert '/collections/obs/items?f=json&offset=0&limit=1&bbox=-180,90,180,90' \ - in links[3]['href'] + assert ('/collections/obs/items?f=json' + '&offset=0&limit=1&bbox=-180,90,180,90') in links[3]['href'] assert links[3]['rel'] == 'prev' - assert '/collections/obs/items?f=json&offset=2&limit=1&bbox=-180,90,180,90' \ - in links[4]['href'] + assert ('/collections/obs/items?f=json' + '&offset=2&limit=1&bbox=-180,90,180,90') in links[4]['href'] assert links[4]['rel'] == 'next' assert '/collections/obs' in links[5]['href'] assert links[5]['rel'] == 'collection'