Пример #1
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)
Пример #2
0
    def test_combined_mixed_fwd_req_params(self):
        # not merged to one request because fwd_req_params are different
        common_params = (r'/service_a?SERVICE=WMS&FORMAT=image%2Fpng'
                                  '&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326&styles='
                                  '&VERSION=1.1.1&BBOX=9.0,50.0,10.0,51.0'
                                  '&WIDTH=200&transparent=True')

        with tmp_image((200, 200), format='png') as img:
            img = img.read()
            expected_req = [({'path': common_params + '&layers=a_one&TIME=20041012'},
                             {'body': img, 'headers': {'content-type': 'image/png'}}),
                             ({'path': common_params + '&layers=a_two&TIME=20041012&VENDOR=foo'},
                             {'body': img, 'headers': {'content-type': 'image/png'}}),
                             ({'path': common_params + '&layers=a_four'},
                             {'body': img, 'headers': {'content-type': 'image/png'}}),
                            ]

            with mock_httpd(('localhost', 42423), expected_req):
                self.common_map_req.params.layers = 'layer_fwdparams1,single'
                self.common_map_req.params['time'] = '20041012'
                self.common_map_req.params['vendor'] = 'foo'
                self.common_map_req.params.transparent = True
                resp = self.app.get(self.common_map_req)
                resp.content_type = 'image/png'
                data = BytesIO(resp.body)
                assert is_png(data)
Пример #3
0
 def test_converted_output(self):
     ir = ImageSource(self.tmp_filename, (100, 100), PNG_FORMAT)
     assert is_png(ir.as_buffer())
     assert is_jpeg(ir.as_buffer(JPEG_FORMAT))
     assert is_jpeg(ir.as_buffer())
     assert is_tiff(ir.as_buffer(TIFF_FORMAT))
     assert is_tiff(ir.as_buffer())
Пример #4
0
    def test_layers_with_opacity(self):
        # overlay with opacity -> request should not be combined
        common_params = (r'?SERVICE=WMS&FORMAT=image%2Fpng'
                                  '&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326&styles='
                                  '&VERSION=1.1.1&BBOX=9.0,50.0,10.0,51.0'
                                  '&WIDTH=200')

        img_bg = create_tmp_image((200, 200), color=(0, 0, 0))
        img_fg = create_tmp_image((200, 200), color=(255, 0, 128))

        expected_req = [
                        ({'path': '/service_a' + common_params + '&layers=a_one'},
                         {'body': img_bg, 'headers': {'content-type': 'image/png'}}),
                        ({'path': '/service_a' + common_params + '&layers=a_two'},
                         {'body': img_fg, 'headers': {'content-type': 'image/png'}}),
                        ]

        with mock_httpd(('localhost', 42423), expected_req):
            self.common_map_req.params.layers = 'opacity_base,opacity_overlay'
            resp = self.app.get(self.common_map_req)
            eq_(resp.content_type, 'image/png')
            data = BytesIO(resp.body)
            assert is_png(data)
            img = Image.open(data)
            eq_(img.getcolors()[0], ((200*200),(127, 0, 64)))
Пример #5
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)
Пример #6
0
 def test_get_map(self):
     resp = self.app.get(self.common_map_req)
     eq_(resp.content_type, 'image/png')
     data = BytesIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     img = img.convert('RGB')
     eq_(img.getcolors(), [(200*200, (255, 0, 0))])
Пример #7
0
 def test_get_tile_uncached(self):
     resp = self.app.get('/tms/1.0.0/wms_cache/0/0/0.jpeg')
     eq_(resp.content_type, 'image/png')
     data = BytesIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGBA')
     eq_(img.getcolors(), [(256*256, (255, 255, 255, 0))])
Пример #8
0
    def test_get_tile_without_caching(self):
        with tmp_image((256, 256), format='png') as img:
            expected_req = ({'path': r'/tile.png'},
                            {'body': img.read(), 'headers': {'content-type': 'image/png'}})
            with mock_httpd(('localhost', 42423), [expected_req]):
                resp = self.app.get('/tms/1.0.0/tiles/0/0/0.png')
                eq_(resp.content_type, 'image/png')
                is_png(resp.body)

        assert not os.path.exists(test_config['cache_dir'])
        
        with tmp_image((256, 256), format='png') as img:
            expected_req = ({'path': r'/tile.png'},
                            {'body': img.read(), 'headers': {'content-type': 'image/png'}})
            with mock_httpd(('localhost', 42423), [expected_req]):
                resp = self.app.get('/tms/1.0.0/tiles/0/0/0.png')
                eq_(resp.content_type, 'image/png')
                is_png(resp.body)
Пример #9
0
 def test_get_map_cached(self):
     resp = self.app.get(self.common_map_req)
     eq_(resp.content_type, 'image/png')
     data = BytesIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGB')
     # cached image has more that 256 colors, getcolors -> None
     eq_(img.getcolors(), None)
Пример #10
0
 def test_get_map_uncached(self):
     self.common_map_req.params['bbox'] = '10,10,20,20'
     resp = self.app.get(self.common_map_req)
     eq_(resp.content_type, 'image/png')
     data = BytesIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGBA')
     eq_(img.getcolors(), [(200*200, (255, 255, 255, 0))])
Пример #11
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)
Пример #12
0
 def test_get_tile_webmerc(self):
     serv = MockServ(42423, bbox_aware_query_comparator=True)
     serv.expects(
         '/service?layers=foo,bar&width=256&version=1.1.1&bbox=-20037508.3428,0.0,0.0,20037508.3428&service=WMS&format=image%2Fpng&styles=&srs=EPSG%3A3857&request=GetMap&height=256').returns(TEST_TILE)
     with serv:
         resp = self.app.get(str(self.common_tile_req))
     eq_(resp.content_type, 'image/png')
     data = BytesIO(resp.body)
     assert is_png(data)
Пример #13
0
 def test_get_map_outside(self):
     self.common_map_req.params.bbox = -90, 0, 0, 90
     self.common_map_req.params['bgcolor'] = '0xff0005'
     resp = self.app.get(self.common_map_req)
     eq_(resp.content_type, 'image/png')
     data = StringIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGB')
     eq_(img.getcolors(), [(200*200, (255, 0, 5))])
Пример #14
0
 def test_single_color_tile_store_w_alpha(self):
     img = Image.new('RGBA', (256, 256), color='#ff0105')
     tile = Tile((0, 0, 4), ImageSource(img, image_opts=ImageOptions(format='image/png')))
     self.cache.link_single_color_images = True
     self.cache.store_tile(tile)
     assert self.cache.is_cached(tile)
     loc = self.cache.tile_location(tile)
     assert os.path.islink(loc)
     assert os.path.realpath(loc).endswith('ff0105ff.png')
     assert is_png(open(loc, 'rb'))
Пример #15
0
 def test_out_of_extent(self):
     resp = self.app.get('http://localhost/service?SERVICE=WMS&REQUEST=GetMap'
         '&LAYERS=direct&STYLES='
         '&WIDTH=100&HEIGHT=100&FORMAT=image/png'
         '&BBOX=-10000,0,0,1000&SRS=EPSG:25832'
         '&VERSION=1.1.0&TRANSPARENT=TRUE')
     # empty/transparent response
     eq_(resp.content_type, 'image/png')
     assert is_png(resp.body)
     assert is_transparent(resp.body)
Пример #16
0
 def test_out_of_extent_bgcolor(self):
     resp = self.app.get('http://localhost/service?SERVICE=WMS&REQUEST=GetMap'
         '&LAYERS=direct&STYLES='
         '&WIDTH=100&HEIGHT=100&FORMAT=image/png'
         '&BBOX=-10000,0,0,1000&SRS=EPSG:25832'
         '&VERSION=1.1.0&TRANSPARENT=FALSE&BGCOLOR=0xff0000')
     # red response
     eq_(resp.content_type, 'image/png')
     assert is_png(resp.body)
     assert_colors_equal(img_from_buf(resp.body).convert('RGBA'),
             [(100 * 100, [255, 0, 0, 255])])
Пример #17
0
    def test_get_tile_utm(self):
        serv = MockServ(42423, bbox_aware_query_comparator=True)
        serv.expects(
            '/service?layers=foo,bar&width=256&version=1.1.1&bbox=-46133.17,5675047.40429,580038.965712,6301219.54&service=WMS&format=image%2Fpng&styles=&srs=EPSG%3A25832&request=GetMap&height=256').returns(TEST_TILE)
        self.common_tile_req.params['tilematrixset'] = 'utm32'

        with serv:
            resp = self.app.get(str(self.common_tile_req))
        eq_(resp.content_type, 'image/png')
        data = BytesIO(resp.body)
        assert is_png(data)
Пример #18
0
 def test_get_map_outside_transparent(self):
     self.common_map_req.params.bbox = -90, 0, 0, 90
     self.common_map_req.params.transparent = True
     resp = self.app.get(self.common_map_req)
     eq_(resp.content_type, 'image/png')
     data = StringIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGBA')
     eq_(img.getcolors()[0][0], 200*200)
     eq_(img.getcolors()[0][1][3], 0) # transparent
Пример #19
0
    def test_get_tile_with_layer(self):
        expected_req = [({'path': '/arcgis/rest/services/ExampleLayer/MapServer/export?f=image&format=png&layers=show:0,1&imageSR=900913&bboxSR=900913&bbox=-20037508.342789244,-20037508.342789244,20037508.342789244,20037508.342789244&size=512,512'},
                 {'body': transp, 'headers': {'content-type': 'image/png'}}),
                ]

        with mock_httpd(('localhost', 42423), expected_req, bbox_aware_query_comparator=True):
            resp = self.app.get('/tms/1.0.0/app2_with_layers_layer/0/0/1.png')
            eq_(resp.content_type, 'image/png')
            eq_(resp.content_length, len(resp.body))
            data = BytesIO(resp.body)
            assert is_png(data)
Пример #20
0
 def test_02_get_legendgraphic_layer_static_url(self):
     self.common_lg_req_111.params['layer'] = 'wms_layer_static_url'
     with tmp_image((256, 256), format='png') as img:
         img_data = img.read()
         expected_req1 = ({'path': r'/staticlegend_layer.png'},
                          {'body': img_data, 'headers': {'content-type': 'image/png'}})
         with mock_httpd(('localhost', 42423), [expected_req1]):
             resp = self.app.get(self.common_lg_req_111)
             eq_(resp.content_type, 'image/png')
             data = StringIO(resp.body)
             assert is_png(data)
             assert Image.open(data).size == (256,256)
Пример #21
0
    def test_exception(self):
        self.req.set("exceptions", "inimage")
        self.req.set("transparent", "true")

        req = WMSMapRequest(self.req)
        req_ex = RequestError("the exception message", request=req)

        response = req_ex.render()
        assert response.content_type == "image/png"
        data = StringIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
Пример #22
0
    def test_exception(self):
        self.req["exceptions"] = "blank"
        req = WMSMapRequest(self.req)
        req_ex = RequestError("the exception message", request=req)

        response = req_ex.render()
        assert response.content_type == "image/png"
        data = StringIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
        eq_(img.getpixel((0, 0)), 0)  # pallete image
        eq_(img.getpalette()[0:3], [255, 255, 255])
Пример #23
0
    def test_get_map_cached(self):
        # mock_s3 interferes with MockServ, use boto to manually upload tile
        tile = create_tmp_image((256, 256))
        boto3.client("s3").upload_fileobj(
                BytesIO(tile),
                Bucket='default_bucket',
                Key='default_cache/WebMerc/4/1/9.png',
        )

        resp = self.app.get(self.common_map_req)
        eq_(resp.content_type, 'image/png')
        data = BytesIO(resp.body)
        assert is_png(data)
Пример #24
0
 def test_get_map(self):
     with tmp_image((512, 512)) as img:
         expected_req = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                                  '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326&styles='
                                  '&VERSION=1.1.1&BBOX=0.0,10.0,10.0,20.0&WIDTH=512'},
                        {'body': img.read(), 'headers': {'content-type': 'image/png'}})
         with mock_httpd(TEST_SERVER_ADDRESS, [expected_req]):
             q = MapQuery((0.0, 10.0, 10.0, 20.0), (512, 512), SRS(4326))
             result = self.source.get_map(q)
             assert isinstance(result, ImageSource)
             eq_(result.size, (512, 512))
             assert is_png(result.as_buffer(seekable=True))
             eq_(result.as_image().size, (512, 512))
Пример #25
0
    def test_get_map_cached_quadkey(self):
        # mock_s3 interferes with MockServ, use boto to manually upload tile
        tile = create_tmp_image((256, 256))
        boto3.client("s3").upload_fileobj(
                BytesIO(tile),
                Bucket='tiles',
                Key='quadkeytiles/2003.png',
        )

        self.common_map_req.params.layers = 'quadkey'
        resp = self.app.get(self.common_map_req)
        eq_(resp.content_type, 'image/png')
        data = BytesIO(resp.body)
        assert is_png(data)
Пример #26
0
 def test_concatenation(self):
     legends = []
     img_1 = Image.new(mode='RGBA', size=(30,10), color="red")
     img_2 = Image.new(mode='RGBA', size=(10,10), color="black")
     img_3 = Image.new(mode='RGBA', size=(50,80), color="blue")
     legends.append(ImageSource(img_1))
     legends.append(ImageSource(img_2))
     legends.append(ImageSource(img_3))
     source = concat_legends(legends)
     src_img = source.as_image()
     assert src_img.getpixel((0,90)) == (255,0,0,255)
     assert src_img.getpixel((0,80)) == (0,0,0,255)
     assert src_img.getpixel((0,0)) == (0,0,255,255)
     assert src_img.getpixel((49,99)) == (255,255,255,0)
     assert is_png(source.as_buffer())
Пример #27
0
    def test_exception_w_transparent(self):
        self.req.set("exceptions", "blank")
        self.req.set("transparent", "true")

        req = WMSMapRequest(self.req)
        req_ex = RequestError("the exception message", request=req)

        response = req_ex.render()
        assert response.content_type == "image/png"
        data = StringIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
        assert img.mode == "P"
        img = img.convert("RGBA")
        eq_(img.getpixel((0, 0))[3], 0)
Пример #28
0
    def test_exception_w_transparent(self):
        self.req.set("exceptions", "inimage")
        self.req.set("transparent", "true")

        req = WMSMapRequest(self.req)
        req_ex = RequestError("the exception message", request=req)

        response = req_ex.render()
        assert response.content_type == "image/png"
        data = StringIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
        eq_(sorted([x for x in img.histogram() if x > 25]), [377, 14623])
        img = img.convert("RGBA")
        eq_(img.getpixel((0, 0))[3], 0)
Пример #29
0
 def test_get_map_intersection(self):
     self.created_tiles.append('wms_cache_EPSG4326/03/000/000/004/000/000/002.jpeg')
     with tmp_image((256, 256), format='jpeg') as img:
         expected_req = ({'path': r'/service?LAYERs=foo,bar&SERVICE=WMS&FORMAT=image%2Fjpeg'
                                   '&REQUEST=GetMap&HEIGHT=91&SRS=EPSG%3A4326&styles='
                                   '&VERSION=1.1.1&BBOX=10,15,30,31'
                                   '&WIDTH=114'},
                         {'body': img.read(), 'headers': {'content-type': 'image/jpeg'}})
         with mock_httpd(('localhost', 42423), [expected_req]):
             self.common_map_req.params.bbox = 0, 0, 40, 40
             self.common_map_req.params.transparent = True
             resp = self.app.get(self.common_map_req)
             eq_(resp.content_type, 'image/png')
             data = StringIO(resp.body)
             assert is_png(data)
             eq_(Image.open(data).mode, 'RGBA')
Пример #30
0
 def test_wms_transparent(self):
     req = WMS111MapRequest(
         url='/service?',
         param=dict(
             service='WMS', version='1.1.1', bbox='-180,0,0,80',
             width='200', height='200', layers='wms_cache_transparent',
             srs='EPSG:4326', format='image/png',
             styles='', request='GetMap', transparent='True'
         )
     )
     resp = self.app.get(
         req, extra_environ={'mapproxy.decorate_img': to_greyscale}
     )
     data = BytesIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGBA')
Пример #31
0
    def test_exception_w_transparent(self):
        self.req.set('exceptions', 'inimage')
        self.req.set('transparent', 'true' )

        req = WMSMapRequest(self.req)
        req_ex = RequestError('the exception message', request=req)

        response = req_ex.render()
        assert response.content_type == 'image/png'
        data = BytesIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
        eq_(sorted([x for x in img.histogram() if x > 25]),
            [377, 14623])
        img = img.convert('RGBA')
        eq_(img.getpixel((0, 0))[3], 0)
Пример #32
0
 def test_wms_transparent(self):
     req = WMS111MapRequest(
         url='/service?',
         param=dict(
             service='WMS', version='1.1.1', bbox='-180,0,0,80',
             width='200', height='200', layers='wms_cache_transparent',
             srs='EPSG:4326', format='image/png',
             styles='', request='GetMap', transparent='True'
         )
     )
     resp = self.app.get(
         req, extra_environ={'mapproxy.decorate_img': to_greyscale}
     )
     data = StringIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGBA')
Пример #33
0
    def test_combined_mixed_fwd_req_params(self):
        # not merged to one request because fwd_req_params are different
        common_params = (r'/service_a?SERVICE=WMS&FORMAT=image%2Fpng'
                         '&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326&styles='
                         '&VERSION=1.1.1&BBOX=9.0,50.0,10.0,51.0'
                         '&WIDTH=200&transparent=True')

        with tmp_image((200, 200), format='png') as img:
            img = img.read()
            expected_req = [
                ({
                    'path': common_params + '&layers=a_one&TIME=20041012'
                }, {
                    'body': img,
                    'headers': {
                        'content-type': 'image/png'
                    }
                }),
                ({
                    'path':
                    common_params + '&layers=a_two&TIME=20041012&VENDOR=foo'
                }, {
                    'body': img,
                    'headers': {
                        'content-type': 'image/png'
                    }
                }),
                ({
                    'path': common_params + '&layers=a_four'
                }, {
                    'body': img,
                    'headers': {
                        'content-type': 'image/png'
                    }
                }),
            ]

            with mock_httpd(('localhost', 42423), expected_req):
                self.common_map_req.params.layers = 'layer_fwdparams1,single'
                self.common_map_req.params['time'] = '20041012'
                self.common_map_req.params['vendor'] = 'foo'
                self.common_map_req.params.transparent = True
                resp = self.app.get(self.common_map_req)
                resp.content_type = 'image/png'
                data = BytesIO(resp.body)
                assert is_png(data)
Пример #34
0
 def test_02_get_legendgraphic_layer_static_url(self):
     self.common_lg_req_111.params['layer'] = 'wms_layer_static_url'
     with tmp_image((256, 256), format='png') as img:
         img_data = img.read()
         expected_req1 = ({
             'path': r'/staticlegend_layer.png'
         }, {
             'body': img_data,
             'headers': {
                 'content-type': 'image/png'
             }
         })
         with mock_httpd(('localhost', 42423), [expected_req1]):
             resp = self.app.get(self.common_lg_req_111)
             eq_(resp.content_type, 'image/png')
             data = StringIO(resp.body)
             assert is_png(data)
             assert Image.open(data).size == (256, 256)
Пример #35
0
 def test_get_legendgraphic_111(self):
     self.common_lg_req_111.params['scale'] = '5.0'
     with tmp_image((256, 256), format='png') as img:
         img_data = img.read()
         expected_req1 = ({'path': r'/service?LAYER=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                                   '&REQUEST=GetLegendGraphic&SCALE=5.0&'
                                   '&VERSION=1.1.1&SLD_VERSION=1.1.0'},
                          {'body': img_data, 'headers': {'content-type': 'image/png'}})
         expected_req2 = ({'path': r'/service?LAYER=bar&SERVICE=WMS&FORMAT=image%2Fpng'
                                   '&REQUEST=GetLegendGraphic&SCALE=5.0&'
                                   '&VERSION=1.1.1&SLD_VERSION=1.1.0'},
                          {'body': img_data, 'headers': {'content-type': 'image/png'}})
         with mock_httpd(('localhost', 42423), [expected_req1, expected_req2]):
             resp = self.app.get(self.common_lg_req_111)
             eq_(resp.content_type, 'image/png')
             data = BytesIO(resp.body)
             assert is_png(data)
             assert Image.open(data).size == (256,512)
Пример #36
0
    def test_layers_with_opacity(self, app):
        # overlay with opacity -> request should not be combined
        common_params = (r"?SERVICE=WMS&FORMAT=image%2Fpng"
                         "&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326&styles="
                         "&VERSION=1.1.1&BBOX=9.0,50.0,10.0,51.0"
                         "&WIDTH=200")

        img_bg = create_tmp_image((200, 200), color=(0, 0, 0))
        img_fg = create_tmp_image((200, 200), color=(255, 0, 128))

        expected_req = [
            (
                {
                    "path": "/service_a" + common_params + "&layers=a_one"
                },
                {
                    "body": img_bg,
                    "headers": {
                        "content-type": "image/png"
                    }
                },
            ),
            (
                {
                    "path": "/service_a" + common_params + "&layers=a_two"
                },
                {
                    "body": img_fg,
                    "headers": {
                        "content-type": "image/png"
                    }
                },
            ),
        ]

        with mock_httpd(("localhost", 42423), expected_req):
            self.common_map_req.params.layers = "opacity_base,opacity_overlay"
            resp = app.get(self.common_map_req)
            assert resp.content_type == "image/png"
            data = BytesIO(resp.body)
            assert is_png(data)
            img = Image.open(data)
            assert img.getcolors()[0] == ((200 * 200), (127, 0, 64))
Пример #37
0
    def test_combined_layers(self):
        common_params = (r'?SERVICE=WMS&FORMAT=image%2Fpng'
                         '&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326&styles='
                         '&VERSION=1.1.1&BBOX=9.0,50.0,10.0,51.0'
                         '&WIDTH=200&transparent=True')

        with tmp_image((200, 200), format='png') as img:
            img = img.read()
            expected_req = [
                ({
                    'path': '/service_a' + common_params + '&layers=a_one'
                }, {
                    'body': img,
                    'headers': {
                        'content-type': 'image/png'
                    }
                }),
                ({
                    'path': '/service_b' + common_params + '&layers=b_one'
                }, {
                    'body': img,
                    'headers': {
                        'content-type': 'image/png'
                    }
                }),
                ({
                    'path':
                    '/service_a' + common_params +
                    '&layers=a_two,a_three,a_four'
                }, {
                    'body': img,
                    'headers': {
                        'content-type': 'image/png'
                    }
                }),
            ]

            with mock_httpd(('localhost', 42423), expected_req):
                self.common_map_req.params.layers = 'uncombinable,single'
                resp = self.app.get(self.common_map_req)
                eq_(resp.content_type, 'image/png')
                data = BytesIO(resp.body)
                assert is_png(data)
Пример #38
0
    def test_combined_mixed_transp_color(self, app):
        # not merged to one request because only one layer has transparent_color
        common_params = (r"?SERVICE=WMS&FORMAT=image%2Fpng"
                         "&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326&styles="
                         "&VERSION=1.1.1&BBOX=9.0,50.0,10.0,51.0"
                         "&WIDTH=200&transparent=True")

        with tmp_image((200, 200), color=(255, 0, 0), format="png") as img:
            img = img.read()
            expected_req = [
                (
                    {
                        "path": "/service_a" + common_params + "&layers=a_four"
                    },
                    {
                        "body": img,
                        "headers": {
                            "content-type": "image/png"
                        }
                    },
                ),
                (
                    {
                        "path":
                        "/service_a" + common_params + "&layers=a_iopts_one"
                    },
                    {
                        "body": img,
                        "headers": {
                            "content-type": "image/png"
                        }
                    },
                ),
            ]

            with mock_httpd(("localhost", 42423), expected_req):
                self.common_map_req.params.layers = "single,layer_image_opts1"
                self.common_map_req.params.transparent = True
                resp = app.get(self.common_map_req)
                resp.content_type = "image/png"
                data = BytesIO(resp.body)
                assert is_png(data)
Пример #39
0
 def test_get_map(self):
     with tmp_image((512, 512)) as img:
         expected_req = ({
             'path':
             r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
             '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326&styles='
             '&VERSION=1.1.1&BBOX=0.0,10.0,10.0,20.0&WIDTH=512'
         }, {
             'body': img.read(),
             'headers': {
                 'content-type': 'image/png'
             }
         })
         with mock_httpd(TEST_SERVER_ADDRESS, [expected_req]):
             q = MapQuery((0.0, 10.0, 10.0, 20.0), (512, 512), SRS(4326))
             result = self.source.get_map(q)
             assert isinstance(result, ImageSource)
             eq_(result.size, (512, 512))
             assert is_png(result.as_buffer(seekable=True))
             eq_(result.as_image().size, (512, 512))
Пример #40
0
 def test_wms_bgcolor(self):
     req = WMS111MapRequest(url='/service?',
                            param=dict(service='WMS',
                                       version='1.1.1',
                                       bbox='-180,0,0,80',
                                       width='200',
                                       height='200',
                                       layers='wms_cache_transparent',
                                       srs='EPSG:4326',
                                       format='image/png',
                                       styles='',
                                       request='GetMap',
                                       bgcolor='0xff00a0'))
     resp = self.app.get(
         req, extra_environ={'mapproxy.decorate_img': to_greyscale})
     data = StringIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGB')
     eq_(sorted(img.getcolors())[-1][1], (94, 94, 94))
Пример #41
0
    def test_combined(self, app):
        common_params = (r"?SERVICE=WMS&FORMAT=image%2Fpng"
                         "&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326&styles="
                         "&VERSION=1.1.1&BBOX=9.0,50.0,10.0,51.0"
                         "&WIDTH=200&transparent=True")

        with tmp_image((200, 200), format="png") as img:
            img = img.read()
            expected_req = [
                (
                    {
                        "path":
                        "/service_a" + common_params +
                        "&layers=a_one,a_two,a_three,a_four"
                    },
                    {
                        "body": img,
                        "headers": {
                            "content-type": "image/png"
                        }
                    },
                ),
                (
                    {
                        "path": "/service_b" + common_params + "&layers=b_one"
                    },
                    {
                        "body": img,
                        "headers": {
                            "content-type": "image/png"
                        }
                    },
                ),
            ]

            with mock_httpd(("localhost", 42423), expected_req):
                self.common_map_req.params.layers = "combinable"
                resp = app.get(self.common_map_req)
                assert resp.content_type == "image/png"
                data = BytesIO(resp.body)
                assert is_png(data)
Пример #42
0
 def test_02_get_legendgraphic_layer_static_url(self, app):
     self.common_lg_req_111.params["layer"] = "wms_layer_static_url"
     with tmp_image((256, 256), format="png") as img:
         img_data = img.read()
         expected_req1 = (
             {
                 "path": r"/staticlegend_layer.png"
             },
             {
                 "body": img_data,
                 "headers": {
                     "content-type": "image/png"
                 }
             },
         )
         with mock_httpd(("localhost", 42423), [expected_req1]):
             resp = app.get(self.common_lg_req_111)
             assert resp.content_type == "image/png"
             data = BytesIO(resp.body)
             assert is_png(data)
             assert Image.open(data).size == (256, 256)
Пример #43
0
    def test_get_tile_with_layer(self):
        expected_req = [
            ({
                'path':
                '/arcgis/rest/services/ExampleLayer/MapServer/export?f=image&format=png&layers=show:0,1&imageSR=900913&bboxSR=900913&bbox=-20037508.342789244,-20037508.342789244,20037508.342789244,20037508.342789244&size=512,512'
            }, {
                'body': transp,
                'headers': {
                    'content-type': 'image/png'
                }
            }),
        ]

        with mock_httpd(('localhost', 42423),
                        expected_req,
                        bbox_aware_query_comparator=True):
            resp = self.app.get('/tms/1.0.0/app2_with_layers_layer/0/0/1.png')
            eq_(resp.content_type, 'image/png')
            eq_(resp.content_length, len(resp.body))
            data = BytesIO(resp.body)
            assert is_png(data)
Пример #44
0
 def test_wms(self, app):
     req = WMS111MapRequest(
         url="/service?",
         param=dict(
             service="WMS",
             version="1.1.1",
             bbox="-180,0,0,80",
             width="200",
             height="200",
             layers="wms_cache",
             srs="EPSG:4326",
             format="image/png",
             styles="",
             request="GetMap",
         ),
     )
     resp = app.get(req, extra_environ={"mapproxy.decorate_img": to_greyscale})
     data = BytesIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     assert img.mode == "RGB"
Пример #45
0
    def test_get_tile_with_layer(self, app):
        expected_req = [(
            {
                "path":
                "/arcgis/rest/services/ExampleLayer/MapServer/export?f=image&format=png&layers=show:0,1&imageSR=900913&bboxSR=900913&bbox=-20037508.342789244,-20037508.342789244,20037508.342789244,20037508.342789244&size=512,512"
            },
            {
                "body": transp,
                "headers": {
                    "content-type": "image/png"
                }
            },
        )]

        with mock_httpd(("localhost", 42423),
                        expected_req,
                        bbox_aware_query_comparator=True):
            resp = app.get("/tms/1.0.0/app2_with_layers_layer/0/0/1.png")
            assert resp.content_type == "image/png"
            assert resp.content_length == len(resp.body)
            data = BytesIO(resp.body)
            assert is_png(data)
Пример #46
0
 def test_get_legendgraphic_111(self, app):
     self.common_lg_req_111.params["scale"] = "5.0"
     with tmp_image((256, 256), format="png") as img:
         img_data = img.read()
         expected_req1 = (
             {
                 "path":
                 r"/service?LAYER=foo&SERVICE=WMS&FORMAT=image%2Fpng"
                 "&REQUEST=GetLegendGraphic&SCALE=5.0&"
                 "&VERSION=1.1.1&SLD_VERSION=1.1.0"
             },
             {
                 "body": img_data,
                 "headers": {
                     "content-type": "image/png"
                 }
             },
         )
         expected_req2 = (
             {
                 "path":
                 r"/service?LAYER=bar&SERVICE=WMS&FORMAT=image%2Fpng"
                 "&REQUEST=GetLegendGraphic&SCALE=5.0&"
                 "&VERSION=1.1.1&SLD_VERSION=1.1.0"
             },
             {
                 "body": img_data,
                 "headers": {
                     "content-type": "image/png"
                 }
             },
         )
         with mock_httpd(("localhost", 42423),
                         [expected_req1, expected_req2]):
             resp = app.get(self.common_lg_req_111)
             assert resp.content_type == "image/png"
             data = BytesIO(resp.body)
             assert is_png(data)
             assert Image.open(data).size == (256, 512)
Пример #47
0
 def test_get_tile_cascaded_cache(self):
     serv = MockServ(
         42423, bbox_aware_query_comparator=True, unordered=True)
     # gk3 cache requests UTM tiles
     serv.expects(
         '/service?layers=foo,bar&width=256&version=1.1.1&bbox=423495.931784,5596775.88732,501767.448748,5675047.40429&service=WMS&format=image%2Fpng&styles=&srs=EPSG%3A25832&request=GetMap&height=256').returns(TEST_TILE)
     serv.expects(
         '/service?layers=foo,bar&width=256&version=1.1.1&bbox=345224.41482,5596775.88732,423495.931784,5675047.40429&service=WMS&format=image%2Fpng&styles=&srs=EPSG%3A25832&request=GetMap&height=256').returns(TEST_TILE)
     serv.expects(
         '/service?layers=foo,bar&width=256&version=1.1.1&bbox=345224.41482,5518504.37036,423495.931784,5596775.88732&service=WMS&format=image%2Fpng&styles=&srs=EPSG%3A25832&request=GetMap&height=256').returns(TEST_TILE)
     serv.expects(
         '/service?layers=foo,bar&width=256&version=1.1.1&bbox=423495.931784,5518504.37036,501767.448748,5596775.88732&service=WMS&format=image%2Fpng&styles=&srs=EPSG%3A25832&request=GetMap&height=256').returns(TEST_TILE)
     serv.expects(
         '/service?layers=foo,bar&width=256&version=1.1.1&bbox=345224.41482,5440232.8534,423495.931784,5518504.37036&service=WMS&format=image%2Fpng&styles=&srs=EPSG%3A25832&request=GetMap&height=256').returns(TEST_TILE)
     serv.expects(
         '/service?layers=foo,bar&width=256&version=1.1.1&bbox=423495.931784,5440232.8534,501767.448748,5518504.37036&service=WMS&format=image%2Fpng&styles=&srs=EPSG%3A25832&request=GetMap&height=256').returns(TEST_TILE)
     self.common_tile_req.params['tilematrixset'] = 'gk3'
     with serv:
         resp = self.app.get(str(self.common_tile_req))
     eq_(resp.content_type, 'image/png')
     data = BytesIO(resp.body)
     assert is_png(data)
Пример #48
0
    def test_layers_with_opacity(self):
        # overlay with opacity -> request should not be combined
        common_params = (r'?SERVICE=WMS&FORMAT=image%2Fpng'
                         '&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326&styles='
                         '&VERSION=1.1.1&BBOX=9.0,50.0,10.0,51.0'
                         '&WIDTH=200')

        img_bg = create_tmp_image((200, 200), color=(0, 0, 0))
        img_fg = create_tmp_image((200, 200), color=(255, 0, 128))

        expected_req = [
            ({
                'path': '/service_a' + common_params + '&layers=a_one'
            }, {
                'body': img_bg,
                'headers': {
                    'content-type': 'image/png'
                }
            }),
            ({
                'path': '/service_a' + common_params + '&layers=a_two'
            }, {
                'body': img_fg,
                'headers': {
                    'content-type': 'image/png'
                }
            }),
        ]

        with mock_httpd(('localhost', 42423), expected_req):
            self.common_map_req.params.layers = 'opacity_base,opacity_overlay'
            resp = self.app.get(self.common_map_req)
            eq_(resp.content_type, 'image/png')
            data = BytesIO(resp.body)
            assert is_png(data)
            img = Image.open(data)
            eq_(img.getcolors()[0], ((200 * 200), (127, 0, 64)))
Пример #49
0
 def test_get_map_intersection(self):
     self.created_tiles.append(
         'wms_cache_EPSG4326/03/000/000/004/000/000/002.jpeg')
     with tmp_image((256, 256), format='jpeg') as img:
         expected_req = ({
             'path':
             r'/service?LAYERs=foo,bar&SERVICE=WMS&FORMAT=image%2Fjpeg'
             '&REQUEST=GetMap&HEIGHT=91&SRS=EPSG%3A4326&styles='
             '&VERSION=1.1.1&BBOX=10,15,30,31'
             '&WIDTH=113'
         }, {
             'body': img.read(),
             'headers': {
                 'content-type': 'image/jpeg'
             }
         })
         with mock_httpd(('localhost', 42423), [expected_req]):
             self.common_map_req.params.bbox = 0, 0, 40, 40
             self.common_map_req.params.transparent = True
             resp = self.app.get(self.common_map_req)
             eq_(resp.content_type, 'image/png')
             data = StringIO(resp.body)
             assert is_png(data)
             eq_(Image.open(data).mode, 'RGBA')
Пример #50
0
    def test_combined_mixed_transp_color(self):
        # not merged to one request because only one layer has transparent_color
        common_params = (r'?SERVICE=WMS&FORMAT=image%2Fpng'
                         '&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326&styles='
                         '&VERSION=1.1.1&BBOX=9.0,50.0,10.0,51.0'
                         '&WIDTH=200&transparent=True')

        with tmp_image((200, 200), color=(255, 0, 0), format='png') as img:
            img = img.read()
            expected_req = [
                ({
                    'path': '/service_a' + common_params + '&layers=a_four'
                }, {
                    'body': img,
                    'headers': {
                        'content-type': 'image/png'
                    }
                }),
                ({
                    'path':
                    '/service_a' + common_params + '&layers=a_iopts_one'
                }, {
                    'body': img,
                    'headers': {
                        'content-type': 'image/png'
                    }
                }),
            ]

            with mock_httpd(('localhost', 42423), expected_req):
                self.common_map_req.params.layers = 'single,layer_image_opts1'
                self.common_map_req.params.transparent = True
                resp = self.app.get(self.common_map_req)
                resp.content_type = 'image/png'
                data = BytesIO(resp.body)
                assert is_png(data)
Пример #51
0
 def test_from_filename(self):
     ir = ImageSource(self.tmp_filename, PNG_FORMAT)
     assert is_png(ir.as_buffer())
     assert ir.as_image().size == (100, 100)
Пример #52
0
 def test_get_map_above_res(self):
     # no layer rendered
     resp = self.app.get(self.common_map_req)
     assert is_png(resp.body)
     assert is_transparent(resp.body)
Пример #53
0
 def test_get_map_cached(self, app):
     resp = app.get(self.common_map_req)
     assert resp.content_type == "image/png"
     data = BytesIO(resp.body)
     assert is_png(data)
Пример #54
0
 def test_from_image(self):
     img = Image.new("RGBA", (100, 100))
     ir = ImageSource(img, (100, 100), PNG_FORMAT)
     assert ir.as_image() == img
     assert is_png(ir.as_buffer())
Пример #55
0
 def test_get_map_cached(self):
     resp = self.app.get(self.common_map_req)
     eq_(resp.content_type, 'image/png')
     data = BytesIO(resp.body)
     assert is_png(data)