Esempio n. 1
0
 def test_wfs3_landing_page_json(self):
     """Test WFS3 API landing page in JSON format"""
     request = QgsBufferServerRequest('http://server.qgis.org/wfs3.json')
     self.compareApi(request, None, 'test_wfs3_landing_page.json')
     request = QgsBufferServerRequest('http://server.qgis.org/wfs3')
     request.setHeader('Accept', 'application/json')
     self.compareApi(request, None, 'test_wfs3_landing_page.json')
Esempio n. 2
0
 def _test_error(uri):
     request = QgsBufferServerRequest(uri)
     request.setHeader('Accept', 'application/json')
     response = QgsBufferServerResponse()
     self.server.handleRequest(request, response)
     self.assertEqual(
         bytes(response.body()),
         b'<ServerException>Project file error. For OWS services: please provide a SERVICE and a MAP parameter pointing to a valid QGIS project file</ServerException>\n'
     )
Esempio n. 3
0
    def test_wfs3_collections_content_type(self):
        """Test WFS3 API collections in html format with Accept header"""

        request = QgsBufferServerRequest('http://server.qgis.org/wfs3/collections')
        request.setHeader('Accept', 'text/html')
        project = QgsProject()
        project.read(unitTestDataPath('qgis_server') + '/test_project_api.qgs')
        response = QgsBufferServerResponse()
        self.server.handleRequest(request, response, project)
        self.assertEqual(response.headers()['Content-Type'], 'text/html')
Esempio n. 4
0
 def _test_valid(uri):
     request = QgsBufferServerRequest(uri)
     request.setHeader('Accept', 'application/json')
     response = QgsBufferServerResponse()
     self.server.handleRequest(request, response)
     if 'index' not in uri:
         self.assertEqual(response.headers()[
             'Location'], 'http://server.qgis.org/mylanding/index.json')
     else:
         # Just check that it's valid json
         j = json.loads(bytes(response.body()))
Esempio n. 5
0
    def test_landing_page_prefix(self):

        os.environ['QGIS_SERVER_LANDING_PAGE_PREFIX'] = '/mylanding'

        def _test_error(uri):
            request = QgsBufferServerRequest(uri)
            request.setHeader('Accept', 'application/json')
            response = QgsBufferServerResponse()
            self.server.handleRequest(request, response)
            self.assertEqual(
                bytes(response.body()),
                b'<ServerException>Project file error. For OWS services: please provide a SERVICE and a MAP parameter pointing to a valid QGIS project file</ServerException>\n'
            )

        _test_error('http://server.qgis.org/index.json')
        _test_error('http://server.qgis.org/index.html')
        _test_error('http://server.qgis.org/')
        _test_error('http://server.qgis.org')

        def _test_valid(uri):
            request = QgsBufferServerRequest(uri)
            request.setHeader('Accept', 'application/json')
            response = QgsBufferServerResponse()
            self.server.handleRequest(request, response)
            if 'index' not in uri:
                self.assertEqual(
                    response.headers()['Location'],
                    'http://server.qgis.org/mylanding/index.json')
            else:
                # Just check that it's valid json
                j = json.loads(bytes(response.body()))

        _test_valid('http://server.qgis.org/mylanding')
        _test_valid('http://server.qgis.org/mylanding/')
        _test_valid('http://server.qgis.org/mylanding/index.json')

        # Test redirects with prefix
        os.environ['QGIS_SERVER_LANDING_PAGE_PREFIX'] = '/ows/catalog'
        request = QgsBufferServerRequest('http://server.qgis.org/ows/catalog')
        response = QgsBufferServerResponse()
        request.setHeader('Accept', 'text/html')
        self.server.handleRequest(request, response)
        self.assertEqual(response.headers()['Location'],
                         'http://server.qgis.org/ows/catalog/index.html')

        request = QgsBufferServerRequest('http://server.qgis.org/ows/catalog/')
        response = QgsBufferServerResponse()
        request.setHeader('Accept', 'text/html')
        self.server.handleRequest(request, response)
        self.assertEqual(response.headers()['Location'],
                         'http://server.qgis.org/ows/catalog/index.html')
    def test_landing_page_redirects(self):
        """Test landing page redirects"""

        request = QgsBufferServerRequest('http://server.qgis.org/')
        request.setHeader('Accept', 'application/json')
        response = QgsBufferServerResponse()
        self.server.handleRequest(request, response)
        self.assertEqual(response.headers()[
                         'Location'], 'http://server.qgis.org/index.json')
        response = QgsBufferServerResponse()
        request.setHeader('Accept', 'text/html')
        self.server.handleRequest(request, response)
        self.assertEqual(response.headers()[
                         'Location'], 'http://server.qgis.org/index.html')
    def test_project_json(self):
        """Test landing page project call in JSON format"""

        # Get hashes for test projects
        request = QgsBufferServerRequest('http://server.qgis.org/index.json')
        request.setHeader('Accept', 'application/json')
        response = QgsBufferServerResponse()
        self.server.handleRequest(request, response)

        j = json.loads(bytes(response.body()))
        test_projects = {p['id']: p['title'].replace(' ', '_') for p in j['projects']}

        for identifier, name in test_projects.items():
            request = QgsBufferServerRequest(
                'http://server.qgis.org/map/' + identifier)
            request.setHeader('Accept', 'application/json')
            self.compareApi(
                request, None, 'test_project_{}.json'.format(name.replace('.', '_')), subdir='landingpage')