예제 #1
0
 def _test_url(original_url, rewritten_url, env={}):
     self._set_env(env)
     request = QgsFcgiServerRequest()
     self.assertEqual(request.originalUrl().toString(), original_url)
     self.assertEqual(request.url().toString(), rewritten_url)
     # Check MAP
     if 'QUERY_STRING' in env:
         map = {k.upper(): v[0] for k, v in parse_qs(
             env['QUERY_STRING']).items()}['MAP']
     else:
         map = {k.upper(): v[0] for k, v in parse_qs(
             urlparse(env['REQUEST_URI']).query).items()}['MAP']
     self.assertEqual(request.parameter('MAP'), map)
예제 #2
0
 def _test_url(original_url, rewritten_url, env={}):
     self._set_env(env)
     request = QgsFcgiServerRequest()
     self.assertEqual(request.originalUrl().toString(), original_url)
     self.assertEqual(request.url().toString(), rewritten_url)
     # Check MAP
     if 'QUERY_STRING' in env:
         map = {k.upper(): v[0] for k, v in parse_qs(
             env['QUERY_STRING']).items()}['MAP']
     else:
         map = {k.upper(): v[0] for k, v in parse_qs(
             urlparse(env['REQUEST_URI']).query).items()}['MAP']
     self.assertEqual(request.parameter('MAP'), map)
예제 #3
0
        def _check_links(params, method='GET'):
            data = urlencode(params)
            if method == 'GET':
                env = {
                    'SERVER_NAME': 'www.myserver.com',
                    'REQUEST_URI': '/aproject/',
                    'QUERY_STRING': data,
                    'REQUEST_METHOD': 'GET',
                }
            else:
                env = {
                    'SERVER_NAME': 'www.myserver.com',
                    'REQUEST_URI': '/aproject/',
                    'REQUEST_BODY': data,
                    'CONTENT_LENGTH': str(len(data)),
                    'REQUEST_METHOD': 'POST',
                }

            self._set_env(env)
            request = QgsFcgiServerRequest()
            response = QgsBufferServerResponse()
            self.server.handleRequest(request, response)
            self.assertFalse(b'ServiceExceptionReport' in response.body())

            if method == 'POST':
                self.assertEqual(request.data(), data.encode('utf8'))
            else:
                original_url = request.originalUrl().toString()
                self.assertTrue(
                    original_url.startswith(
                        'http://www.myserver.com/aproject/'))
                self.assertEqual(
                    original_url.find(urlencode({'MAP': params['map']})), -1)

            exp = re.compile(r'href="([^"]+)"', re.DOTALL | re.MULTILINE)
            elems = exp.findall(bytes(response.body()).decode('utf8'))
            self.assertTrue(len(elems) > 0)
            for href in elems:
                self.assertTrue(
                    href.startswith('http://www.myserver.com/aproject/'))
                self.assertEqual(href.find(urlencode({'MAP': params['map']})),
                                 -1)
예제 #4
0
        def _check_links(params, method='GET'):
            data = urlencode(params)
            if method == 'GET':
                env = {
                    'SERVER_NAME': 'www.myserver.com',
                    'REQUEST_URI': '/aproject/',
                    'QUERY_STRING': data,
                    'REQUEST_METHOD': 'GET',
                }
            else:
                env = {
                    'SERVER_NAME': 'www.myserver.com',
                    'REQUEST_URI': '/aproject/',
                    'REQUEST_BODY': data,
                    'CONTENT_LENGTH': str(len(data)),
                    'REQUEST_METHOD': 'POST',
                }

            self._set_env(env)
            request = QgsFcgiServerRequest()
            response = QgsBufferServerResponse()
            self.server.handleRequest(request, response)
            self.assertFalse(b'ServiceExceptionReport' in response.body())

            if method == 'POST':
                self.assertEqual(request.data(), data.encode('utf8'))
            else:
                original_url = request.originalUrl().toString()
                self.assertTrue(original_url.startswith('http://www.myserver.com/aproject/'))
                self.assertEqual(original_url.find(urlencode({'MAP': params['map']})), -1)

            exp = re.compile(r'href="([^"]+)"', re.DOTALL | re.MULTILINE)
            elems = exp.findall(bytes(response.body()).decode('utf8'))
            self.assertTrue(len(elems) > 0)
            for href in elems:
                self.assertTrue(href.startswith('http://www.myserver.com/aproject/'))
                self.assertEqual(href.find(urlencode({'MAP': params['map']})), -1)