From 6dcd10b10ab2af43cfd4ec5f02af81459970431c Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Wed, 25 Aug 2021 06:34:39 -0400 Subject: [PATCH] test for item prev and next links on item queries (#752) (#757) --- pygeoapi/api.py | 28 ++++++++++++++++++---------- tests/test_api.py | 2 ++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/pygeoapi/api.py b/pygeoapi/api.py index 5a67891..2557092 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -1832,16 +1832,24 @@ class API: request.locale), 'href': '{}/collections/{}'.format( self.config['server']['url'], dataset) - }, { - 'rel': 'prev', - 'type': 'application/geo+json', - 'href': uri - }, { - 'rel': 'next', - 'type': 'application/geo+json', - 'href': uri - } - ] + }] + + if 'prev' in content: + content['links'].append({ + 'rel': 'prev', + 'type': FORMAT_TYPES[request.format], + 'href': '{}/collections/{}/items/{}?f={}'.format( + self.config['server']['url'], dataset, + content['prev'], request.format) + }) + if 'next' in content: + content['links'].append({ + 'rel': 'next', + 'type': FORMAT_TYPES[request.format], + 'href': '{}/collections/{}/items/{}?f={}'.format( + self.config['server']['url'], dataset, + content['next'], request.format) + }) # Set response language to requested provider locale # (if it supports language) and/or otherwise the requested pygeoapi diff --git a/tests/test_api.py b/tests/test_api.py index 2324e23..2cd0483 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -724,6 +724,8 @@ def test_get_collection_item(config, api_): feature = json.loads(response) assert feature['properties']['stn_id'] == '35' + assert 'prev' not in feature['links'] + assert 'next' not in feature['links'] def test_get_collection_item_json_ld(config, api_):