예제 #1
0
    def test_GetFeatureInfo_JSONP(self):
        from c2cgeoportal.views import mapserverproxy

        map = self._get_mapfile_path()
        request = self._create_dummy_request()
        request.params = dict(map=map,
                              service='wms',
                              version='1.1.1',
                              request='getfeatureinfo',
                              bbox='-90,-45,90,0',
                              layers='testpoint_unprotected',
                              query_layers='testpoint_unprotected',
                              srs='EPSG:21781',
                              format='image/png',
                              info_format='application/vnd.ogc.gml',
                              width='600',
                              height='400',
                              x='0',
                              y='400',
                              callback='cb')
        response = mapserverproxy.proxy(request)

        expected_response = """
        <?xmlversion="1.0"encoding="UTF-8"?>
        <msGMLOutput
         xmlns:gml="http://www.opengis.net/gml"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <testpoint_unprotected_layer>
        <gml:name>countries</gml:name>
                <testpoint_unprotected_feature>
                        <gml:boundedBy>
                                <gml:Box srsName="EPSG:21781">
                                        <gml:coordinates>-90.000000,-45.000000 -90.000000,-45.000000</gml:coordinates>
                                </gml:Box>
                        </gml:boundedBy>
                        <the_geom>
                        <gml:Point srsName="EPSG:21781">
                          <gml:coordinates>-90.000000,-45.000000</gml:coordinates>
                        </gml:Point>
                        </the_geom>
                        <name>foo</name>
                        <city>Lausanne</city>
                        <country>Swiss</country>
                </testpoint_unprotected_feature>
        </testpoint_unprotected_layer>
        </msGMLOutput>
        """
        import re
        pattern = re.compile(r'\s+')
        expected_response = ''.join(
            re.sub(pattern, '', l) for l in expected_response.splitlines())
        expected_response = '%s(\'%s\');' % ('cb', expected_response)
        response = ''.join(
            re.sub(pattern, '', l) for l in response.body.splitlines())
        self.assertEqual(response, expected_response)
예제 #2
0
    def test_GetMap_protected_layer_collect_query_user1(self):
        from c2cgeoportal.views import mapserverproxy

        map = self._get_mapfile_path()
        request = self._create_dummy_request(username=u'__test_user1')
        request.params = dict(map=map, service='wms', version='1.1.1', request='getmap',
                      bbox='-180,-90,180,90', layers='testpoint_protected_query_with_collect',
                      width='600', height='400', srs='EPSG:21781', format='image/png')
        response = mapserverproxy.proxy(request)

        md5sum = hashlib.md5(response.body).hexdigest()
        self.assertEquals(response.status_int, 200)
        assert md5sum == '0a4fac2209d06c6fa36048c125b1679a'
예제 #3
0
    def test_GetMap_protected_layer_user2(self):
        from c2cgeoportal.views import mapserverproxy

        map = self._get_mapfile_path()
        request = self._create_dummy_request(username=u'__test_user2')
        request.params = dict(map=map, service='wms', version='1.1.1', request='getmap',
                      bbox='-180,-90,180,90', layers='testpoint_protected',
                      width='600', height='400', srs='EPSG:21781', format='image/png')
        response = mapserverproxy.proxy(request)

        md5sum = hashlib.md5(response.body).hexdigest()
        # empty
        self.assertEquals(response.status_int, 200)
        assert md5sum == 'ef33223235b26c782736c88933b35331'
예제 #4
0
    def test_GetMap_unprotected_layer_user1(self):
        from c2cgeoportal.views import mapserverproxy

        map = self._get_mapfile_path()
        request = self._create_dummy_request(username=u'__test_user1')
        request.params = dict(map=map, service='wms', version='1.1.1', request='getmap',
                      bbox='-180,-90,180,90', layers='testpoint_unprotected',
                      width='600', height='400', srs='EPSG:21781', format='image/png')
        response = mapserverproxy.proxy(request)

        md5sum = hashlib.md5(response.body).hexdigest()
        # 4 points
        self.assertEquals(response.status_int, 200)
        assert md5sum == '61cbb0a6d18b72e4a28c1087019de245'
예제 #5
0
    def test_GetFeatureInfo_JSONP(self):
        from c2cgeoportal.views import mapserverproxy

        map = self._get_mapfile_path()
        request = self._create_dummy_request()
        request.params = dict(map=map, service='wms', version='1.1.1',
                      request='getfeatureinfo', bbox='-90,-45,90,0',
                      layers='testpoint_unprotected',
                      query_layers='testpoint_unprotected',
                      srs='EPSG:21781', format='image/png',
                      info_format='application/vnd.ogc.gml',
                      width='600', height='400', x='0', y='400',
                      callback='cb')
        response = mapserverproxy.proxy(request)

        expected_response = """
        <?xmlversion="1.0"encoding="UTF-8"?>
        <msGMLOutput
         xmlns:gml="http://www.opengis.net/gml"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <testpoint_unprotected_layer>
        <gml:name>countries</gml:name>
                <testpoint_unprotected_feature>
                        <gml:boundedBy>
                                <gml:Box srsName="EPSG:21781">
                                        <gml:coordinates>-90.000000,-45.000000 -90.000000,-45.000000</gml:coordinates>
                                </gml:Box>
                        </gml:boundedBy>
                        <the_geom>
                        <gml:Point srsName="EPSG:21781">
                          <gml:coordinates>-90.000000,-45.000000</gml:coordinates>
                        </gml:Point>
                        </the_geom>
                        <name>foo</name>
                        <city>Lausanne</city>
                        <country>Swiss</country>
                </testpoint_unprotected_feature>
        </testpoint_unprotected_layer>
        </msGMLOutput>
        """
        import re
        pattern = re.compile(r'\s+')
        expected_response = ''.join(re.sub(pattern, '', l) for l in
                                        expected_response.splitlines())
        expected_response = '%s(\'%s\');' % ('cb', expected_response)
        response = ''.join(re.sub(pattern, '', l) for l in
                                        response.body.splitlines())
        self.assertEqual(response, expected_response)
예제 #6
0
    def GetFeature_IsLike(self, value):
        from c2cgeoportal.views import mapserverproxy
        request = self._create_dummy_request()
        map = self._get_mapfile_path()
        request.params = dict(map=map)

        request.method = 'POST'
        request.body = (GETFEATURE_REQUEST % {
            'feature': u'testpoint_unprotected',
            'function': u'Like',
            'arguments': u'wildCard="*" singleChar="." escapeChar="!"',
            'property': u'name',
            'value': value,
        }).encode('utf-8')
        return mapserverproxy.proxy(request)
예제 #7
0
    def test_GetLegendGraphic(self):
        from c2cgeoportal.views import mapserverproxy

        map = self._get_mapfile_path()
        request = self._create_dummy_request()
        request.params = dict(map=map, service='wms', version='1.1.1',
                              request='getlegendgraphic',
                              layer='testpoint_unprotected',
                              srs='EPSG:21781',
                              format='image/png',
                              extraparam=u'with spéciàl chârs')
        response = mapserverproxy.proxy(request)
        self.assertTrue('Cache-Control' in response.headers)
        self.assertTrue(response.cache_control.public)
        self.assertEqual(response.cache_control.max_age, 1800)
예제 #8
0
    def GetFeature_IsLike(self, value):
        from c2cgeoportal.views import mapserverproxy
        request = self._create_dummy_request()
        map = self._get_mapfile_path()
        request.params = dict(map=map)

        request.method = 'POST'
        request.body = (GETFEATURE_REQUEST % {
            'feature': u'testpoint_unprotected',
            'function': u'Like',
            'arguments': u'wildCard="*" singleChar="." escapeChar="!"',
            'property': u'name',
            'value': value,
        }).encode('utf-8')
        return mapserverproxy.proxy(request)
예제 #9
0
    def test_GetLegendGraphic(self):
        from c2cgeoportal.views import mapserverproxy

        map = self._get_mapfile_path()
        request = self._create_dummy_request()
        request.params = dict(map=map,
                              service='wms',
                              version='1.1.1',
                              request='getlegendgraphic',
                              layer='testpoint_unprotected',
                              srs='EPSG:21781',
                              format='image/png',
                              extraparam=u'with spéciàl chârs')
        response = mapserverproxy.proxy(request)
        self.assertTrue('Cache-Control' in response.headers)
        self.assertTrue(response.cache_control.public)
        self.assertEqual(response.cache_control.max_age, 1800)
예제 #10
0
    def test_GetFeature_FeatureId_GET_JSONP(self):
        from c2cgeoportal.views import mapserverproxy

        map = self._get_mapfile_path()
        request = self._create_dummy_request()

        featureid = '%(typename)s.%(fid1)s,%(typename)s.%(fid2)s' % \
                    {'typename': 'testpoint_unprotected',
                     'fid1': self.id_lausanne,
                     'fid2': self.id_paris}
        request.params = dict(map=map, service='wfs', version='1.0.0',
                      request='getfeature', typename='testpoint_unprotected',
                      featureid=featureid, callback='cb')
        response = mapserverproxy.proxy(request)
        self.assertTrue('Lausanne' in response.body)
        self.assertTrue('Paris' in response.body)
        self.assertFalse('Londre' in response.body)
        self.assertFalse('Chambéry' in response.body)
        self.assertEqual(response.content_type, 'application/javascript')
예제 #11
0
    def test_GetMap_protected_layer_collect_query_user1(self):
        from c2cgeoportal.views import mapserverproxy

        map = self._get_mapfile_path()
        request = self._create_dummy_request(username=u'__test_user1')
        request.params = dict(map=map,
                              service='wms',
                              version='1.1.1',
                              request='getmap',
                              bbox='-180,-90,180,90',
                              layers='testpoint_protected_query_with_collect',
                              width='600',
                              height='400',
                              srs='EPSG:21781',
                              format='image/png')
        response = mapserverproxy.proxy(request)

        md5sum = hashlib.md5(response.body).hexdigest()
        self.assertEquals(response.status_int, 200)
        assert md5sum == '0a4fac2209d06c6fa36048c125b1679a'
예제 #12
0
    def test_GetMap_protected_layer_user2(self):
        from c2cgeoportal.views import mapserverproxy

        map = self._get_mapfile_path()
        request = self._create_dummy_request(username=u'__test_user2')
        request.params = dict(map=map,
                              service='wms',
                              version='1.1.1',
                              request='getmap',
                              bbox='-180,-90,180,90',
                              layers='testpoint_protected',
                              width='600',
                              height='400',
                              srs='EPSG:21781',
                              format='image/png')
        response = mapserverproxy.proxy(request)

        md5sum = hashlib.md5(response.body).hexdigest()
        # empty
        self.assertEquals(response.status_int, 200)
        assert md5sum == 'ef33223235b26c782736c88933b35331'
예제 #13
0
    def test_GetMap_unprotected_layer_user1(self):
        from c2cgeoportal.views import mapserverproxy

        map = self._get_mapfile_path()
        request = self._create_dummy_request(username=u'__test_user1')
        request.params = dict(map=map,
                              service='wms',
                              version='1.1.1',
                              request='getmap',
                              bbox='-180,-90,180,90',
                              layers='testpoint_unprotected',
                              width='600',
                              height='400',
                              srs='EPSG:21781',
                              format='image/png')
        response = mapserverproxy.proxy(request)

        md5sum = hashlib.md5(response.body).hexdigest()
        # 4 points
        self.assertEquals(response.status_int, 200)
        assert md5sum == '61cbb0a6d18b72e4a28c1087019de245'
예제 #14
0
    def test_GetFeature_FeatureId_GET(self):
        from c2cgeoportal.views import mapserverproxy

        map = self._get_mapfile_path()
        request = self._create_dummy_request()

        featureid = '%(typename)s.%(fid1)s,%(typename)s.%(fid2)s' % \
                    {'typename': 'testpoint_unprotected',
                     'fid1': self.id_lausanne,
                     'fid2': self.id_paris}
        request.params = dict(map=map,
                              service='wfs',
                              version='1.0.0',
                              request='getfeature',
                              typename='testpoint_unprotected',
                              featureid=featureid)
        response = mapserverproxy.proxy(request)
        self.assertTrue('Lausanne' in response.body)
        self.assertTrue('Paris' in response.body)
        self.assertFalse('Londre' in response.body)
        self.assertFalse('Chambéry' in response.body)
        self.assertEqual(response.content_type, 'text/xml')
예제 #15
0
    def test_substitution(self):
        from c2cgeoportal.views import mapserverproxy
        request = self._create_dummy_request()
        map = self._get_mapfile_path()
        request.method = 'POST'
        request.body = SUBSTITUTION_GETFEATURE_REQUEST

        request.params = dict(map=map)
        response = mapserverproxy.proxy(request)
        self.assertEquals(response.status_int, 200)
        assert unicode(response.body.decode('utf-8')).find(u'foo') > 0
        assert unicode(response.body.decode('utf-8')).find(u'bar') < 0
        assert unicode(response.body.decode('utf-8')).find(u'éàè') < 0
        assert unicode(response.body.decode('utf-8')).find(u'123') < 0

        request.params = dict(map=map, s_name='bar')
        response = mapserverproxy.proxy(request)
        self.assertEquals(response.status_int, 200)
        assert unicode(response.body.decode('utf-8')).find(u'foo') > 0
        assert unicode(response.body.decode('utf-8')).find(u'bar') < 0
        assert unicode(response.body.decode('utf-8')).find(u'éàè') < 0
        assert unicode(response.body.decode('utf-8')).find(u'123') < 0

        request.params = dict(map=map, S_NAME='bar')
        response = mapserverproxy.proxy(request)
        self.assertEquals(response.status_int, 200)
        assert unicode(response.body.decode('utf-8')).find(u'foo') > 0
        assert unicode(response.body.decode('utf-8')).find(u'bar') < 0
        assert unicode(response.body.decode('utf-8')).find(u'éàè') < 0
        assert unicode(response.body.decode('utf-8')).find(u'123') < 0

        request.registry.settings['functionalities']['anonymous'] = \
                {"mapserver_substitution":["name=bar"]}
        request.params = dict(map=map)
        response = mapserverproxy.proxy(request)
        self.assertEquals(response.status_int, 200)
        assert unicode(response.body.decode('utf-8')).find(u'foo') < 0
        assert unicode(response.body.decode('utf-8')).find(u'bar') > 0
        assert unicode(response.body.decode('utf-8')).find(u'éàè') < 0
        assert unicode(response.body.decode('utf-8')).find(u'123') < 0

        request.body = COLUMN_RESTRICTION_GETFEATURE_REQUEST
        request.registry.settings['functionalities']['anonymous'] = \
                {"mapserver_substitution":["cols=name","cols=city","cols=country"]}
        response = mapserverproxy.proxy(request)
        self.assertEquals(response.status_int, 200)
        assert unicode(response.body.decode('utf-8')).find(u'Lausanne') > 0
        assert unicode(response.body.decode('utf-8')).find(u'Swiss') > 0

        request.registry.settings['functionalities']['anonymous'] = \
                {"mapserver_substitution":["cols=name","cols=city"]}
        response = mapserverproxy.proxy(request)
        self.assertEquals(response.status_int, 200)
        assert unicode(response.body.decode('utf-8')).find(u'Lausanne') > 0
        assert unicode(response.body.decode('utf-8')).find(u'Swiss') < 0

        request.registry.settings['functionalities']['anonymous'] = \
                {"mapserver_substitution":["cols=name","cols=country"]}
        response = mapserverproxy.proxy(request)
        self.assertEquals(response.status_int, 200)
        assert unicode(response.body.decode('utf-8')).find(u'Lausanne') < 0
        assert unicode(response.body.decode('utf-8')).find(u'Swiss') > 0

        request.registry.settings['functionalities']['anonymous'] = \
                {"mapserver_substitution":["cols=name"]}
        response = mapserverproxy.proxy(request)
        self.assertEquals(response.status_int, 200)
        assert unicode(response.body.decode('utf-8')).find(u'Lausanne') < 0
        assert unicode(response.body.decode('utf-8')).find(u'Swiss') < 0

        request = self._create_dummy_request()
        request.method = 'POST'
        request.body = SUBSTITUTION_GETFEATURE_REQUEST
        request.registry.settings['functionalities']['anonymous'] = \
                {"mapserver_substitution":["foo_bar"]}
        request.params = dict(map=map,
                      s_test1='to be removed', S_TEST2='to be removed')
        # just pass in the log messagse
        response = mapserverproxy.proxy(request)
예제 #16
0
    def test_substitution(self):
        from c2cgeoportal.views import mapserverproxy
        request = self._create_dummy_request()
        map = self._get_mapfile_path()
        request.method = 'POST'
        request.body = SUBSTITUTION_GETFEATURE_REQUEST

        request.params = dict(map=map)
        response = mapserverproxy.proxy(request)
        self.assertEquals(response.status_int, 200)
        assert unicode(response.body.decode('utf-8')).find(u'foo') > 0
        assert unicode(response.body.decode('utf-8')).find(u'bar') < 0
        assert unicode(response.body.decode('utf-8')).find(u'éàè') < 0
        assert unicode(response.body.decode('utf-8')).find(u'123') < 0

        request.params = dict(map=map, s_name='bar')
        response = mapserverproxy.proxy(request)
        self.assertEquals(response.status_int, 200)
        assert unicode(response.body.decode('utf-8')).find(u'foo') > 0
        assert unicode(response.body.decode('utf-8')).find(u'bar') < 0
        assert unicode(response.body.decode('utf-8')).find(u'éàè') < 0
        assert unicode(response.body.decode('utf-8')).find(u'123') < 0

        request.params = dict(map=map, S_NAME='bar')
        response = mapserverproxy.proxy(request)
        self.assertEquals(response.status_int, 200)
        assert unicode(response.body.decode('utf-8')).find(u'foo') > 0
        assert unicode(response.body.decode('utf-8')).find(u'bar') < 0
        assert unicode(response.body.decode('utf-8')).find(u'éàè') < 0
        assert unicode(response.body.decode('utf-8')).find(u'123') < 0

        request.registry.settings['functionalities']['anonymous'] = \
                {"mapserver_substitution":["name=bar"]}
        request.params = dict(map=map)
        response = mapserverproxy.proxy(request)
        self.assertEquals(response.status_int, 200)
        assert unicode(response.body.decode('utf-8')).find(u'foo') < 0
        assert unicode(response.body.decode('utf-8')).find(u'bar') > 0
        assert unicode(response.body.decode('utf-8')).find(u'éàè') < 0
        assert unicode(response.body.decode('utf-8')).find(u'123') < 0

        request.body = COLUMN_RESTRICTION_GETFEATURE_REQUEST
        request.registry.settings['functionalities']['anonymous'] = \
                {"mapserver_substitution":["cols=name","cols=city","cols=country"]}
        response = mapserverproxy.proxy(request)
        self.assertEquals(response.status_int, 200)
        assert unicode(response.body.decode('utf-8')).find(u'Lausanne') > 0
        assert unicode(response.body.decode('utf-8')).find(u'Swiss') > 0

        request.registry.settings['functionalities']['anonymous'] = \
                {"mapserver_substitution":["cols=name","cols=city"]}
        response = mapserverproxy.proxy(request)
        self.assertEquals(response.status_int, 200)
        assert unicode(response.body.decode('utf-8')).find(u'Lausanne') > 0
        assert unicode(response.body.decode('utf-8')).find(u'Swiss') < 0

        request.registry.settings['functionalities']['anonymous'] = \
                {"mapserver_substitution":["cols=name","cols=country"]}
        response = mapserverproxy.proxy(request)
        self.assertEquals(response.status_int, 200)
        assert unicode(response.body.decode('utf-8')).find(u'Lausanne') < 0
        assert unicode(response.body.decode('utf-8')).find(u'Swiss') > 0

        request.registry.settings['functionalities']['anonymous'] = \
                {"mapserver_substitution":["cols=name"]}
        response = mapserverproxy.proxy(request)
        self.assertEquals(response.status_int, 200)
        assert unicode(response.body.decode('utf-8')).find(u'Lausanne') < 0
        assert unicode(response.body.decode('utf-8')).find(u'Swiss') < 0

        request = self._create_dummy_request()
        request.method = 'POST'
        request.body = SUBSTITUTION_GETFEATURE_REQUEST
        request.registry.settings['functionalities']['anonymous'] = \
                {"mapserver_substitution":["foo_bar"]}
        request.params = dict(map=map,
                              s_test1='to be removed',
                              S_TEST2='to be removed')
        # just pass in the log messagse
        response = mapserverproxy.proxy(request)