Ejemplo n.º 1
0
def test_wfs3_pygeoapi():
    w = WebFeatureService(SERVICE_URL, version='3.0')

    assert w.url == 'https://demo.pygeoapi.io/master/'
    assert w.version == '3.0'
    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'

    lakes_query = w.collection_items('lakes', limit=0)
    assert lakes_query['numberMatched'] == 25
    assert lakes_query['numberReturned'] == 0
    assert len(lakes_query['features']) == 0
def test_wfs3_pygeoapi():
    w = WebFeatureService(SERVICE_URL, version='3.0')

    assert w.url == 'http://geo.kralidis.ca/pygeoapi/'
    assert w.version == '3.0'
    assert w.url_query_string is None

    conformance = w.conformance()
    assert len(conformance['conformsTo']) == 4

    collections = w.collections()
    assert len(collections) == 3

    lakes = w.collection('lakes')
    assert lakes['name'] == 'lakes'
    assert lakes['title'] == 'Large Lakes'
    assert lakes['description'] == 'lakes of the world, public domain'

    lakes_query = w.collection_items('lakes', limit=0)
    assert lakes_query['numberMatched'] == 25
    assert lakes_query['numberReturned'] == 0
    assert len(lakes_query['features']) == 0
Ejemplo n.º 3
0
    def perform_request(self):
        """
        Perform the drilldown.
        See https://github.com/geopython/OWSLib/blob/
        master/tests/doctests/wfs3_GeoServerCapabilities.txt
        """
        wfs3 = None
        collections = None

        # 1.1 Test Landing Page
        result = Result(True, 'Test Landing Page')
        result.start()
        try:
            wfs3 = WebFeatureService(self._resource.url, version='3.0')
        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:
            wfs3.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:
            collections = wfs3.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:

            # TODO: OWSLib 0.17.1 has no call to '/api yet, upgrade when GHC
            #  supports Py3 to 0.19+.
            api = wfs3_api_doc(wfs3)
            for attr in ['components', 'paths', 'openapi']:
                val = api.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:
                    coll = wfs3.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:
                    items = wfs3.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 = wfs3.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)
Ejemplo n.º 4
0
    def perform_request(self):
        """
        Perform the drilldown.
        See https://github.com/geopython/OWSLib/blob/
        master/tests/doctests/wfs3_GeoServerCapabilities.txt
        """
        wfs3 = None
        collections = None

        # 1. Test top endpoints existence
        result = Result(True, 'Test Top Endpoints')
        result.start()
        try:
            wfs3 = WebFeatureService(self._resource.url, version='3.0')
            wfs3.conformance()

            # TODO: OWSLib 0.17.1 has no call to '/api yet.
            url = wfs3._build_url('api')
            api = requests.get(url).json()
            for attr in ['components', 'paths', 'openapi']:
                val = api.get(attr, None)
                if val is None:
                    msg = '/api: missing attr: %s' % attr
                    result = push_result(self, result, False, msg,
                                         'Test Collection')
                    continue

            collections = wfs3.collections()
        except Exception as err:
            result.set(False, str(err))

        result.stop()
        self.result.add_result(result)

        if self._parameters['drilldown_level'] == 'basic':
            return

        # ASSERTION: will do full drilldown 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_name = ''
        try:
            for collection in collections:
                coll_name = collection['name']
                coll_name = coll_name.encode('utf-8')

                try:
                    coll = wfs3.collection(coll_name)

                    # TODO: Maybe also add crs
                    for attr in ['name', 'links']:
                        val = coll.get(attr, None)
                        if val is None:
                            msg = '%s: missing attr: %s' \
                                  % (coll_name, attr)
                            result = push_result(self, result, False, msg,
                                                 'Test Collection')
                            continue
                except Exception as e:
                    msg = 'GetCollection %s: OWSLib err: %s ' \
                          % (str(e), coll_name)
                    result = push_result(self, result, False, msg,
                                         'Test GetCollection')
                    continue

                try:
                    items = wfs3.collection_items(coll_name, limit=1)
                except Exception as e:
                    msg = 'GetItems %s: OWSLib err: %s ' % (str(e), coll_name)
                    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_name
                    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_name, type, val)
                    result = push_result(self, result, False, msg,
                                         'Test GetItems')
                    continue

                if len(items['features']) > 0:

                    fid = items['features'][0]['id']
                    try:
                        item = wfs3.collection_item(coll_name, fid)
                    except Exception as e:
                        msg = 'GetItem %s: OWSLib err: %s' \
                              % (str(e), coll_name)
                        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_name, 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_name, 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_name, str(err)))

        result.stop()

        # Add to overall Probe result
        self.result.add_result(result)