Beispiel #1
0
    def test_find_url(self):
        """
        Test finding URL
        """
        self.assertEqual(
            WadlServiceParser.find_url(
                'https://www.emidius.eu/fdsnws/event/1/query?'),
            'https://www.emidius.eu/fdsnws/event/1/application.wadl')
        self.assertEqual(
            WadlServiceParser.find_url(
                'https://www.emidius.eu/fdsnws/event/1/query'),
            'https://www.emidius.eu/fdsnws/event/1/application.wadl')

        self.assertEqual(
            WadlServiceParser.find_url(
                'https://www.emidius.eu/fdsnws/event/1/'),
            'https://www.emidius.eu/fdsnws/event/1/application.wadl')

        self.assertEqual(
            WadlServiceParser.find_url(
                'https://www.emidius.eu/fdsnws/event/1/application.wadl'),
            'https://www.emidius.eu/fdsnws/event/1/application.wadl')

        self.assertEqual(
            WadlServiceParser.find_url(
                'https://earthquake.usgs.gov/fdsnws/event/1/'),
            'https://earthquake.usgs.gov/fdsnws/event/1/application.wadl')
    def _load_service(self):
        """
        Attempts to defined the service via WADL
        """
        url = self.web_service_url_edit.text().strip()
        url = WadlServiceParser.find_url(url)

        request = QNetworkRequest(QUrl(url))
        request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
        reply = QgsNetworkAccessManager.instance().get(request)

        def response_finished(_reply: QNetworkReply):
            """
            Triggered when the response is finished
            """
            self.button_load_service.setEnabled(True)
            self.button_load_service.setText(
                self.tr('Load Web Service Capabilities'))

            content = _reply.readAll()
            try:
                self._set_state_from_wadl(
                    WadlServiceParser.parse_wadl(content, self.service_type,
                                                 url))
            except AssertionError:
                self.message_bar.pushMessage(
                    '',
                    self.tr('Could not load web service capabilities from {}'.
                            format(url)), Qgis.Critical, 0)

        self.button_load_service.setEnabled(False)
        self.button_load_service.setText(self.tr('Loading'))
        reply.finished.connect(partial(response_finished, reply))
        def response_finished(_reply: QNetworkReply):
            """
            Triggered when the response is finished
            """
            self.button_load_service.setEnabled(True)
            self.button_load_service.setText(
                self.tr('Load Web Service Capabilities'))

            content = _reply.readAll()
            try:
                self._set_state_from_wadl(
                    WadlServiceParser.parse_wadl(content, self.service_type,
                                                 url))
            except AssertionError:
                self.message_bar.pushMessage(
                    '',
                    self.tr('Could not load web service capabilities from {}'.
                            format(url)), Qgis.Critical, 0)
Beispiel #4
0
    def test_station(self):
        """
        Test station parsing
        """
        path = os.path.join(os.path.dirname(__file__), 'data', 'station.wadl')
        with open(path, 'rb') as f:
            content = f.read()

        byte_array = QByteArray(content)

        res = WadlServiceParser.parse_wadl(
            byte_array, ServiceManager.FDSNSTATION,
            'http://www.orfeus-eu.org/fdsnws/station/1/application.wadl')
        self.assertEqual(
            res, {
                'boundingbox': [-90.0, -180.0, 90.0, 180.0],
                'endpointurl':
                'http://www.orfeus-eu.org/fdsnws/station/1/query?',
                'settings': {}
            })
Beispiel #5
0
    def test_macro_2(self):
        """
        Test WADL macro parsing 2
        """
        path = os.path.join(os.path.dirname(__file__), 'data', 'macro2.wadl')
        with open(path, 'rb') as f:
            content = f.read()

        byte_array = QByteArray(content)

        res = WadlServiceParser.parse_wadl(
            byte_array, ServiceManager.MACROSEISMIC,
            'https://www.emidius.mi.ingv.it/services/macroseismic/application.wadl'
        )
        self.assertEqual(
            res, {
                'boundingbox': [5.0, 35.0, 21.0, 48.0],
                'endpointurl':
                'https://www.emidius.mi.ingv.it/services/macroseismic/query?',
                'settings': {
                    'outputgeojson': False,
                    'outputjson': True,
                    'outputkml': False,
                    'outputtext': True,
                    'querycatalog': True,
                    'querycircular': True,
                    'querycircularradiuskm': True,
                    'querycontributorid': True,
                    'querydepth': True,
                    'queryeventid': True,
                    'queryeventtype': False,
                    'queryincludeallmagnitudes': True,
                    'queryincludeallorigins': True,
                    'queryincludearrivals': True,
                    'querymagnitudeid': False,
                    'queryoriginid': False,
                    'queryupdatedafter': False
                }
            })
Beispiel #6
0
    def test_event_wadl(self):
        """
        Test WADL event parsing
        """
        path = os.path.join(os.path.dirname(__file__), 'data', 'event.wadl')
        with open(path, 'rb') as f:
            content = f.read()

        byte_array = QByteArray(content)

        res = WadlServiceParser.parse_wadl(
            byte_array, ServiceManager.FDSNEVENT,
            'http://webservices.rm.ingv.it/fdsnws/event/1/application.wadl')
        self.assertEqual(
            res, {
                'boundingbox': [-120.0, -70.0, 60.0, 50.0],
                'endpointurl':
                'http://webservices.rm.ingv.it/fdsnws/event/1/query?',
                'settings': {
                    'outputgeojson': False,
                    'outputjson': False,
                    'outputkml': False,
                    'outputtext': False,
                    'querycatalog': False,
                    'querycircular': True,
                    'querycircularradiuskm': True,
                    'querycontributorid': False,
                    'querydepth': True,
                    'queryeventid': True,
                    'queryeventtype': True,
                    'queryincludeallmagnitudes': True,
                    'queryincludeallorigins': True,
                    'queryincludearrivals': True,
                    'querymagnitudeid': True,
                    'queryoriginid': True,
                    'queryupdatedafter': True
                }
            })