Files
pygeoapi/tests/test_ogr_esrijson_provider.py
T
Francesco Bartoli 8d1c812162 Fix issue 137 (#396)
* Fix regression on string messages

* Fix paging for ESRIJSON driver

* catch ogr http errors

* Fix test and inherit from intermediate class

Co-authored-by: Francesco Bartoli <francesco.bartoli@geobeyond.it>
2020-04-12 23:47:42 +02:00

150 lines
5.3 KiB
Python

# =================================================================
#
# Authors: Francesco Bartoli <xbartolone@gmail.com>
#
# Copyright (c) 2020 Francesco Bartoli
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# =================================================================
# Needs to be run like: python3 -m pytest
# https://sampleserver6.arcgisonline.com/arcgis/rest/services/CommunityAddressing/FeatureServer/0
import logging
import pytest
from pygeoapi.provider.ogr import OGRProvider
LOGGER = logging.getLogger(__name__)
@pytest.fixture()
def config_ArcGIS_ESRIJSON():
return {
'name': 'OGR',
'data': {
'source_type': 'ESRIJSON',
'source': 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/CommunityAddressing/FeatureServer/0/query?where=objectid+%3D+objectid&outfields=*&orderByFields=objectid+ASC&f=json', # noqa
'source_srs': 'EPSG:4326',
'target_srs': 'EPSG:4326',
'source_capabilities': {
'paging': True
},
'open_options': {
'FEATURE_SERVER_PAGING': 'YES',
},
'gdal_ogr_options': {
'EMPTY_AS_NULL': 'NO',
'GDAL_CACHEMAX': '64',
'CPL_DEBUG': 'NO'
},
},
'id_field': 'objectid',
'layer': 'ESRIJSON'
}
def test_get_fields_agol(config_ArcGIS_ESRIJSON):
"""Testing field types"""
p = OGRProvider(config_ArcGIS_ESRIJSON)
results = p.get_fields()
assert results['fulladdr'] == 'string'
assert results['municipality'] == 'string'
def test_get_agol(config_ArcGIS_ESRIJSON):
"""Testing query for a specific object"""
p = OGRProvider(config_ArcGIS_ESRIJSON)
result = p.get('78232831')
assert result['id'] == 78232831
assert '2605' in result['properties']['fulladdr']
def test_query_hits_agol(config_ArcGIS_ESRIJSON):
"""Testing query on entire collection for hits"""
p = OGRProvider(config_ArcGIS_ESRIJSON)
feature_collection = p.query(resulttype='hits')
assert feature_collection.get('type', None) == 'FeatureCollection'
features = feature_collection.get('features', None)
assert len(features) == 0
hits = feature_collection.get('numberMatched', None)
assert hits is not None
assert hits > 100
def test_query_bbox_hits_agol(config_ArcGIS_ESRIJSON):
"""Testing query for a valid JSON object with geometry"""
p = OGRProvider(config_ArcGIS_ESRIJSON)
feature_collection = p.query(
bbox=[-9822165.181154, 5112669.004249,
-9807305.104750, 5133712.297986],
resulttype='hits')
assert feature_collection.get('type', None) == 'FeatureCollection'
features = feature_collection.get('features', None)
assert len(features) == 0
hits = feature_collection.get('numberMatched', None)
assert hits is not None
print('hits={}'.format(hits))
assert hits > 1
def test_query_with_limit_agol(config_ArcGIS_ESRIJSON):
"""Testing query for a valid JSON object with geometry"""
p = OGRProvider(config_ArcGIS_ESRIJSON)
feature_collection = p.query(limit=2, resulttype='results')
assert feature_collection.get('type', None) == 'FeatureCollection'
features = feature_collection.get('features', None)
assert len(features) == 2
hits = feature_collection.get('numberMatched', None)
assert hits is None
feature = features[0]
properties = feature.get('properties', None)
assert properties is not None
geometry = feature.get('geometry', None)
assert geometry is not None
def test_query_with_startindex(config_ArcGIS_ESRIJSON):
"""Testing query for a valid JSON object with geometry"""
p = OGRProvider(config_ArcGIS_ESRIJSON)
feature_collection = p.query(startindex=10, limit=10, resulttype='results')
assert feature_collection.get('type', None) == 'FeatureCollection'
features = feature_collection.get('features', None)
assert len(features) == 10
hits = feature_collection.get('numberMatched', None)
assert hits is None
feature = features[0]
properties = feature.get('properties', None)
assert properties is not None
assert feature['id'] == 78220641
assert '1364' in properties['fulladdr']
geometry = feature.get('geometry', None)
assert geometry is not None