def test_requestUrl(self):
     """Test url"""
     request = QgsServerRequest(
         'http://somesite.com/somepath', QgsServerRequest.GetMethod)
     self.assertEqual(request.url().toString(),
                      'http://somesite.com/somepath')
     request.setUrl(QUrl('http://someother.com/someotherpath'))
     self.assertEqual(request.url().toString(),
                      'http://someother.com/someotherpath')
    def executeRequest(self, request: QgsServerRequest, response: QgsServerResponse,
                       project: QgsProject) -> None:
        """ Execute a 'cadastre' request
        """
        params = request.parameters()

        try:
            reqparam  = params.get('REQUEST','').lower()

            if reqparam == 'createpdf':
                self.create_pdf(params, response, project)
            elif reqparam == 'getpdf':
                self.get_pdf(params, response)
            elif reqparam == 'gethtml':
                self.get_html(params, response, project)
            else:
                raise CadastreError(400, ("Invalid REQUEST parameter: "
                                          "must be one of GetHtml, CreatePdf or GetPdf,"
                                          "found '%s'") % reqparam)

        except CadastreError as err:
            err.formatResponse(response)
        except Exception as exc:
            QgsMessageLog.logMessage("Unhandled exception:\n%s" % traceback.format_exc(),"cadastre",Qgis.Critical)
            err = CadastreError(500,"Internal 'cadastre' service error")
            err.formatResponse(response)
 def test_requestParameters(self):
     """Test request parameters"""
     request = QgsServerRequest('http://somesite.com/somepath?parm1=val1&parm2=val2', QgsServerRequest.GetMethod)
     parameters = {'PARM1': 'val1', 'PARM2': 'val2'}
     for k, v in request.parameters().items():
         self.assertEqual(parameters[k], v)
     request.removeParameter('PARM1')
     self.assertEqual(request.parameters(), {'PARM2': 'val2'})
     request.setHeader('PARM1', 'val1')
     for k, v in request.headers().items():
         self.assertEqual(parameters[k], v)
 def test_requestHeaders(self):
     """Test request headers"""
     headers = {'header-key-1': 'header-value-1', 'header-key-2': 'header-value-2'}
     request = QgsServerRequest('http://somesite.com/somepath', QgsServerRequest.GetMethod, headers)
     for k, v in request.headers().items():
         self.assertEqual(headers[k], v)
     request.removeHeader('header-key-1')
     self.assertEqual(request.headers(), {'header-key-2': 'header-value-2'})
     request.setHeader('header-key-1', 'header-value-1')
     for k, v in request.headers().items():
         self.assertEqual(headers[k], v)
 def test_requestMethod(self):
     request = QgsServerRequest('http://somesite.com/somepath', QgsServerRequest.GetMethod)
     self.assertEqual(request.method(), QgsServerRequest.GetMethod)
     request.setMethod(QgsServerRequest.PostMethod)
     self.assertEqual(request.method(), QgsServerRequest.PostMethod)
 def test_requestParametersDecoding(self):
     """Test request parameters decoding"""
     request = QgsServerRequest('http://somesite.com/somepath?parm1=val1%20%2B+val2', QgsServerRequest.GetMethod)
     self.assertEqual(request.parameters()['PARM1'], 'val1 + val2')
 def test_requestMethod(self):
     request = QgsServerRequest('http://somesite.com/somepath',
                                QgsServerRequest.GetMethod)
     self.assertEqual(request.method(), QgsServerRequest.GetMethod)
     request.setMethod(QgsServerRequest.PostMethod)
     self.assertEqual(request.method(), QgsServerRequest.PostMethod)
 def test_requestParametersDecoding(self):
     """Test request parameters decoding"""
     request = QgsServerRequest(
         'http://somesite.com/somepath?parm1=val1%20%2B+val2',
         QgsServerRequest.GetMethod)
     self.assertEqual(request.parameters()['PARM1'], 'val1 + val2')
 def test_requestUrl(self):
     """Test url"""
     request = QgsServerRequest('http://somesite.com/somepath', QgsServerRequest.GetMethod)
     self.assertEqual(request.url().toString(), 'http://somesite.com/somepath')
     request.setUrl(QUrl('http://someother.com/someotherpath'))
     self.assertEqual(request.url().toString(), 'http://someother.com/someotherpath')
Exemple #10
0
 def test_add_parameters(self):
     request = QgsServerRequest()
     request.setParameter('FOOBAR', 'foobar')
     self.assertEqual(request.parameter('FOOBAR'), 'foobar')
     self.assertEqual(request.parameter('UNKNOWN'), '')
Exemple #11
0
 def test_add_parameters(self):
     request = QgsServerRequest()
     request.setParameter('FOOBAR', 'foobar')
     self.assertEqual(request.parameter('FOOBAR'), 'foobar')
     self.assertEqual(request.parameter('UNKNOWN'), '')