def setUpClass(cls): super().setUpClass() cls.temp_dir = QtCore.QTemporaryDir() temp_dir = cls.temp_dir.path() cls.directories = [os.path.join(temp_dir, 'landingpage', 'projects'), os.path.join(temp_dir, 'landingpage', 'projects2')] shutil.copytree(os.path.join(unitTestDataPath('qgis_server'), 'landingpage'), os.path.join(temp_dir, 'landingpage'))
def test_dxf_export_works_with_reverse_axis_epsg(self): qs = "?" + "&".join([ "%s=%s" % i for i in list({ "MAP": urllib.parse.quote( os.path.join(self.testdata_path, 'test_dxf_export.qgs')), "SERVICE": "WMS", "VERSION": "1.3.0", "REQUEST": "GetMap", "BBOX": "399980,449980,400050,450100", "CRS": "EPSG:3844", "LAYERS": "test_dxf_export", "STYLES": ",", "FORMAT": "application/dxf", "SCALE": "500", "FILE_NAME": "test_dxf_export.dxf" }.items()) ]) r, h = self._result(self._execute_request(qs)) tempDir = QtCore.QTemporaryDir() dxf = os.path.join(tempDir.path(), 'test_dxf_export.dxf') f = open(dxf, 'wb') f.write(r) f.close() vl = QgsVectorLayer(dxf, "lyr", "ogr") myMessage = ('Expected downloaded dxf contains: %s line\nGot: %s\n' % (1, vl.featureCount())) self.assertEqual(vl.featureCount(), 1, myMessage) line_from_dxf = next(vl.getFeatures()).geometry().asWkt() line = 'LineString (450000 400000, 450100 400000)' self.assertEqual(line_from_dxf, line)
def testOgcApiHandlerContentType(self): """Test OGC API Handler content types""" project = QgsProject() project.read(unitTestDataPath('qgis_server') + '/test_project.qgs') request = QgsBufferServerRequest( 'http://server.qgis.org/api3/handlerthree?value1=9.5') response = QgsBufferServerResponse() # Add handler to API and test for /api3 ctx = QgsServerApiContext('/services/api3', request, response, project, self.server.serverInterface()) api = QgsServerOgcApi(self.server.serverInterface(), '/api3', 'apithree', 'a third api', '1.2') h3 = Handler3() api.registerHandler(h3) ctx = QgsServerApiContext('/services/api3/', request, response, project, self.server.serverInterface()) api.executeRequest(ctx) self.assertEqual( json.loads(bytes(ctx.response().data()))['value1'], 9.5) # Call HTML ctx.request().setUrl( QtCore.QUrl( 'http://server.qgis.org/api3/handlerthree.html?value1=9.5')) with self.assertRaises(QgsServerApiBadRequestException) as ex: api.executeRequest(ctx) self.assertEqual(str(ex.exception), 'Unsupported Content-Type: HTML') h3.setContentTypes([QgsServerOgcApi.HTML]) with self.assertRaises(QgsServerApiBadRequestException) as ex: api.executeRequest(ctx) self.assertEqual(str(ex.exception), 'Template not found: handlerThree.html') # Define a template path dir = QtCore.QTemporaryDir() with open(dir.path() + '/handlerThree.html', 'w+') as f: f.write("Hello world") h3.templatePathOverride = dir.path() + '/handlerThree.html' ctx.response().clear() api.executeRequest(ctx) self.assertEqual(bytes(ctx.response().data()), b"Hello world")