예제 #1
0
    def __init__(self, url, timeout, auth):
        try:
            from owslib.ogcapi.records import Records
        except ModuleNotFoundError:
            # OWSLIB_OAREC_SUPPORTED already set to False
            pass

        super().__init__(url, timeout, auth)

        self.type = CATALOG_TYPES[1]
        self.format = 'json'
        self.service_info_template = 'oarec_service_metadata.html'
        self.record_info_template = 'record_metadata_oarec.html'
        self.base_url = None
        self.record_collection = None

        if '/collections/' in self.url:  # catalog is a collection
            self.base_url, self.record_collection = self.url.split(
                '/collections/')  # noqa
            self.conn = Records(self.base_url,
                                timeout=self.timeout,
                                auth=self.auth)
            c = self.conn.collection(self.record_collection)
            try:
                self.conn.links = c['links']
                self.conn.title = c['title']
                self.conn.description = c['description']
            except KeyError:
                pass
            self.request = self.conn.request
        else:
            self.conn = Records(self.url, timeout=self.timeout, auth=self.auth)
            self.request = None

        self.response = self.conn.response
예제 #2
0
    def __init__(self, url, timeout, auth):
        super().__init__(url, timeout, auth)

        self.type = CATALOG_TYPES[1]
        self.format = 'json'
        self.service_info_template = 'oarec_service_metadata.html'
        self.record_info_template = 'record_metadata_oarec.html'
        self.base_url = None
        self.record_collection = None

        if '/collections/' in self.url:  # catalog is a collection
            self.base_url, self.record_collection = self.url.split(
                '/collections/')  # noqa
            self.conn = Records(self.base_url,
                                timeout=self.timeout,
                                auth=self.auth)
            c = self.conn.collection(self.record_collection)
            try:
                self.conn.links = c['links']
                self.conn.title = c['title']
                self.conn.description = c['description']
            except KeyError:
                pass
            self.request = self.conn.request
        else:
            self.conn = Records(self.url, timeout=self.timeout, auth=self.auth)
            self.request = None

        self.response = self.conn.response
def test_ogcapi_records_pygeoapi():
    w = Records(SERVICE_URL)

    assert w.url == 'http://52.170.144.218:8000/'
    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/msc-wis-dcpc'] is not None

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

    collections = w.collections()
    assert len(collections) > 0

    msc_wis_dcpc = w.collection('msc-wis-dcpc')
    assert msc_wis_dcpc['id'] == 'msc-wis-dcpc'
    assert msc_wis_dcpc['title'] == 'MSC WIS DCPC'
    assert msc_wis_dcpc['description'] == 'MSC WIS DCPC'

    msc_wis_dcpc_queryables = w.collection_queryables('msc-wis-dcpc')
    assert len(msc_wis_dcpc_queryables['queryables']) == 7

    # Minimum of limit param is 1
    with pytest.raises(RuntimeError):
        msc_wis_dcpc_query = w.collection_items('msc-wis-dcpc', limit=0)

    msc_wis_dcpc_query = w.collection_items('msc-wis-dcpc', limit=1)
    assert msc_wis_dcpc_query['numberMatched'] == 178
    assert msc_wis_dcpc_query['numberReturned'] == 1
    assert len(msc_wis_dcpc_query['features']) == 1

    msc_wis_dcpc_query = w.collection_items('msc-wis-dcpc', q='metar')
    assert msc_wis_dcpc_query['numberMatched'] == 2
    assert msc_wis_dcpc_query['numberReturned'] == 2
    assert len(msc_wis_dcpc_query['features']) == 2
예제 #4
0
def test_ogcapi_records_pygeoapi():
    w = Records(SERVICE_URL)

    assert w.url == 'https://dev.api.weather.gc.ca/msc-wis-dcpc/'
    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/discovery-metadata'] is not None

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

    collections = w.collections()
    assert len(collections) > 0

    records = w.records()
    assert len(records['features']) > 0

    msc_wis_dcpc = w.collection('discovery-metadata')
    assert msc_wis_dcpc['id'] == 'discovery-metadata'
    assert msc_wis_dcpc['title'] == 'MSC discovery metadata'
    assert msc_wis_dcpc['description'] == 'MSC discovery metadata'
    assert w.request == 'https://dev.api.weather.gc.ca/msc-wis-dcpc/collections/discovery-metadata'  # noqa
    assert w.response is not None
    assert isinstance(w.response, dict)

    msc_wis_dcpc_queryables = w.collection_queryables('discovery-metadata')
    assert len(msc_wis_dcpc_queryables['queryables']) == 7

    # Minimum of limit param is 1
    with pytest.raises(RuntimeError):
        msc_wis_dcpc_query = w.collection_items('discovery-metadata', limit=0)

    msc_wis_dcpc_query = w.collection_items('discovery-metadata', limit=1)
    assert msc_wis_dcpc_query['numberMatched'] == 178
    assert msc_wis_dcpc_query['numberReturned'] == 1
    assert len(msc_wis_dcpc_query['features']) == 1

    msc_wis_dcpc_query = w.collection_items('discovery-metadata', q='metar')
    assert msc_wis_dcpc_query['numberMatched'] == 2
    assert msc_wis_dcpc_query['numberReturned'] == 2
    assert len(msc_wis_dcpc_query['features']) == 2
예제 #5
0
class OARecSearch(SearchBase):
    def __init__(self, url, timeout, auth):
        try:
            from owslib.ogcapi.records import Records
        except ModuleNotFoundError:
            # OWSLIB_OAREC_SUPPORTED already set to False
            pass

        super().__init__(url, timeout, auth)

        self.type = CATALOG_TYPES[1]
        self.format = 'json'
        self.service_info_template = 'oarec_service_metadata.html'
        self.record_info_template = 'record_metadata_oarec.html'
        self.base_url = None
        self.record_collection = None

        if '/collections/' in self.url:  # catalog is a collection
            self.base_url, self.record_collection = self.url.split(
                '/collections/')  # noqa
            self.conn = Records(self.base_url,
                                timeout=self.timeout,
                                auth=self.auth)
            c = self.conn.collection(self.record_collection)
            try:
                self.conn.links = c['links']
                self.conn.title = c['title']
                self.conn.description = c['description']
            except KeyError:
                pass
            self.request = self.conn.request
        else:
            self.conn = Records(self.url, timeout=self.timeout, auth=self.auth)
            self.request = None

        self.response = self.conn.response

    def query_records(self, bbox=[], keywords=None, limit=10, offset=1):
        # set zero-based offset (default MetaSearch behavior is CSW-based
        # offset of 1
        offset2 = offset - 1

        params = {
            'collection_id': self.record_collection,
            'limit': limit,
            'offset': offset2
        }

        if keywords:
            params['q'] = keywords
        if bbox and bbox != ['-180', '-90', '180', '90']:
            params['bbox'] = bbox

        self.response = self.conn.collection_items(**params)

        self.matches = self.response.get('numberMatched', 0)
        self.returned = self.response.get('numberReturned', 0)
        self.request = self.conn.request

    def records(self):
        recs = []

        for rec in self.response['features']:
            rec1 = {
                'identifier': rec['id'],
                'type': rec['properties']['type'],
                'bbox': None,
                'title': rec['properties']['title'],
                'links': rec.get('links', [])
            }
            try:
                bbox2 = rec['properties']['extent']['spatial']['bbox'][0]
                if bbox2:
                    rec1['bbox'] = bbox_list_to_dict(bbox2)
            except KeyError:
                pass

            recs.append(rec1)

        return recs

    def get_record(self, identifier):
        return self.conn.collection_item(self.record_collection, identifier)

    def parse_link(self, link):
        link2 = {}
        if 'href' in link:
            link2['url'] = link['href']
        if 'type' in link:
            link2['protocol'] = link['type']
        if 'title' in link:
            link2['title'] = link['title']
        if 'id' in link:
            link2['name'] = link['id']
        return link2
예제 #6
0
def test_ogcapi_records_pycsw():
    w = Records(SERVICE_URL)

    assert w.url == 'https://demo.pycsw.org/cite/'
    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/{collectionId}'] is not None

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

    collections = w.collections()
    assert len(collections) > 0

    record_collections = w.records()
    assert record_collections == ['metadata:main']

    pycsw_cite_demo = w.collection('metadata:main')
    assert pycsw_cite_demo['id'] == 'metadata:main'
    assert pycsw_cite_demo[
        'title'] == 'pycsw OGC CITE demo and Reference Implementation'  # noqa
    assert pycsw_cite_demo['itemType'] == 'record'
    assert w.request == 'https://demo.pycsw.org/cite/collections/metadata:main'  # noqa
    assert w.response is not None
    assert isinstance(w.response, dict)

    pycsw_cite_demo_queryables = w.collection_queryables('metadata:main')
    assert len(pycsw_cite_demo_queryables['properties'].keys()) == 12

    # Minimum of limit param is 1
    with pytest.raises(RuntimeError):
        pycsw_cite_demo_query = w.collection_items('metadata:main', limit=0)

    pycsw_cite_demo_query = w.collection_items('metadata:main', limit=1)
    assert pycsw_cite_demo_query['numberMatched'] == 12
    assert pycsw_cite_demo_query['numberReturned'] == 1
    assert len(pycsw_cite_demo_query['features']) == 1

    pycsw_cite_demo_query = w.collection_items('metadata:main', q='lorem')
    assert pycsw_cite_demo_query['numberMatched'] == 5
    assert pycsw_cite_demo_query['numberReturned'] == 5
    assert len(pycsw_cite_demo_query['features']) == 5

    cql_text = "title LIKE 'Lorem%'"
    pycsw_cite_demo_query = w.collection_items('metadata:main',
                                               filter=cql_text)
    assert pycsw_cite_demo_query['numberMatched'] == 2
    assert pycsw_cite_demo_query['numberReturned'] == 2
    assert len(pycsw_cite_demo_query['features']) == 2

    cql_json = {'op': '=', 'args': [{'property': 'title'}, 'Lorem ipsum']}
    pycsw_cite_demo_query = w.collection_items('metadata:main', cql=cql_json)
    assert pycsw_cite_demo_query['numberMatched'] == 1
    assert pycsw_cite_demo_query['numberReturned'] == 1
    assert len(pycsw_cite_demo_query['features']) == 1
def test_ogcapi_records_pygeoapi():
    w = Records(SERVICE_URL)

    assert w.url == SERVICE_URL
    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/dutch-metadata'] is not None

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

    collections = w.collections()
    assert len(collections) > 0

    records = w.records()
    assert len(records) == 1

    dutch_metacat = w.collection('dutch-metadata')
    assert dutch_metacat['id'] == 'dutch-metadata'
    assert dutch_metacat[
        'title'] == 'Sample metadata records from Dutch Nationaal georegister'  # noqa
    assert dutch_metacat[
        'description'] == 'Sample metadata records from Dutch Nationaal georegister'  # noqa
    assert w.request == f'{SERVICE_URL}collections/dutch-metadata'
    assert w.response is not None
    assert isinstance(w.response, dict)

    dutch_metacat_queryables = w.collection_queryables('dutch-metadata')
    assert len(dutch_metacat_queryables['properties']) == 11

    # Minimum of limit param is 1
    with pytest.raises(RuntimeError):
        dutch_metacat_query = w.collection_items('dutch-metadata', limit=0)

    dutch_metacat_query = w.collection_items('dutch-metadata', limit=1)
    assert dutch_metacat_query['numberMatched'] == 198
    assert dutch_metacat_query['numberReturned'] == 1
    assert len(dutch_metacat_query['features']) == 1

    dutch_metacat_query = w.collection_items('dutch-metadata', q='Wegpanorama')
    assert dutch_metacat_query['numberMatched'] == 2
    assert dutch_metacat_query['numberReturned'] == 2
    assert len(dutch_metacat_query['features']) == 2