示例#1
0
    def setup(self):
        self.layers = {}

        self.layers['layer1'] = DummyTileLayer('layer1')
        self.layers['layer2'] = DummyTileLayer('layer2')
        self.layers['layer3'] = DummyTileLayer('layer3')
        self.server = TileServer(self.layers, {})
示例#2
0
 def setup(self):
     self.layers = {}
     
     self.layers['layer1'] = DummyTileLayer('layer1')
     self.layers['layer2'] = DummyTileLayer('layer2')
     self.layers['layer3'] = DummyTileLayer('layer3')
     self.server = TileServer(self.layers, {})
示例#3
0
 def setup(self):
     # Base server
     self.server = Server()
     # WMS Server
     root_layer = WMSGroupLayer(None, 'root layer', None, [DummyLayer('wms_cache')])
     self.wms_server = WMSServer(
         md={}, root_layer=root_layer, srs=['EPSG:4326'],
         image_formats={'image/png': ImageOptions(format='image/png')}
     )
     # Tile Servers
     layers = odict()
     layers["wms_cache_EPSG900913"] = DummyTileLayer('wms_cache')
     self.tile_server = TileServer(layers, {})
     self.wmts_server = WMTSServer(layers, {})
     # Common arguments
     self.query_extent = ('EPSG:27700', (0, 0, 700000, 1300000))
示例#4
0
 def setup(self):
     # Base server
     self.server = Server()
     # WMS Server
     root_layer = WMSGroupLayer(None, 'root layer', None, [DummyLayer('wms_cache')])
     self.wms_server = WMSServer(
         md={}, root_layer=root_layer, srs=['EPSG:4326'],
         image_formats={'image/png': ImageOptions(format='image/png')}
     )
     # Tile Servers
     layers = odict()
     layers["wms_cache_EPSG900913"] = DummyTileLayer('wms_cache')
     self.tile_server = TileServer(layers, {})
     self.wmts_server = WMTSServer(layers, {})
     # Common arguments
     self.query_extent = ('EPSG:27700', (0, 0, 700000, 1300000))
示例#5
0
class TestTMSAuth(object):
    service = 'tms'
    def setup(self):
        self.layers = {}
        
        self.layers['layer1'] = DummyTileLayer('layer1')
        self.layers['layer2'] = DummyTileLayer('layer2')
        self.layers['layer3'] = DummyTileLayer('layer3')
        self.server = TileServer(self.layers, {})
    
    def tile_request(self, tile, auth):
        env = make_wsgi_env('', extra_environ={'mapproxy.authorize': auth,
                                               'PATH_INFO': '/tms/1.0.0/'+tile})
        req = Request(env)
        return tile_request(req)
    
    @raises(RequestError)
    def test_deny_all(self):
        def auth(service, layers, **kw):
            eq_(service, self.service)
            eq_(layers, 'layer1'.split())
            return {
                'authorized': 'none',
            }
        self.server.map(self.tile_request('layer1/0/0/0.png', auth))

    @raises(RequestError)
    def test_deny_layer(self):
        def auth(service, layers, **kw):
            eq_(service, self.service)
            eq_(layers, 'layer1'.split())
            return {
                'authorized': 'partial',
                'layers': {
                    'layer1': {'tile': False},
                    'layer2': {'tile': True},
                }
            }
        self.server.map(self.tile_request('layer1/0/0/0.png', auth))

    def test_allow_all(self):
        def auth(service, layers, **kw):
            eq_(service, self.service)
            eq_(layers, 'layer1'.split())
            return {
                'authorized': 'full',
            }
        self.server.map(self.tile_request('layer1/0/0/0.png', auth))
        assert self.layers['layer1'].requested
    
    def test_allow_layer(self):
        def auth(service, layers, **kw):
            eq_(service, self.service)
            eq_(layers, 'layer1'.split())
            return {
                'authorized': 'partial',
                'layers': {
                    'layer1': {'tile': True},
                    'layer2': {'tile': False},
                }
            }
        self.server.map(self.tile_request('layer1/0/0/0.png', auth))
        assert self.layers['layer1'].requested
示例#6
0
class TestDecorateImg(object):
    def setup(self):
        # Base server
        self.server = Server()
        # WMS Server
        root_layer = WMSGroupLayer(None, 'root layer', None,
                                   [DummyLayer('wms_cache')])
        self.wms_server = WMSServer(
            md={},
            root_layer=root_layer,
            srs=['EPSG:4326'],
            image_formats={'image/png': ImageOptions(format='image/png')})
        # Tile Servers
        layers = odict()
        layers["wms_cache_EPSG900913"] = DummyTileLayer('wms_cache')
        self.tile_server = TileServer(layers, {})
        self.wmts_server = WMTSServer(layers, {})
        # Common arguments
        self.query_extent = ('EPSG:27700', (0, 0, 700000, 1300000))

    def test_original_imagesource_returned_when_no_callback(self):
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        env = make_wsgi_env('', extra_environ={})
        img_src2 = self.server.decorate_img(img_src1, 'wms.map', ['layer1'],
                                            env, self.query_extent)
        assert img_src1 == img_src2

    def test_returns_imagesource(self):
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        env = make_wsgi_env('', extra_environ={})
        img_src2 = self.server.decorate_img(img_src1, 'wms.map', ['layer1'],
                                            env, self.query_extent)
        assert isinstance(img_src2, ImageSource)

    def set_called_callback(self, img_src, service, layers, **kw):
        self.called = True
        return img_src

    def test_calls_callback(self):
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        self.called = False
        env = make_wsgi_env(
            '',
            extra_environ={'mapproxy.decorate_img': self.set_called_callback})
        img_src2 = self.server.decorate_img(img_src1, 'wms.map', ['layer1'],
                                            env, self.query_extent)
        assert self.called == True

    def return_new_imagesource_callback(self, img_src, service, layers, **kw):
        new_img_src = ImageSource(Image.new('RGBA', (100, 100)))
        self.new_img_src = new_img_src
        return new_img_src

    def test_returns_callbacks_return_value(self):
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        env = make_wsgi_env('',
                            extra_environ={
                                'mapproxy.decorate_img':
                                self.return_new_imagesource_callback
                            })
        self.new_img_src = None
        img_src2 = self.server.decorate_img(img_src1, 'wms.map', ['layer1'],
                                            env, self.query_extent)
        assert img_src2 == self.new_img_src

    def test_wms_server(self):
        ''' Test that the decorate_img method is available on a WMSServer instance '''
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        self.called = False
        env = make_wsgi_env(
            '',
            extra_environ={'mapproxy.decorate_img': self.set_called_callback})
        img_src2 = self.wms_server.decorate_img(img_src1, 'wms.map',
                                                ['layer1'], env,
                                                self.query_extent)
        assert self.called == True

    def test_tile_server(self):
        ''' Test that the decorate_img method is available on a TileServer instance '''
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        self.called = False
        env = make_wsgi_env(
            '',
            extra_environ={'mapproxy.decorate_img': self.set_called_callback})
        img_src2 = self.tile_server.decorate_img(img_src1, 'tms', ['layer1'],
                                                 env, self.query_extent)
        assert self.called == True

    def test_wmts_server(self):
        ''' Test that the decorate_img method is available on a WMTSServer instance '''
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        self.called = False
        env = make_wsgi_env(
            '',
            extra_environ={'mapproxy.decorate_img': self.set_called_callback})
        img_src2 = self.wmts_server.decorate_img(img_src1, 'wmts', ['layer1'],
                                                 env, self.query_extent)
        assert self.called == True

    def test_args(self):
        def callback(img_src, service, layers, environ, query_extent, **kw):
            assert isinstance(img_src, ImageSource)
            assert 'wms.map' == service
            assert isinstance(layers, list)
            assert isinstance(environ, dict)
            assert len(query_extent) == 2
            assert len(query_extent[1]) == 4
            return img_src

        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        env = make_wsgi_env('',
                            extra_environ={'mapproxy.decorate_img': callback})
        img_src2 = self.tile_server.decorate_img(img_src1, 'wms.map',
                                                 ['layer1'], env,
                                                 self.query_extent)
示例#7
0
class TestTMSAuth(object):
    service = 'tms'

    def setup(self):
        self.layers = {}

        self.layers['layer1'] = DummyTileLayer('layer1')
        self.layers['layer2'] = DummyTileLayer('layer2')
        self.layers['layer3'] = DummyTileLayer('layer3')
        self.server = TileServer(self.layers, {})

    def tile_request(self, tile, auth):
        env = make_wsgi_env('',
                            extra_environ={
                                'mapproxy.authorize': auth,
                                'PATH_INFO': '/tms/1.0.0/' + tile
                            })
        req = Request(env)
        return tile_request(req)

    @raises(RequestError)
    def test_deny_all(self):
        def auth(service, layers, **kw):
            eq_(service, self.service)
            eq_(layers, 'layer1'.split())
            return {
                'authorized': 'none',
            }

        self.server.map(self.tile_request('layer1/0/0/0.png', auth))

    @raises(RequestError)
    def test_deny_layer(self):
        def auth(service, layers, **kw):
            eq_(service, self.service)
            eq_(layers, 'layer1'.split())
            return {
                'authorized': 'partial',
                'layers': {
                    'layer1': {
                        'tile': False
                    },
                    'layer2': {
                        'tile': True
                    },
                }
            }

        self.server.map(self.tile_request('layer1/0/0/0.png', auth))

    def test_allow_all(self):
        def auth(service, layers, **kw):
            eq_(service, self.service)
            eq_(layers, 'layer1'.split())
            return {
                'authorized': 'full',
            }

        self.server.map(self.tile_request('layer1/0/0/0.png', auth))
        assert self.layers['layer1'].requested

    def test_allow_layer(self):
        def auth(service, layers, **kw):
            eq_(service, self.service)
            eq_(layers, 'layer1'.split())
            return {
                'authorized': 'partial',
                'layers': {
                    'layer1': {
                        'tile': True
                    },
                    'layer2': {
                        'tile': False
                    },
                }
            }

        self.server.map(self.tile_request('layer1/0/0/0.png', auth))
        assert self.layers['layer1'].requested
示例#8
0
class TestDecorateImg(object):

    def setup(self):
        # Base server
        self.server = Server()
        # WMS Server
        root_layer = WMSGroupLayer(None, 'root layer', None, [DummyLayer('wms_cache')])
        self.wms_server = WMSServer(
            md={}, root_layer=root_layer, srs=['EPSG:4326'],
            image_formats={'image/png': ImageOptions(format='image/png')}
        )
        # Tile Servers
        layers = odict()
        layers["wms_cache_EPSG900913"] = DummyTileLayer('wms_cache')
        self.tile_server = TileServer(layers, {})
        self.wmts_server = WMTSServer(layers, {})
        # Common arguments
        self.query_extent = ('EPSG:27700', (0, 0, 700000, 1300000))

    def test_original_imagesource_returned_when_no_callback(self):
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        env = make_wsgi_env('', extra_environ={})
        img_src2 = self.server.decorate_img(
            img_src1, 'wms.map', ['layer1'],
            env, self.query_extent
        )
        eq_(img_src1, img_src2)

    def test_returns_imagesource(self):
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        env = make_wsgi_env('', extra_environ={})
        img_src2 = self.server.decorate_img(
            img_src1, 'wms.map', ['layer1'],
            env, self.query_extent
        )
        assert isinstance(img_src2, ImageSource)

    def set_called_callback(self, img_src, service, layers, **kw):
        self.called = True
        return img_src

    def test_calls_callback(self):
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        self.called = False
        env = make_wsgi_env('', extra_environ={'mapproxy.decorate_img': self.set_called_callback})
        img_src2 = self.server.decorate_img(
            img_src1, 'wms.map', ['layer1'],
            env, self.query_extent
        )
        eq_(self.called, True)

    def return_new_imagesource_callback(self, img_src, service, layers, **kw):
        new_img_src = ImageSource(Image.new('RGBA', (100, 100)))
        self.new_img_src = new_img_src
        return new_img_src

    def test_returns_callbacks_return_value(self):
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        env = make_wsgi_env('', extra_environ={'mapproxy.decorate_img': self.return_new_imagesource_callback})
        self.new_img_src = None
        img_src2 = self.server.decorate_img(
            img_src1, 'wms.map', ['layer1'],
            env, self.query_extent
        )
        eq_(img_src2, self.new_img_src)

    def test_wms_server(self):
        ''' Test that the decorate_img method is available on a WMSServer instance '''
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        self.called = False
        env = make_wsgi_env('', extra_environ={'mapproxy.decorate_img': self.set_called_callback})
        img_src2 = self.wms_server.decorate_img(
            img_src1, 'wms.map', ['layer1'],
            env, self.query_extent
        )
        eq_(self.called, True)

    def test_tile_server(self):
        ''' Test that the decorate_img method is available on a TileServer instance '''
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        self.called = False
        env = make_wsgi_env('', extra_environ={'mapproxy.decorate_img': self.set_called_callback})
        img_src2 = self.tile_server.decorate_img(
            img_src1, 'tms', ['layer1'],
            env, self.query_extent
        )
        eq_(self.called, True)

    def test_wmts_server(self):
        ''' Test that the decorate_img method is available on a WMTSServer instance '''
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        self.called = False
        env = make_wsgi_env('', extra_environ={'mapproxy.decorate_img': self.set_called_callback})
        img_src2 = self.wmts_server.decorate_img(
            img_src1, 'wmts', ['layer1'],
            env, self.query_extent
        )
        eq_(self.called, True)

    def test_args(self):
        def callback(img_src, service, layers, environ, query_extent, **kw):
            assert isinstance(img_src, ImageSource)
            eq_('wms.map', service)
            assert isinstance(layers, list)
            assert isinstance(environ, dict)
            assert len(query_extent) == 2
            assert len(query_extent[1]) == 4
            return img_src
        img_src1 = ImageSource(Image.new('RGBA', (100, 100)))
        env = make_wsgi_env('', extra_environ={'mapproxy.decorate_img': callback})
        img_src2 = self.tile_server.decorate_img(
            img_src1, 'wms.map', ['layer1'],
            env, self.query_extent
        )