def test_ogcapi_features_pygeoapi(): w = Features(SERVICE_URL) assert w.url == 'https://demo.pygeoapi.io/master/' assert w.url_query_string is None api = w.api() assert api['components']['parameters'] is not None paths = api['paths'] assert paths is not None assert paths['/collections/lakes'] is not None conformance = w.conformance() assert len(conformance['conformsTo']) == 4 collections = w.collections() assert len(collections) > 0 lakes = w.collection('lakes') assert lakes['id'] == 'lakes' assert lakes['title'] == 'Large Lakes' assert lakes['description'] == 'lakes of the world, public domain' # Minimum of limit param is 1 lakes_query = w.collection_items('lakes', limit=0) assert lakes_query['code'] == 'InvalidParameterValue' lakes_query = w.collection_items('lakes', limit=1) assert lakes_query['numberMatched'] == 25 assert lakes_query['numberReturned'] == 1 assert len(lakes_query['features']) == 1
def perform_request(self): """ Perform the validation. Uses https://github.com/p1c2u/openapi-spec-validator on the specfile (dict) returned from the OpenAPI endpoint. """ # Step 1 basic sanity check result = Result(True, 'OpenAPI Sanity Check') result.start() api_doc = None try: oa_feat = Features(self._resource.url, headers=self.get_request_headers()) set_accept_header(oa_feat, type_for_link( oa_feat.links, 'service-desc')) api_doc = oa_feat.api() # Basic sanity check for attr in ['components', 'paths', 'openapi']: val = api_doc.get(attr, None) if val is None: msg = 'OpenAPI doc: missing attr: %s' % attr result.set(False, msg) break except Exception as err: result.set(False, '%s:%s' % (result.message, str(err))) result.stop() self.result.add_result(result) # No use to proceed if OpenAPI basics not complied if api_doc is None or result.success is False: return # ASSERTION: OpenAPI doc exists, next OpenAPI Validation # Step 2 detailed OpenAPI Compliance test result = Result(True, 'Validate OpenAPI Compliance') result.start() try: # Call the openapi-spec-validator and iterate through errors errors_iterator = openapi_v3_spec_validator.iter_errors(api_doc) for error in errors_iterator: # Add each validation error as separate Result object result = push_result( self, result, False, str(error), 'OpenAPI Compliance Result') except Exception as err: result.set(False, '%s:%s' % (result.message, str(err))) result.stop() # Add to overall Probe result self.result.add_result(result)
def test_ogcapi_features_ldproxy(): w = Features(SERVICE_URL) assert w.url == 'https://www.ldproxy.nrw.de/rest/services/kataster/' assert w.url_query_string == 'f=json' conformance = w.conformance() assert len(conformance['conformsTo']) == 5 api = w.api() assert api['components']['parameters'] is not None assert api['paths'] is not None
def test_ogcapi_features_ldproxy(): w = Features(SERVICE_URL) assert w.url == 'https://www.ldproxy.nrw.de/rest/services/kataster/' assert w.url_query_string == 'f=json' conformance = w.conformance() assert len(conformance['conformsTo']) == 5 # TODO: remove pytest.raises once ldproxy is fixed/updated with pytest.raises(RuntimeError): api = w.api() assert api['components']['parameters'] is not None assert api['paths'] is not None
def test_ogcapi_features_pygeoapi(): w = Features(SERVICE_URL) assert w.url == 'https://demo.pygeoapi.io/master/' assert w.url_query_string is None api = w.api() assert api['components']['parameters'] is not None paths = api['paths'] assert paths is not None assert paths['/collections/lakes'] is not None conformance = w.conformance() assert len(conformance['conformsTo']) == 17 collections = w.collections() assert len(collections) > 0 feature_collections = w.feature_collections() assert len(feature_collections) > 0 lakes = w.collection('lakes') assert lakes['id'] == 'lakes' assert lakes['title'] == 'Large Lakes' assert lakes['description'] == 'lakes of the world, public domain' #lakes_queryables = w.collection_queryables('lakes') #assert len(lakes_queryables['queryables']) == 6 # Minimum of limit param is 1 with pytest.raises(RuntimeError): lakes_query = w.collection_items('lakes', limit=0) lakes_query = w.collection_items('lakes', limit=1, admin='admin-0') assert lakes_query['numberMatched'] == 25 assert lakes_query['numberReturned'] == 1 assert len(lakes_query['features']) == 1
def perform_request(self): """ Perform the drilldown. See https://github.com/geopython/OWSLib/blob/ master/tests/doctests/wfs3_GeoServerCapabilities.txt """ oa_feat = None collections = None # 1.1 Test Landing Page result = Result(True, 'Test Landing Page') result.start() try: oa_feat = Features(self._resource.url, headers=self.get_request_headers()) except Exception as err: result.set(False, '%s:%s' % (result.message, str(err))) result.stop() self.result.add_result(result) # 1.2 Test top endpoints existence: /conformance result = Result(True, 'conformance endpoint exists') result.start() try: set_accept_header(oa_feat, type_for_link( oa_feat.links, 'conformance')) oa_feat.conformance() except Exception as err: result.set(False, str(err)) result.stop() self.result.add_result(result) # 1.3 Test top endpoints existence: /collections result = Result(True, 'Get collections') result.start() try: set_accept_header(oa_feat, type_for_link( oa_feat.links, 'data')) collections = oa_feat.collections()['collections'] except Exception as err: result.set(False, '%s:%s' % (result.message, str(err))) result.stop() self.result.add_result(result) # 1.4 Test top endpoints existence: OpenAPI doc result = Result(True, 'Test OpenAPI Doc') result.start() try: # OWSLib 0.20.0+ has call to '/api now. set_accept_header(oa_feat, type_for_link( oa_feat.links, 'service-desc')) api_doc = oa_feat.api() for attr in ['components', 'paths', 'openapi']: val = api_doc.get(attr, None) if val is None: msg = 'missing attr: %s' % attr result = push_result( self, result, False, msg, 'Test OpenAPI doc') continue except Exception as err: result.set(False, '%s:%s' % (result.message, str(err))) result.stop() self.result.add_result(result) if self._parameters['drilldown_level'] == 'basic': return # ASSERTION: will do full drilldown, level 2, from here # 2. Test layers # TODO: use parameters to work on less/more drilling # "full" could be all layers. result = Result(True, 'Test Collections') result.start() coll_id = '' try: for collection in collections: coll_id = collection['id'] coll_id = coll_id try: set_accept_header(oa_feat, type_for_link( collection['links'], 'self')) coll = oa_feat.collection(coll_id) # TODO: Maybe also add crs for attr in ['id', 'links']: val = coll.get(attr, None) if val is None: msg = '%s: missing attr: %s' \ % (coll_id, attr) result = push_result( self, result, False, msg, 'Test Collection') continue except Exception as e: msg = 'GetCollection %s: OWSLib err: %s ' \ % (str(e), coll_id) result = push_result( self, result, False, msg, 'Test GetCollection') continue try: set_accept_header(oa_feat, 'application/geo+json') items = oa_feat.collection_items(coll_id, limit=1) except Exception as e: msg = 'GetItems %s: OWSLib err: %s ' % (str(e), coll_id) result = push_result( self, result, False, msg, 'Test GetItems') continue features = items.get('features', None) if features is None: msg = 'GetItems %s: No features attr' % coll_id result = push_result( self, result, False, msg, 'Test GetItems') continue type = items.get('type', '') if type != 'FeatureCollection': msg = '%s:%s type not FeatureCollection: %s' \ % (coll_id, type, val) result = push_result( self, result, False, msg, 'Test GetItems') continue if len(items['features']) > 0: fid = items['features'][0]['id'] try: item = oa_feat.collection_item(coll_id, fid) except Exception as e: msg = 'GetItem %s: OWSLib err: %s' \ % (str(e), coll_id) result = push_result( self, result, False, msg, 'Test GetItem') continue for attr in \ ['id', 'links', 'properties', 'geometry', 'type']: val = item.get(attr, None) if val is None: msg = '%s:%s missing attr: %s' \ % (coll_id, str(fid), attr) result = push_result( self, result, False, msg, 'Test GetItem') continue if attr == 'type' and val != 'Feature': msg = '%s:%s type not Feature: %s' \ % (coll_id, str(fid), val) result = push_result( self, result, False, msg, 'Test GetItem') continue except Exception as err: result.set(False, 'Collection err: %s : e=%s' % (coll_id, str(err))) result.stop() # Add to overall Probe result self.result.add_result(result)