当前位置: 首页>>代码示例>>Python>>正文


Python QgsServer.handleRequestGetBody方法代码示例

本文整理汇总了Python中qgis.server.QgsServer.handleRequestGetBody方法的典型用法代码示例。如果您正苦于以下问题:Python QgsServer.handleRequestGetBody方法的具体用法?Python QgsServer.handleRequestGetBody怎么用?Python QgsServer.handleRequestGetBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qgis.server.QgsServer的用法示例。


在下文中一共展示了QgsServer.handleRequestGetBody方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestQgsServer

# 需要导入模块: from qgis.server import QgsServer [as 别名]
# 或者: from qgis.server.QgsServer import handleRequestGetBody [as 别名]
class TestQgsServer(unittest.TestCase):

    def setUp(self):
        """Create the server instance"""
        self.testdata_path = unitTestDataPath('qgis_server') + '/'
        # Clean env just to be sure
        env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
        for ev in env_vars:
            try:
                del os.environ[ev]
            except KeyError:
                pass
        self.server = QgsServer()


    def test_destructor_segfaults(self):
        """Segfault on destructor?"""
        server = QgsServer()
        del server


    def test_multiple_servers(self):
        """Segfaults?"""
        for i in range(10):
            locals()["s%s" % i] = QgsServer()
            locals()["s%s" % i].handleRequest()


    def test_api(self):
        """Using an empty query string (returns an XML exception)
        we are going to test if headers and body are returned correctly"""
        # Test as a whole
        response = str(self.server.handleRequest())
        expected = 'Content-Length: 206\nContent-Type: text/xml; charset=utf-8\n\n<ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc">\n <ServiceException code="Service configuration error">Service unknown or unsupported</ServiceException>\n</ServiceExceptionReport>\n'
        self.assertEqual(response, expected)
        # Test header
        response = str(self.server.handleRequestGetHeaders())
        expected = 'Content-Length: 206\nContent-Type: text/xml; charset=utf-8\n\n'
        self.assertEqual(response, expected)
        # Test body
        response = str(self.server.handleRequestGetBody())
        expected = '<ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc">\n <ServiceException code="Service configuration error">Service unknown or unsupported</ServiceException>\n</ServiceExceptionReport>\n'
        self.assertEqual(response, expected)


    def test_pluginfilters(self):
        """Test python plugins filters"""
        try:
            from qgis.server import QgsServerFilter
        except ImportError:
            print "QGIS Server plugins are not compiled. Skipping test"
            return

        class SimpleHelloFilter(QgsServerFilter):
            def requestReady(self):
                QgsMessageLog.logMessage("SimpleHelloFilter.requestReady")

            def sendResponse(self):
                QgsMessageLog.logMessage("SimpleHelloFilter.sendResponse")

            def responseComplete(self):
                request = self.serverInterface().requestHandler()
                params = request.parameterMap()
                QgsMessageLog.logMessage("SimpleHelloFilter.responseComplete")
                if params.get('SERVICE', '').upper() == 'SIMPLE':
                    request.clearHeaders()
                    request.setHeader('Content-type', 'text/plain')
                    request.clearBody()
                    request.appendBody('Hello from SimpleServer!')


        serverIface = self.server.serverInterface()
        serverIface.registerFilter(SimpleHelloFilter(serverIface), 100 )
        response = str(self.server.handleRequest('service=simple'))
        expected = 'Content-type: text/plain\n\nHello from SimpleServer!'
        self.assertEqual(response, expected)


    ## WMS tests
    def wms_request_compare(self, request):
        map = self.testdata_path + "testproject.qgs"
        query_string = 'MAP=%s&SERVICE=WMS&VERSION=1.3&REQUEST=%s' % (map, request)
        response = str(self.server.handleRequest(query_string))
        f = open(self.testdata_path + request.lower() + '.txt')
        expected = f.read()
        f.close()
        # Store for debug or to regenerate the reference documents:
        """
        f = open(os.path.dirname(__file__) + '/expected.txt', 'w+')
        f.write(expected)
        f.close()
        f = open(os.path.dirname(__file__) + '/response.txt', 'w+')
        f.write(response)
        f.close()
        """
        response = re.sub(RE_STRIP_PATH, '', response)
        expected = re.sub(RE_STRIP_PATH, '', expected)
        self.assertEqual(response, expected, msg="request %s failed. Expected:\n%s\n\nResponse:\n%s" % (request, expected, response))


#.........这里部分代码省略.........
开发者ID:hylhero,项目名称:QGIS,代码行数:103,代码来源:test_qgsserver.py


注:本文中的qgis.server.QgsServer.handleRequestGetBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。