Fix CSV provider for a single item (#1138)

* Add larger test data for CSV provider

* Fix CSV provider for single item
This commit is contained in:
Benjamin Webb
2023-02-10 14:48:24 -05:00
committed by GitHub
parent 983530ac55
commit 30f279b7ad
4 changed files with 119 additions and 0 deletions
+3
View File
@@ -113,6 +113,9 @@ class CSVProvider(BaseProvider):
'type': 'FeatureCollection',
'features': []
}
if identifier is not None:
# Loop through all rows when searching for a single feature
limit = self._load(resulttype='hits').get('numberMatched')
with open(self.data) as ff:
LOGGER.debug('Serializing DictReader')
+6
View File
@@ -32,6 +32,12 @@ This directory provides test data to demonstrate functionality.
- Copyright (c) 2008-2018 Open Source Geospatial Foundation
- Copyright (c) 1996-2008 Regents of the University of Minnesota
### `station_list.csv`
- source: wis2box test data
- URL: [https://github.com/wmo-im/wis2box/blob/main/tests/data/metadata/station/station_list.csv](https://github.com/wmo-im/wis2box/blob/29a90a469597c832931523f08eb3fddcba6ff6dd/tests/data/metadata/station/station_list.csv)
- License: https://github.com/wmo-im/wis2box/blob/main/LICENSE
### `poi_portugal.gpkg`
- source: OpenStreetMap - Natural GIS
+80
View File
@@ -0,0 +1,80 @@
station_name,wigos_station_identifier,traditional_station_identifier,facility_type,latitude,longitude,elevation,territory_name,wmo_region
BONIFATI (16337-0),0-20000-0-16337,16337,Land (fixed),39.5847222222,15.8913888889,484,Italy,6
DECIMOMANNU,0-20000-0-16546,16546,Land (fixed),39.3461111111,8.9675,29,Italy,6
CAMPOBASSO,0-20000-0-16252,16252,Land (fixed),41.5636111111,14.655,793,Italy,6
GRAZZANISE,0-20000-0-16253,16253,Land (fixed),41.0605555556,14.0788888889,9.19,Italy,6
PRATICA DI MARE,0-20000-0-16245,16245,Land (fixed),41.6555555556,12.4480555556,12.3,Italy,6
ILLIZI,0-20000-0-60640,60640,Land (fixed),26.71916,8.61722,542,Algeria,1
SKIKDA,0-20000-0-60355,60355,Land (fixed),36.88178,6.93503,2,Algeria,1
PIAN ROSA,0-20000-0-16052,16052,Land (fixed),45.935,7.7061111111,3480,Italy,6
PRIZZI,0-20000-0-16434,16434,Land (fixed),37.7227777778,13.4280555556,1034,Italy,6
DOBBIACO,0-20000-0-16033,16033,Land (fixed),46.73,12.22,1222,Italy,6
CATANIA SIGONELLA,0-20000-0-16459,16459,Land (fixed),37.4055555556,14.9186111111,24,Italy,6
BALAKA,0-454-2-AWSBALAKA,AWSBALAKA,Land (fixed),-14.983333,34.966666,618,Malawi,1
MECHERIA,0-20000-0-60549,60549,Land (fixed),33.54581,-0.23527,1123.2,Algeria,1
TERMOLI,0-20000-0-16232,16232,Land (fixed),42.0041666667,14.9963888889,16,Italy,6
VIGNA DI VALLE,0-20000-0-16224,16224,Land (fixed),42.0802777778,12.2113888889,260,Italy,6
HASSI-MESSAOUD,0-20000-0-60581,60581,Land (fixed),31.65861,6.14138,140,Algeria,1
DJELFA,0-20000-0-60535,60535,Land (fixed),34.65361,3.28138,1180,Algeria,1
PAGANELLA,0-20000-0-16022,16022,Land (fixed),46.1597222222,11.0341666667,2125,Italy,6
MONTE S. ANGELO,0-20000-0-16258,16258,Land (fixed),41.7083333333,15.9477777778,838,Italy,6
MALOMO,0-454-2-AWSMALOMO,AWSMALOMO,Land (fixed),-13.14202,33.83727,1088,Malawi,1
TREVICO,0-20000-0-16263,16263,Land (fixed),41.0466666667,15.2327777778,1085,Italy,6
EL-OUED,0-20000-0-60559,60559,Land (fixed),33.50618,6.78841,63,Algeria,1
TIMIMOUN,0-20000-0-60607,60607,Land (fixed),29.24412,0.28385,312,Algeria,1
CONCORDIA,0-20000-0-89625,89625,Land (fixed),-75.1016666667,123.4119444444,3233,Italy,7
TOUGGOURT,0-20000-0-60555,60555,Land (fixed),33.07011,6.09208,87,Algeria,1
MONTE SCURO,0-20000-0-16344,16344,Land (fixed),39.3305555556,16.3963888889,1669,Italy,6
BATNA,0-20000-0-60468,60468,Land (fixed),35.76083,6.31972,821,Algeria,1
ENNA,0-20000-0-16450,16450,Land (fixed),37.5680555556,14.2797222222,1000,Italy,6
NAMITAMBO,0-454-2-AWSNAMITAMBO,AWSNAMITAMBO,Land (fixed),-15.84052,35.27428,806,Malawi,1
TOLEZA,0-454-2-AWSTOLEZA,AWSTOLEZA,Land (fixed),-14.948,34.955,764,Malawi,1
IN-GUEZZAM,0-20000-0-60690,60690,Land (fixed),19.56388,5.74887,399,Algeria,1
BRIC DELLA CROCE,0-20000-0-16061,16061,Land (fixed),45.0333333333,7.7316666667,709,Italy,6
TREVISO/ISTRANA,0-20000-0-16098,16098,Land (fixed),45.6838888889,12.1066666667,42,Italy,6
KAYEREKERA,0-454-2-AWSKAYEREKERA,AWSKAYEREKERA,Land (fixed),-9.92951,33.67305,848,Malawi,1
LOBI AWS,0-454-2-AWSLOBI,AWSLOBI,Land (fixed),-14.39528,34.07244,1288,Malawi,1
CERVIA,0-20000-0-16148,16148,Land (fixed),44.2288888889,12.2919444444,6,Italy,6
NKHOMA UNIVERSITY,0-454-2-AWSNKHOMA,AWSNKHOMA,Land (fixed),-14.04422,34.10468,1230,Malawi,1
SAIDA,0-20000-0-60536,60536,Land (fixed),34.89186,0.15774,750,Algeria,1
PASSO ROLLE,0-20000-0-16021,16021,Land (fixed),46.2977777778,11.7866666667,2004,Italy,6
AREZZO,0-20000-0-16172,16172,Land (fixed),43.4597222222,11.8455555556,248,Italy,6
CAPRI,0-20000-0-16294,16294,Land (fixed),40.5577777778,14.2019444444,160,Italy,6
TARVISIO,0-20000-0-16040,16040,Land (fixed),46.5055555556,13.5861111111,777,Italy,6
SETIF/AIN ARNAT,0-20000-0-60445,60445,Land (fixed),36.1666666667,5.3166666667,1009,Algeria,1
JIJEL- ACHOUAT,0-20000-0-60351,60351,Land (fixed),36.79472,5.87722,8,Algeria,1
MONTE ARGENTARIO,0-20000-0-16168,16168,Land (fixed),42.3869444444,11.1697222222,630.7,Italy,6
CAPO CARBONARA,0-20000-0-16564,16564,Land (fixed),39.1038888889,9.5136111111,116,Italy,6
ANNABA,0-20000-0-60360,60360,Land (fixed),36.822222,7.8025,5,Algeria,1
BENI-ABBES,0-20000-0-60602,60602,Land (fixed),30.12846,-2.14953,510,Algeria,1
FRONTONE,0-20000-0-16179,16179,Land (fixed),43.5169444444,12.7277777778,570,Italy,6
FERRARA (16138-0),0-20000-0-16138,16138,Land (fixed),44.8155555556,11.6125,8,Italy,6
TIARET,0-20000-0-60511,60511,Land (fixed),35.35542,1.46792,977,Algeria,1
MASCARA-GHRISS,0-20000-0-60507,60507,Land (fixed),35.20666,0.1525,511,Algeria,1
EL-BAYADH,0-20000-0-60550,60550,Land (fixed),33.71966,1.09484,1361,Algeria,1
USTICA,0-20000-0-16400,16400,Land (fixed),38.7072222222,13.1772222222,242,Italy,6
GROSSETO,0-20000-0-16206,16206,Land (fixed),42.7480555556,11.0588888889,5.4,Italy,6
BENI OUNIF,0-12-0-08BECCN60577,60577,Land (fixed),32.05138,-1.26527,830,Algeria,1
OCNA SUGATAG,0-20000-0-15015,15015,Land (fixed),47.7770616258,23.9404602638,503,Romania,6
BOTOSANI,0-20000-0-15020,15020,Land (fixed),47.7356532437,26.6455501701,161,Romania,6
IASI,0-20000-0-15090,15090,Land (fixed),47.163333333,27.6272222222,74.29,Romania,6
CEAHLAU TOACA,0-20000-0-15108,15108,Land (fixed),46.9775099973,25.9499399749,1897,Romania,6
CLUJ-NAPOCA,0-20000-0-15120,15120,Land (fixed),46.7777705044,23.5713052939,410,Romania,6
BACAU,0-20000-0-15150,15150,Land (fixed),46.5577777778,26.8966666667,174,Romania,6
MIERCUREA CIUC,0-20000-0-15170,15170,Land (fixed),46.3713166568,25.7726166755,661,Romania,6
ARAD,0-20000-0-15200,15200,Land (fixed),46.1335163958,21.3536215174,116.59,Romania,6
DEVA,0-20000-0-15230,15230,Land (fixed),45.8649230138,22.898806236,240,Romania,6
SIBIU,0-20000-0-15260,15260,Land (fixed),45.79018,24.036245,450,Romania,6
VARFU OMU,0-20000-0-15280,15280,Land (fixed),45.4457927989,25.456690976,2504,Romania,6
CARANSEBES,0-20000-0-15292,15292,Land (fixed),45.41667,22.22917,241,Romania,6
GALATI,0-20000-0-15310,15310,Land (fixed),45.4729181384,28.0323010582,69,Romania,6
TULCEA,0-20000-0-15335,15335,Land (fixed),45.1905064849,28.8241607619,4.36,Romania,6
RAMNICU VALCEA,0-20000-0-15346,15346,Land (fixed),45.0888211225,24.3628139123,237,Romania,6
BUZAU,0-20000-0-15350,15350,Land (fixed),45.1326632857,26.8517319231,97,Romania,6
SULINA,0-20000-0-15360,15360,Land (fixed),45.1623111,29.7268286,12.69,Romania,6
DROBETA-TURNU SEVERIN,0-20000-0-15410,15410,Land (fixed),44.6264587019,22.6260737132,77,Romania,6
BUCURESTI BANEASA,0-20000-0-15420,15420,Land (fixed),44.5104330044,26.0781904077,90,Romania,6
CRAIOVA,0-20000-0-15450,15450,Land (fixed),44.3101404313,23.8669847441,192,Romania,6
CALARASI,0-20000-0-15460,15460,Land (fixed),44.2057385289,27.3383080718,18.72,Romania,6
ROSIORII DE VEDE,0-20000-0-15470,15470,Land (fixed),44.1072133362,24.9787400713,102.15,Romania,6
CONSTANTA,0-20000-0-15480,15480,Land (fixed),44.2138143888,28.6455646839,12.8,Romania,6
1 station_name wigos_station_identifier traditional_station_identifier facility_type latitude longitude elevation territory_name wmo_region
2 BONIFATI (16337-0) 0-20000-0-16337 16337 Land (fixed) 39.5847222222 15.8913888889 484 Italy 6
3 DECIMOMANNU 0-20000-0-16546 16546 Land (fixed) 39.3461111111 8.9675 29 Italy 6
4 CAMPOBASSO 0-20000-0-16252 16252 Land (fixed) 41.5636111111 14.655 793 Italy 6
5 GRAZZANISE 0-20000-0-16253 16253 Land (fixed) 41.0605555556 14.0788888889 9.19 Italy 6
6 PRATICA DI MARE 0-20000-0-16245 16245 Land (fixed) 41.6555555556 12.4480555556 12.3 Italy 6
7 ILLIZI 0-20000-0-60640 60640 Land (fixed) 26.71916 8.61722 542 Algeria 1
8 SKIKDA 0-20000-0-60355 60355 Land (fixed) 36.88178 6.93503 2 Algeria 1
9 PIAN ROSA 0-20000-0-16052 16052 Land (fixed) 45.935 7.7061111111 3480 Italy 6
10 PRIZZI 0-20000-0-16434 16434 Land (fixed) 37.7227777778 13.4280555556 1034 Italy 6
11 DOBBIACO 0-20000-0-16033 16033 Land (fixed) 46.73 12.22 1222 Italy 6
12 CATANIA SIGONELLA 0-20000-0-16459 16459 Land (fixed) 37.4055555556 14.9186111111 24 Italy 6
13 BALAKA 0-454-2-AWSBALAKA AWSBALAKA Land (fixed) -14.983333 34.966666 618 Malawi 1
14 MECHERIA 0-20000-0-60549 60549 Land (fixed) 33.54581 -0.23527 1123.2 Algeria 1
15 TERMOLI 0-20000-0-16232 16232 Land (fixed) 42.0041666667 14.9963888889 16 Italy 6
16 VIGNA DI VALLE 0-20000-0-16224 16224 Land (fixed) 42.0802777778 12.2113888889 260 Italy 6
17 HASSI-MESSAOUD 0-20000-0-60581 60581 Land (fixed) 31.65861 6.14138 140 Algeria 1
18 DJELFA 0-20000-0-60535 60535 Land (fixed) 34.65361 3.28138 1180 Algeria 1
19 PAGANELLA 0-20000-0-16022 16022 Land (fixed) 46.1597222222 11.0341666667 2125 Italy 6
20 MONTE S. ANGELO 0-20000-0-16258 16258 Land (fixed) 41.7083333333 15.9477777778 838 Italy 6
21 MALOMO 0-454-2-AWSMALOMO AWSMALOMO Land (fixed) -13.14202 33.83727 1088 Malawi 1
22 TREVICO 0-20000-0-16263 16263 Land (fixed) 41.0466666667 15.2327777778 1085 Italy 6
23 EL-OUED 0-20000-0-60559 60559 Land (fixed) 33.50618 6.78841 63 Algeria 1
24 TIMIMOUN 0-20000-0-60607 60607 Land (fixed) 29.24412 0.28385 312 Algeria 1
25 CONCORDIA 0-20000-0-89625 89625 Land (fixed) -75.1016666667 123.4119444444 3233 Italy 7
26 TOUGGOURT 0-20000-0-60555 60555 Land (fixed) 33.07011 6.09208 87 Algeria 1
27 MONTE SCURO 0-20000-0-16344 16344 Land (fixed) 39.3305555556 16.3963888889 1669 Italy 6
28 BATNA 0-20000-0-60468 60468 Land (fixed) 35.76083 6.31972 821 Algeria 1
29 ENNA 0-20000-0-16450 16450 Land (fixed) 37.5680555556 14.2797222222 1000 Italy 6
30 NAMITAMBO 0-454-2-AWSNAMITAMBO AWSNAMITAMBO Land (fixed) -15.84052 35.27428 806 Malawi 1
31 TOLEZA 0-454-2-AWSTOLEZA AWSTOLEZA Land (fixed) -14.948 34.955 764 Malawi 1
32 IN-GUEZZAM 0-20000-0-60690 60690 Land (fixed) 19.56388 5.74887 399 Algeria 1
33 BRIC DELLA CROCE 0-20000-0-16061 16061 Land (fixed) 45.0333333333 7.7316666667 709 Italy 6
34 TREVISO/ISTRANA 0-20000-0-16098 16098 Land (fixed) 45.6838888889 12.1066666667 42 Italy 6
35 KAYEREKERA 0-454-2-AWSKAYEREKERA AWSKAYEREKERA Land (fixed) -9.92951 33.67305 848 Malawi 1
36 LOBI AWS 0-454-2-AWSLOBI AWSLOBI Land (fixed) -14.39528 34.07244 1288 Malawi 1
37 CERVIA 0-20000-0-16148 16148 Land (fixed) 44.2288888889 12.2919444444 6 Italy 6
38 NKHOMA UNIVERSITY 0-454-2-AWSNKHOMA AWSNKHOMA Land (fixed) -14.04422 34.10468 1230 Malawi 1
39 SAIDA 0-20000-0-60536 60536 Land (fixed) 34.89186 0.15774 750 Algeria 1
40 PASSO ROLLE 0-20000-0-16021 16021 Land (fixed) 46.2977777778 11.7866666667 2004 Italy 6
41 AREZZO 0-20000-0-16172 16172 Land (fixed) 43.4597222222 11.8455555556 248 Italy 6
42 CAPRI 0-20000-0-16294 16294 Land (fixed) 40.5577777778 14.2019444444 160 Italy 6
43 TARVISIO 0-20000-0-16040 16040 Land (fixed) 46.5055555556 13.5861111111 777 Italy 6
44 SETIF/AIN ARNAT 0-20000-0-60445 60445 Land (fixed) 36.1666666667 5.3166666667 1009 Algeria 1
45 JIJEL- ACHOUAT 0-20000-0-60351 60351 Land (fixed) 36.79472 5.87722 8 Algeria 1
46 MONTE ARGENTARIO 0-20000-0-16168 16168 Land (fixed) 42.3869444444 11.1697222222 630.7 Italy 6
47 CAPO CARBONARA 0-20000-0-16564 16564 Land (fixed) 39.1038888889 9.5136111111 116 Italy 6
48 ANNABA 0-20000-0-60360 60360 Land (fixed) 36.822222 7.8025 5 Algeria 1
49 BENI-ABBES 0-20000-0-60602 60602 Land (fixed) 30.12846 -2.14953 510 Algeria 1
50 FRONTONE 0-20000-0-16179 16179 Land (fixed) 43.5169444444 12.7277777778 570 Italy 6
51 FERRARA (16138-0) 0-20000-0-16138 16138 Land (fixed) 44.8155555556 11.6125 8 Italy 6
52 TIARET 0-20000-0-60511 60511 Land (fixed) 35.35542 1.46792 977 Algeria 1
53 MASCARA-GHRISS 0-20000-0-60507 60507 Land (fixed) 35.20666 0.1525 511 Algeria 1
54 EL-BAYADH 0-20000-0-60550 60550 Land (fixed) 33.71966 1.09484 1361 Algeria 1
55 USTICA 0-20000-0-16400 16400 Land (fixed) 38.7072222222 13.1772222222 242 Italy 6
56 GROSSETO 0-20000-0-16206 16206 Land (fixed) 42.7480555556 11.0588888889 5.4 Italy 6
57 BENI OUNIF 0-12-0-08BECCN60577 60577 Land (fixed) 32.05138 -1.26527 830 Algeria 1
58 OCNA SUGATAG 0-20000-0-15015 15015 Land (fixed) 47.7770616258 23.9404602638 503 Romania 6
59 BOTOSANI 0-20000-0-15020 15020 Land (fixed) 47.7356532437 26.6455501701 161 Romania 6
60 IASI 0-20000-0-15090 15090 Land (fixed) 47.163333333 27.6272222222 74.29 Romania 6
61 CEAHLAU TOACA 0-20000-0-15108 15108 Land (fixed) 46.9775099973 25.9499399749 1897 Romania 6
62 CLUJ-NAPOCA 0-20000-0-15120 15120 Land (fixed) 46.7777705044 23.5713052939 410 Romania 6
63 BACAU 0-20000-0-15150 15150 Land (fixed) 46.5577777778 26.8966666667 174 Romania 6
64 MIERCUREA CIUC 0-20000-0-15170 15170 Land (fixed) 46.3713166568 25.7726166755 661 Romania 6
65 ARAD 0-20000-0-15200 15200 Land (fixed) 46.1335163958 21.3536215174 116.59 Romania 6
66 DEVA 0-20000-0-15230 15230 Land (fixed) 45.8649230138 22.898806236 240 Romania 6
67 SIBIU 0-20000-0-15260 15260 Land (fixed) 45.79018 24.036245 450 Romania 6
68 VARFU OMU 0-20000-0-15280 15280 Land (fixed) 45.4457927989 25.456690976 2504 Romania 6
69 CARANSEBES 0-20000-0-15292 15292 Land (fixed) 45.41667 22.22917 241 Romania 6
70 GALATI 0-20000-0-15310 15310 Land (fixed) 45.4729181384 28.0323010582 69 Romania 6
71 TULCEA 0-20000-0-15335 15335 Land (fixed) 45.1905064849 28.8241607619 4.36 Romania 6
72 RAMNICU VALCEA 0-20000-0-15346 15346 Land (fixed) 45.0888211225 24.3628139123 237 Romania 6
73 BUZAU 0-20000-0-15350 15350 Land (fixed) 45.1326632857 26.8517319231 97 Romania 6
74 SULINA 0-20000-0-15360 15360 Land (fixed) 45.1623111 29.7268286 12.69 Romania 6
75 DROBETA-TURNU SEVERIN 0-20000-0-15410 15410 Land (fixed) 44.6264587019 22.6260737132 77 Romania 6
76 BUCURESTI BANEASA 0-20000-0-15420 15420 Land (fixed) 44.5104330044 26.0781904077 90 Romania 6
77 CRAIOVA 0-20000-0-15450 15450 Land (fixed) 44.3101404313 23.8669847441 192 Romania 6
78 CALARASI 0-20000-0-15460 15460 Land (fixed) 44.2057385289 27.3383080718 18.72 Romania 6
79 ROSIORII DE VEDE 0-20000-0-15470 15470 Land (fixed) 44.1072133362 24.9787400713 102.15 Romania 6
80 CONSTANTA 0-20000-0-15480 15480 Land (fixed) 44.2138143888 28.6455646839 12.8 Romania 6
+30
View File
@@ -35,6 +35,7 @@ from pygeoapi.provider.csv_ import CSVProvider
from .util import get_test_file_path
path = get_test_file_path('data/obs.csv')
stations_path = get_test_file_path('data/station_list.csv')
@pytest.fixture()
@@ -51,6 +52,20 @@ def config():
}
@pytest.fixture()
def station_config():
return {
'name': 'CSV',
'type': 'feature',
'data': stations_path,
'id_field': 'wigos_station_identifier',
'geometry': {
'x_field': 'longitude',
'y_field': 'latitude'
}
}
def test_query(config):
p = CSVProvider(config)
@@ -115,3 +130,18 @@ def test_get_not_existing_item_raise_exception(config):
p = CSVProvider(config)
with pytest.raises(ProviderItemNotFoundError):
p.get('404')
def test_get_station(station_config):
p = CSVProvider(station_config)
results = p.query(limit=20)
assert len(results['features']) == 20
assert results['numberMatched'] == 20
assert results['numberReturned'] == 20
result = p.get('0-20000-0-16337')
assert result['properties']['station_name'] == 'BONIFATI (16337-0)'
result = p.get('0-454-2-AWSNAMITAMBO')
assert result['properties']['station_name'] == 'NAMITAMBO'