Beispiel #1
0
    def test_post_urlencoded_action(self):
        """Test form www urlencoded"""
        def _req_logger(self, params):
            self.body = bytes(params.content())

        QgsNetworkAccessManager.instance(
        ).requestAboutToBeCreated[QgsNetworkRequestParameters].connect(
            partial(_req_logger, self))

        temp_dir = QTemporaryDir()
        temp_path = temp_dir.path()
        temp_file = os.path.join(temp_path, 'urlencoded.txt')

        action = QgsAction(
            QgsAction.SubmitUrlEncoded, 'url_encoded',
            "http://fake_qgis_http_endpoint" + temp_file +
            r"?[% url_encode(map('a&+b', 'a and plus b', 'a=b', 'a equals b')) %]"
        )
        ctx = QgsExpressionContext()
        action.run(ctx)

        while not self.body:
            QgsApplication.instance().processEvents()

        self.assertEqual(self.body,
                         br"a%26%2Bb=a%20and%20plus%20b&a%3Db=a%20equals%20b")
Beispiel #2
0
    def test_post_multipart_action(self):
        """Test multipart"""

        self.body = None

        def _req_logger(self, params):
            self.body = bytes(params.content())

        QgsNetworkAccessManager.instance(
        ).requestAboutToBeCreated[QgsNetworkRequestParameters].connect(
            partial(_req_logger, self))

        temp_dir = QTemporaryDir()
        temp_path = temp_dir.path()
        temp_file = os.path.join(temp_path, 'multipart.txt')

        action = QgsAction(
            QgsAction.SubmitUrlMultipart, 'url_encoded',
            "http://fake_qgis_http_endpoint" + temp_file +
            r"?[% url_encode(map('a&+b', 'a and plus b', 'a=b', 'a equals b')) %]"
        )
        ctx = QgsExpressionContext()
        action.run(ctx)

        while not self.body:
            QgsApplication.instance().processEvents()

        self.assertEqual(
            re.sub(r'\.oOo\.[^\r]*', '.oOo.UUID', self.body.decode('utf8')),
            '\r\n'.join([
                '--boundary_.oOo.UUID',
                'Content-Disposition: form-data; name="a&+b"', '',
                'a and plus b', '--boundary_.oOo.UUID',
                'Content-Disposition: form-data; name="a=b"', '', 'a equals b',
                '--boundary_.oOo.UUID', ''
            ]))