Пример #1
0
    def test_get_tile_limited_to_inside(self):
        def auth(service, layers, environ, **kw):
            eq_(environ['PATH_INFO'], '/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg')
            eq_(service, 'wmts')
            eq_(len(layers), 1)
            return {
                'authorized': 'partial',
                'limited_to': {
                    'geometry': [-180, -89, 180, 89],
                    'srs': 'EPSG:4326',
                },
                'layers': {
                    'layer3': {'tile': True},
                }
            }

        serv = MockServ(port=42423)
        serv.expects('/1/0/1.png')
        serv.returns(create_tmp_image((256, 256), color=(255, 0, 0)), headers={'content-type': 'image/png'})
        with serv:
            resp = self.app.get('/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg', extra_environ={'mapproxy.authorize': auth})

        eq_(resp.content_type, 'image/jpeg')

        img = img_from_buf(resp.body)
        eq_(img.getcolors()[0], (256*256, (255, 0, 0)))
Пример #2
0
    def test_get_map_uncached(self):
        mbtiles_file = os.path.join(test_config['base_dir'], 'cache.mbtiles')
        tiles_lock_dir = os.path.join(test_config['base_dir'], 'testlockdir')

        assert os.path.exists(mbtiles_file) # already created on startup
        assert not os.path.exists(tiles_lock_dir)

        self.common_map_req.params.bbox = '-180,0,0,80'
        serv = MockServ(port=42423)
        serv.expects('/tiles/01/000/000/000/000/000/001.png')
        serv.returns(create_tmp_image((256, 256)))
        with serv:
            resp = self.app.get(self.common_map_req)
            eq_(resp.content_type, 'image/png')
            data = StringIO(resp.body)
            assert is_png(data)

        # now cached
        resp = self.app.get(self.common_map_req)
        eq_(resp.content_type, 'image/png')
        data = StringIO(resp.body)
        assert is_png(data)

        # custom tile_lock_dir created
        assert os.path.exists(tiles_lock_dir)
Пример #3
0
    def test_get_tile_limited_to(self):
        def auth(service, layers, environ, query_extent, **kw):
            eq_(environ['PATH_INFO'], '/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg')
            eq_(service, 'wmts')
            eq_(len(layers), 1)
            eq_(query_extent[0], 'EPSG:900913')
            assert bbox_equals(query_extent[1], (-20037508.342789244, 0, 0, 20037508.342789244))
            return {
                'authorized': 'partial',
                'limited_to': {
                    'geometry': [-180, -89, -90, 89],
                    'srs': 'EPSG:4326',
                },
                'layers': {
                    'layer3': {'tile': True},
                }
            }

        serv = MockServ(port=42423)
        serv.expects('/1/0/1.png')
        serv.returns(create_tmp_image((256, 256), color=(255, 0, 0)), headers={'content-type': 'image/png'})
        with serv:
            resp = self.app.get('/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg', extra_environ={'mapproxy.authorize': auth})

        eq_(resp.content_type, 'image/png')

        img = img_from_buf(resp.body)
        img = img.convert('RGBA')
        # left part authorized, red
        eq_(img.crop((0, 0, 127, 255)).getcolors()[0], (127*255, (255, 0, 0, 255)))
        # right part not authorized, transparent
        eq_(img.crop((129, 0, 255, 255)).getcolors()[0][1][3], 0)
Пример #4
0
    def test_get_featureinfo_limited_to_inside(self):
        def auth(service, layers, query_extent, **kw):
            eq_(query_extent, ('EPSG:4326', (-80.0, -40.0, 0.0, 0.0)))
            eq_(service, 'wms.featureinfo')
            eq_(len(layers), 1)
            return {
                'authorized': 'partial',
                'layers': {
                    'layer1b': {
                        'featureinfo': True,
                        'limited_to': {
                            'srs': 'EPSG:4326',
                            'geometry': [-80.0, -40.0, 0.0, 0.0]
                        }
                    },
                }
            }

        serv = MockServ(port=42423)
        serv.expects(
            '/service?request=GetFeatureInfo&service=WMS&Version=1.1.1&SRS=EPSG:4326'
            '&BBOX=-80.0,-40.0,0.0,0.0&WIDTH=200&HEIGHT=100&styles=&FORMAT=image/png&X=10&Y=10'
            '&query_layers=fi&layers=fi')
        serv.returns(b'infoinfo')
        with serv:
            resp = self.app.get(FI_REQ + 'query_layers=layer1b&layers=layer1b',
                                extra_environ={'mapproxy.authorize': auth})
            eq_(resp.body, b'infoinfo')
Пример #5
0
    def check_get_tile_limited_to(self, auth_dict):
        def auth(service, layers, environ, query_extent, **kw):
            eq_(environ['PATH_INFO'],
                '/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg')
            eq_(service, 'wmts')
            eq_(len(layers), 1)
            eq_(query_extent[0], 'EPSG:900913')
            assert bbox_equals(query_extent[1],
                               (-20037508.342789244, 0, 0, 20037508.342789244))
            return auth_dict

        serv = MockServ(port=42423)
        serv.expects('/1/0/1.png')
        serv.returns(create_tmp_image((256, 256), color=(255, 0, 0)),
                     headers={'content-type': 'image/png'})
        with serv:
            resp = self.app.get('/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg',
                                extra_environ={'mapproxy.authorize': auth})

        eq_(resp.content_type, 'image/png')

        img = img_from_buf(resp.body)
        img = img.convert('RGBA')
        # left part authorized, red
        eq_(
            img.crop((0, 0, 127, 255)).getcolors()[0],
            (127 * 255, (255, 0, 0, 255)))
        # right part not authorized, transparent
        eq_(img.crop((129, 0, 255, 255)).getcolors()[0][1][3], 0)
Пример #6
0
    def test_get_map_uncached(self):
        mbtiles_file = os.path.join(test_config['base_dir'], 'cache.mbtiles')
        tiles_lock_dir = os.path.join(test_config['base_dir'], 'testlockdir')

        assert os.path.exists(mbtiles_file)  # already created on startup
        assert not os.path.exists(tiles_lock_dir)

        self.common_map_req.params.bbox = '-180,0,0,80'
        serv = MockServ(port=42423)
        serv.expects('/tiles/01/000/000/000/000/000/001.png')
        serv.returns(create_tmp_image((256, 256)))
        with serv:
            resp = self.app.get(self.common_map_req)
            eq_(resp.content_type, 'image/png')
            data = StringIO(resp.body)
            assert is_png(data)

        # now cached
        resp = self.app.get(self.common_map_req)
        eq_(resp.content_type, 'image/png')
        data = StringIO(resp.body)
        assert is_png(data)

        # custom tile_lock_dir created
        assert os.path.exists(tiles_lock_dir)
Пример #7
0
    def test_get_tile_limited_to_inside(self):
        def auth(service, layers, environ, **kw):
            eq_(environ['PATH_INFO'],
                '/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg')
            eq_(service, 'wmts')
            eq_(len(layers), 1)
            return {
                'authorized': 'partial',
                'limited_to': {
                    'geometry': [-180, -89, 180, 89],
                    'srs': 'EPSG:4326',
                },
                'layers': {
                    'layer3': {
                        'tile': True
                    },
                }
            }

        serv = MockServ(port=42423)
        serv.expects('/1/0/1.png')
        serv.returns(create_tmp_image((256, 256), color=(255, 0, 0)),
                     headers={'content-type': 'image/png'})
        with serv:
            resp = self.app.get('/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg',
                                extra_environ={'mapproxy.authorize': auth})

        eq_(resp.content_type, 'image/jpeg')

        img = img_from_buf(resp.body)
        eq_(img.getcolors()[0], (256 * 256, (255, 0, 0)))
Пример #8
0
 def test_get_tile_flipped_axis(self):
     serv = MockServ(port=42423)
     # source is ll, cache/service ul
     serv.expects('/tiles/01/000/000/000/000/000/001.png')
     serv.returns(create_tmp_image((256, 256)))
     with serv:
         resp = self.app.get('/wmts/myrest/tms_cache_ul/ulgrid/01/0/0.png', status=200)
         eq_(resp.content_type, 'image/png')
Пример #9
0
 def test_get_tile_flipped_axis(self):
     serv = MockServ(port=42423)
     # source is ll, cache/service ul
     serv.expects("/tiles/01/000/000/000/000/000/001.png")
     serv.returns(create_tmp_image((256, 256)))
     with serv:
         resp = self.app.get("/wmts/myrest/tms_cache_ul/ulgrid/01/0/0.png", status=200)
         eq_(resp.content_type, "image/png")
Пример #10
0
    def test_returns_headers(self):
        serv = MockServ()
        serv.expects('/test')
        serv.returns(body=b'hello', headers={'content-type': 'text/plain'})

        with serv:
            resp = requests.get('http://localhost:%d/test' % serv.port)
            eq_(resp.headers['Content-type'], 'text/plain')
            eq_(resp.content, b'hello')
Пример #11
0
    def test_returns_status(self):
        serv = MockServ()
        serv.expects('/test')
        serv.returns(body=b'hello', status_code=418)

        with serv:
            resp = requests.get('http://localhost:%d/test' % serv.port)
            assert resp.status_code == 418
            assert resp.content == b'hello'
Пример #12
0
    def test_returns_headers(self):
        serv = MockServ()
        serv.expects('/test')
        serv.returns(body=b'hello', headers={'content-type': 'text/plain'})

        with serv:
            resp = requests.get('http://localhost:%d/test' % serv.port)
            assert resp.headers['Content-type'] == 'text/plain'
            assert resp.content == b'hello'
Пример #13
0
    def test_returns(self):
        serv = MockServ()
        serv.expects('/test')
        serv.returns(body=b'hello')

        with serv:
            resp = requests.get('http://localhost:%d/test' % serv.port)
            assert 'Content-type' not in resp.headers
            assert resp.content == b'hello'
Пример #14
0
    def test_returns_status(self):
        serv = MockServ()
        serv.expects('/test')
        serv.returns(body=b'hello', status_code=418)

        with serv:
            resp = requests.get('http://localhost:%d/test' % serv.port)
            eq_(resp.status_code, 418)
            eq_(resp.content, b'hello')
Пример #15
0
    def test_returns(self):
        serv = MockServ()
        serv.expects('/test')
        serv.returns(body=b'hello')

        with serv:
            resp = requests.get('http://localhost:%d/test' % serv.port)
            assert 'Content-type' not in resp.headers
            eq_(resp.content, b'hello')
Пример #16
0
 def test_get_tile_flipped_axis(self):
     self.common_tile_req.params['layer'] = 'tms_cache_ul'
     self.common_tile_req.params['tilematrixset'] = 'ulgrid'
     self.common_tile_req.params['format'] = 'image/png'
     self.common_tile_req.tile = (0, 0, '01')
     serv = MockServ(port=42423)
     # source is ll, cache/service ul
     serv.expects('/tiles/01/000/000/000/000/000/001.png')
     serv.returns(create_tmp_image((256, 256)))
     with serv:
         resp = self.app.get(str(self.common_tile_req), status=200)
         eq_(resp.content_type, 'image/png')
Пример #17
0
 def test_get_tile_flipped_axis(self):
     self.common_tile_req.params['layer'] = 'tms_cache_ul'
     self.common_tile_req.params['tilematrixset'] = 'ulgrid'
     self.common_tile_req.params['format'] = 'image/png'
     self.common_tile_req.tile = (0, 0, '01')
     serv = MockServ(port=42423)
     # source is ll, cache/service ul
     serv.expects('/tiles/01/000/000/000/000/000/001.png')
     serv.returns(create_tmp_image((256, 256)))
     with serv:
         resp = self.app.get(str(self.common_tile_req), status=200)
         eq_(resp.content_type, 'image/png')
Пример #18
0
 def test_get_tile_flipped_axis(self, app):
     serv = MockServ(port=42423)
     # source is ll, cache/service ul
     serv.expects("/tiles/01/000/000/000/000/000/001.png")
     serv.returns(create_tmp_image((256, 256)))
     with serv:
         resp = app.get("/wmts/myrest/tms_cache_ul/ulgrid/01/0/0.png",
                        status=200)
         assert resp.content_type == "image/png"
         # test without leading 0 in level
         resp = app.get("/wmts/myrest/tms_cache_ul/ulgrid/1/0/0.png",
                        status=200)
         assert resp.content_type == "image/png"
Пример #19
0
 def test_getfeatureinfo(self, app, fi_req):
     serv = MockServ(port=42423)
     serv.expects(
         "/service?layers=foo,bar" +
         "&bbox=-20037508.342789244,-20037508.342789244,20037508.342789244,20037508.342789244"
         +
         "&width=256&height=256&x=17&y=27&query_layers=foo,bar&format=image%2Fpng&srs=EPSG%3A900913"
         +
         "&request=GetFeatureInfo&version=1.1.1&service=WMS&styles=&info_format=application/json"
     )
     serv.returns(b'{"data": 43}')
     with serv:
         resp = app.get(str(fi_req), status=200)
         assert resp.content_type == "application/json"
Пример #20
0
    def test_get_map_uncached(self, app):
        self.common_map_req.params.bbox = "-180,0,0,80"
        serv = MockServ(port=42423)
        serv.expects("/tiles/01/000/000/000/000/000/001.png")
        serv.returns(create_tmp_image((256, 256)))
        with serv:
            resp = app.get(self.common_map_req)
            assert resp.content_type == "image/png"
            data = BytesIO(resp.body)
            assert is_png(data)

        # now cached
        resp = app.get(self.common_map_req)
        assert resp.content_type == "image/png"
        data = BytesIO(resp.body)
        assert is_png(data)
Пример #21
0
    def test_get_map_uncached(self):
        self.common_map_req.params.bbox = '-180,0,0,80'
        serv = MockServ(port=42423)
        serv.expects('/tiles/01/000/000/000/000/000/001.png')
        serv.returns(create_tmp_image((256, 256)))
        with serv:
            resp = self.app.get(self.common_map_req)
            eq_(resp.content_type, 'image/png')
            data = StringIO(resp.body)
            assert is_png(data)

        # now cached
        resp = self.app.get(self.common_map_req)
        eq_(resp.content_type, 'image/png')
        data = StringIO(resp.body)
        assert is_png(data)
Пример #22
0
    def test_get_map_uncached(self):
        self.common_map_req.params.bbox = '-180,0,0,80'
        serv = MockServ(port=42423)
        serv.expects('/tiles/01/000/000/000/000/000/001.png')
        serv.returns(create_tmp_image((256, 256)))
        with serv:
            resp = self.app.get(self.common_map_req)
            eq_(resp.content_type, 'image/png')
            data = StringIO(resp.body)
            assert is_png(data)

        # now cached
        resp = self.app.get(self.common_map_req)
        eq_(resp.content_type, 'image/png')
        data = StringIO(resp.body)
        assert is_png(data)
Пример #23
0
 def test_getfeatureinfo_xml(self, app, fi_req):
     fi_req.params["infoformat"] = "application/gml+xml; version=3.1"
     serv = MockServ(port=42423)
     serv.expects(
         "/service?layers=foo,bar" +
         "&bbox=-20037508.342789244,-20037508.342789244,20037508.342789244,20037508.342789244"
         +
         "&width=256&height=256&x=17&y=27&query_layers=foo,bar&format=image%2Fpng&srs=EPSG%3A900913"
         +
         "&request=GetFeatureInfo&version=1.1.1&service=WMS&styles=&info_format=application/gml%2bxml%3b%20version=3.1"
     )
     serv.returns(b"<root />")
     with serv:
         resp = app.get(str(fi_req), status=200)
         assert resp.headers[
             "Content-type"] == "application/gml+xml; version=3.1"
Пример #24
0
    def test_get_map_uncached(self):
        assert os.path.exists(os.path.join(test_config['base_dir'], 'cache.gpkg')) # already created on startup

        self.common_map_req.params.bbox = '-180,0,0,80'
        serv = MockServ(port=42423)
        serv.expects('/tiles/01/000/000/000/000/000/001.png')
        serv.returns(create_tmp_image((256, 256)))
        with serv:
            resp = self.app.get(self.common_map_req)
            eq_(resp.content_type, 'image/png')
            data = BytesIO(resp.body)
            assert is_png(data)

        # now cached
        resp = self.app.get(self.common_map_req)
        eq_(resp.content_type, 'image/png')
        data = BytesIO(resp.body)
        assert is_png(data)
Пример #25
0
    def test_get_map_uncached(self, app, base_dir):
        assert base_dir.join("cache.gpkg").check()
        # already created on startup

        self.common_map_req.params.bbox = "-180,0,0,80"
        serv = MockServ(port=42423)
        serv.expects("/tiles/01/000/000/000/000/000/001.png")
        serv.returns(create_tmp_image((256, 256)))
        with serv:
            resp = app.get(self.common_map_req)
            assert resp.content_type == "image/png"
            data = BytesIO(resp.body)
            assert is_png(data)

        # now cached
        resp = app.get(self.common_map_req)
        assert resp.content_type == "image/png"
        data = BytesIO(resp.body)
        assert is_png(data)
Пример #26
0
    def test_get_tile_flipped_axis(self, app, cache_dir, fixture_cache_data):
        # test default tile lock directory
        tiles_lock_dir = cache_dir.join("tile_locks")
        assert not tiles_lock_dir.check()

        self.common_tile_req.params["layer"] = "tms_cache_ul"
        self.common_tile_req.params["tilematrixset"] = "ulgrid"
        self.common_tile_req.params["format"] = "image/png"
        self.common_tile_req.tile = (0, 0, "01")
        serv = MockServ(port=42423)
        # source is ll, cache/service ul
        serv.expects("/tiles/01/000/000/000/000/000/001.png")
        serv.returns(create_tmp_image((256, 256)))
        with serv:
            resp = app.get(str(self.common_tile_req), status=200)
            assert resp.content_type == "image/png"

        # test default tile lock directory was created
        assert tiles_lock_dir.check()
Пример #27
0
 def test_get_featureinfo_limited_to_inside(self):
     def auth(service, layers, query_extent, **kw):
         eq_(query_extent, ('EPSG:4326', (-80.0, -40.0, 0.0, 0.0)))
         eq_(service, 'wms.featureinfo')
         eq_(len(layers), 1)
         return {
             'authorized': 'partial',
             'layers': {
                 'layer1b': {'featureinfo': True, 'limited_to':  {'srs': 'EPSG:4326', 'geometry': [-80.0, -40.0, 0.0, 0.0]}},
             }
         }
     serv = MockServ(port=42423)
     serv.expects('/service?request=GetFeatureInfo&service=WMS&Version=1.1.1&SRS=EPSG:4326'
         '&BBOX=-80.0,-40.0,0.0,0.0&WIDTH=200&HEIGHT=100&styles=&FORMAT=image/png&X=10&Y=10'
         '&query_layers=fi&layers=fi')
     serv.returns('infoinfo')
     with serv:
         resp = self.app.get(FI_REQ + 'query_layers=layer1b&layers=layer1b', extra_environ={'mapproxy.authorize': auth})
         eq_(resp.body, 'infoinfo')
Пример #28
0
    def test_getfeatureinfo_coverage(self, app, fi_req):
        fi_req.params['layer'] = 'tms_cache'
        fi_req.params['i'] = '250'
        fi_req.params['j'] = '50'
        resp = app.get(str(fi_req), status=200)
        assert resp.content_type == "application/json"

        fi_req.params['i'] = '150'
        serv = MockServ(port=42423)
        serv.expects(
            "/service?layers=fi" +
            "&bbox=-20037508.3428,-20037508.3428,20037508.3428,20037508.3428" +
            "&width=256&height=256&x=150&y=50&query_layers=fi&format=image%2Fpng&srs=EPSG%3A900913"
            +
            "&request=GetFeatureInfo&version=1.1.1&service=WMS&styles=&info_format=application/json"
        )
        serv.returns(b'{"data": 43}')
        with serv:
            resp = app.get(str(fi_req), status=200)
            assert resp.content_type == "application/json"
Пример #29
0
    def test_get_tile_flipped_axis(self):
        # test default tile lock directory
        tiles_lock_dir = os.path.join(test_config['base_dir'], 'cache_data', 'tile_locks')
        # make sure default tile_lock_dir was not created by other tests
        shutil.rmtree(tiles_lock_dir, ignore_errors=True)
        assert not os.path.exists(tiles_lock_dir)

        self.common_tile_req.params['layer'] = 'tms_cache_ul'
        self.common_tile_req.params['tilematrixset'] = 'ulgrid'
        self.common_tile_req.params['format'] = 'image/png'
        self.common_tile_req.tile = (0, 0, '01')
        serv = MockServ(port=42423)
        # source is ll, cache/service ul
        serv.expects('/tiles/01/000/000/000/000/000/001.png')
        serv.returns(create_tmp_image((256, 256)))
        with serv:
            resp = self.app.get(str(self.common_tile_req), status=200)
            eq_(resp.content_type, 'image/png')

        # test default tile lock directory was created
        assert os.path.exists(tiles_lock_dir)
Пример #30
0
    def test_get_tile_flipped_axis(self):
        # test default tile lock directory
        tiles_lock_dir = os.path.join(test_config['base_dir'], 'cache_data', 'tile_locks')
        # make sure default tile_lock_dir was not created by other tests
        shutil.rmtree(tiles_lock_dir, ignore_errors=True)
        assert not os.path.exists(tiles_lock_dir)

        self.common_tile_req.params['layer'] = 'tms_cache_ul'
        self.common_tile_req.params['tilematrixset'] = 'ulgrid'
        self.common_tile_req.params['format'] = 'image/png'
        self.common_tile_req.tile = (0, 0, '01')
        serv = MockServ(port=42423)
        # source is ll, cache/service ul
        serv.expects('/tiles/01/000/000/000/000/000/001.png')
        serv.returns(create_tmp_image((256, 256)))
        with serv:
            resp = self.app.get(str(self.common_tile_req), status=200)
            eq_(resp.content_type, 'image/png')

        # test default tile lock directory was created
        assert os.path.exists(tiles_lock_dir)
Пример #31
0
    def test_get_tile_flipped_axis(self):
        # test default tile lock directory
        tiles_lock_dir = os.path.join(test_config["base_dir"], "cache_data", "tile_locks")
        # make sure default tile_lock_dir was not created by other tests
        shutil.rmtree(tiles_lock_dir, ignore_errors=True)
        assert not os.path.exists(tiles_lock_dir)

        self.common_tile_req.params["layer"] = "tms_cache_ul"
        self.common_tile_req.params["tilematrixset"] = "ulgrid"
        self.common_tile_req.params["format"] = "image/png"
        self.common_tile_req.tile = (0, 0, "01")
        serv = MockServ(port=42423)
        # source is ll, cache/service ul
        serv.expects("/tiles/01/000/000/000/000/000/001.png")
        serv.returns(create_tmp_image((256, 256)))
        with serv:
            resp = self.app.get(str(self.common_tile_req), status=200)
            eq_(resp.content_type, "image/png")

        # test default tile lock directory was created
        assert os.path.exists(tiles_lock_dir)
Пример #32
0
    def test_add_get_edit_delete(self):
        mock_serv = MockServ()
        mock_serv.expects('/foo/service?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1')
        cap_file = os.path.join(os.path.dirname(__file__), 'fixtures', 'wms_nasa_cap.xml')
        mock_serv.returns(body_file=cap_file)
        with mock_serv:
            resp = self.app.post_json('/conf/base/wms_capabilities', {'data': {'url': mock_serv.base_url + '/foo/service'}})

        id = resp.json['_id']

        expected = {
            '_id': id,
            'data': {
                'abstract': helper.ANY,
                'title': 'JPL Global Imagery Service',
                'url': 'http://wms.jpl.nasa.gov/wms.cgi?',
                'layer': helper.ANY,
            }
        }
        assert resp.json == expected

        resp = self.app.get('/conf/base/wms_capabilities/%d' % resp.json['_id'])
        expected.pop('_id') # remove if we decide to pass _id in get request
        assert resp.json == expected

        resp = self.app.get('/conf/base/wms_capabilities')
        # add vars returned by function
        expected['_id'] = id
        expected['_locked'] = 0
        expected['_manual'] = 0
        expected['_section'] = 'wms_capabilities'
        assert resp.json == {str(id): expected}
        mock_serv.reset()

        with mock_serv:
            resp = self.app.put_json('/conf/base/wms_capabilities/%d' % id, {'data': {'url': mock_serv.base_url + '/foo/service'}})

        resp = self.app.delete('/conf/base/wms_capabilities/%d' % id)
        assert resp.status_code == 204
        resp = self.app.get('/conf/base/wms_capabilities/%d' % id, status=404)
Пример #33
0
    def check_get_tile_limited_to(self, auth_dict):
        def auth(service, layers, environ, query_extent, **kw):
            eq_(environ['PATH_INFO'], '/kml/layer3_EPSG900913/1/0/0.jpeg')
            eq_(service, 'kml')
            eq_(len(layers), 1)
            eq_(query_extent[0], 'EPSG:900913')
            assert bbox_equals(query_extent[1], (-20037508.342789244, -20037508.342789244, 0, 0))
            return auth_dict

        serv = MockServ(port=42423)
        serv.expects('/1/0/0.png')
        serv.returns(create_tmp_image((256, 256), color=(255, 0, 0)), headers={'content-type': 'image/png'})
        with serv:
            resp = self.app.get('/kml/layer3_EPSG900913/1/0/0.jpeg', extra_environ={'mapproxy.authorize': auth})

        eq_(resp.content_type, 'image/png')

        img = img_from_buf(resp.body)
        img = img.convert('RGBA')
        # left part authorized, red
        eq_(img.crop((0, 0, 127, 255)).getcolors()[0], (127*255, (255, 0, 0, 255)))
        # right part not authorized, transparent
        eq_(img.crop((129, 0, 255, 255)).getcolors()[0][1][3], 0)