Skip to content

Commit 0af1df9

Browse files
authored
fix CSV provider paging (#1703) (#1710)
* fix CSV provider paging (#1703) * update tests
1 parent 2b00cf2 commit 0af1df9

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

pygeoapi/provider/csv_.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def _load(self, offset=0, limit=10, resulttype='results',
130130
feature_collection['numberMatched'] = len(list(data_))
131131
return feature_collection
132132
LOGGER.debug('Slicing CSV rows')
133-
for row in itertools.islice(data_, offset, offset+limit):
133+
for row in itertools.islice(data_, 0, None):
134134
try:
135135
coordinates = [
136136
float(row.pop(self.geometry_x)),
@@ -178,6 +178,9 @@ def _load(self, offset=0, limit=10, resulttype='results',
178178
elif identifier is not None and found:
179179
return result
180180

181+
features_returned = feature_collection['features'][offset:offset+limit]
182+
feature_collection['features'] = features_returned
183+
181184
feature_collection['numberReturned'] = len(
182185
feature_collection['features'])
183186

tests/api/test_itemtypes.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,16 @@ def test_get_collection_items(config, api_):
194194
assert features['features'][1]['properties']['stn_id'] == 35
195195

196196
links = features['links']
197-
assert len(links) == 4
197+
assert len(links) == 5
198198
assert '/collections/obs/items?f=json' in links[0]['href']
199199
assert links[0]['rel'] == 'self'
200200
assert '/collections/obs/items?f=jsonld' in links[1]['href']
201201
assert links[1]['rel'] == 'alternate'
202202
assert '/collections/obs/items?f=html' in links[2]['href']
203203
assert links[2]['rel'] == 'alternate'
204204
assert '/collections/obs' in links[3]['href']
205-
assert links[3]['rel'] == 'collection'
205+
assert links[3]['rel'] == 'next'
206+
assert links[4]['rel'] == 'collection'
206207

207208
# Invalid offset
208209
req = mock_api_request({'offset': -1})
@@ -242,7 +243,7 @@ def test_get_collection_items(config, api_):
242243
assert len(features['features']) == 1
243244

244245
links = features['links']
245-
assert len(links) == 5
246+
assert len(links) == 6
246247
assert '/collections/obs/items?f=json&limit=1&bbox=-180,90,180,90' in \
247248
links[0]['href']
248249
assert links[0]['rel'] == 'self'
@@ -256,7 +257,9 @@ def test_get_collection_items(config, api_):
256257
in links[3]['href']
257258
assert links[3]['rel'] == 'prev'
258259
assert '/collections/obs' in links[4]['href']
259-
assert links[4]['rel'] == 'collection'
260+
assert links[3]['rel'] == 'prev'
261+
assert links[4]['rel'] == 'next'
262+
assert links[5]['rel'] == 'collection'
260263

261264
req = mock_api_request({
262265
'sortby': 'bad-property',

tests/test_csv__provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def test_get_station(station_config):
137137

138138
results = p.query(limit=20)
139139
assert len(results['features']) == 20
140-
assert results['numberMatched'] == 20
140+
assert results['numberMatched'] == 79
141141
assert results['numberReturned'] == 20
142142

143143
result = p.get('0-20000-0-16337')

0 commit comments

Comments
 (0)