コード例 #1
0
ファイル: test_client.py プロジェクト: LKajan/mapproxy
    def test_timeouts(self):
        test_req = ({'path': '/', 'req_assert_function': lambda x: time.sleep(0.9) or True},
                    {'body': b'nothing'})

        import mapproxy.client.http

        client1 = HTTPClient(timeout=0.1)
        client2 = HTTPClient(timeout=0.5)
        with mock_httpd(TESTSERVER_ADDRESS, [test_req]):
            try:
                start = time.time()
                client1.open(TESTSERVER_URL + '/')
            except HTTPClientError as ex:
                assert 'timed out' in ex.args[0]
            else:
                assert False, 'HTTPClientError expected'
            duration1 = time.time() - start

        with mock_httpd(TESTSERVER_ADDRESS, [test_req]):
            try:
                start = time.time()
                client2.open(TESTSERVER_URL + '/')
            except HTTPClientError as ex:
                assert 'timed out' in ex.args[0]
            else:
                assert False, 'HTTPClientError expected'
            duration2 = time.time() - start

        # check individual timeouts
        assert 0.1 <= duration1 < 0.5, duration1
        assert 0.5 <= duration2 < 0.9, duration2
コード例 #2
0
ファイル: test_sld.py プロジェクト: atrawog/mapproxy
 def test_sld_body(self):
     self.common_map_req.params['layers'] = 'sld_body'
     with mock_httpd(TESTSERVER_ADDRESS, [
       ({'path': self.common_wms_url + '&sld_body=' +quote('<sld:StyledLayerDescriptor />'),
         'method': 'POST'},
        {'body': ''})]):
         self.app.get(self.common_map_req)
コード例 #3
0
ファイル: test_seed.py プロジェクト: cedricmoullet/mapproxy
    def test_timeout(self):
        # test concurrent seeding where seed concurrency is higher than the permitted
        # concurrent_request value of the source and a lock times out

        seed_conf  = load_seed_tasks_conf(self.seed_conf_file, self.mapproxy_conf)
        tasks = seed_conf.seeds(['test'])
        
        expected_req1 = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                          '&REQUEST=GetMap&VERSION=1.1.1&bbox=-180.0,-90.0,180.0,90.0'
                          '&width=256&height=128&srs=EPSG:4326'},
                        {'body': tile_image, 'headers': {'content-type': 'image/png'}, 'duration': 0.1})
        
        expected_req2 = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                          '&REQUEST=GetMap&VERSION=1.1.1&bbox=-180.0,-90.0,180.0,90.0'
                          '&width=512&height=256&srs=EPSG:4326'},
                        {'body': tile_image, 'headers': {'content-type': 'image/png'}, 'duration': 0.1})

        expected_req3 = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                          '&REQUEST=GetMap&VERSION=1.1.1&bbox=-180.0,-90.0,180.0,90.0'
                          '&width=1024&height=512&srs=EPSG:4326'},
                        {'body': tile_image, 'headers': {'content-type': 'image/png'}, 'duration': 0.1})


        with mock_httpd(('localhost', 42423), [expected_req1, expected_req2, expected_req3], unordered=True):
            seed(tasks, dry_run=False, concurrency=3)
コード例 #4
0
ファイル: test_sld.py プロジェクト: atrawog/mapproxy
 def test_sld_url(self):
     self.common_map_req.params['layers'] = 'sld_url'
     with mock_httpd(TESTSERVER_ADDRESS, [
       ({'path': self.common_wms_url + '&sld=' +quote('http://example.org/sld.xml'),
         'method': 'GET'},
        {'body': ''})]):
         self.app.get(self.common_map_req)
コード例 #5
0
 def test_request_not_parsable(self):
     with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/', 'method': 'GET'},
                                           {'status': '200', 'body': ''})]):
         with capture_out() as (out,err):
             assert_raises(SystemExit, wms_capabilities_command, self.args)
         error_msg = err.getvalue().rsplit('-'*80, 1)[1].strip()
         assert error_msg.startswith('Could not parse the document')
コード例 #6
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)
コード例 #7
0
 def test_get_multiple_featureinfo_html_out(self):
     fi_body1 = "<a><b>Bar1</b></a>"
     fi_body2 = "<a><b>Bar2</b></a>"
     fi_body3 = "<body><h1>Hello<p>Bar3"
     expected_req1 = ({'path': r'/service_a?LAYERs=a_one&SERVICE=WMS&FORMAT=image%2Fpng'
                               '&REQUEST=GetFeatureInfo&HEIGHT=200&CRS=EPSG%3A900913'
                               '&VERSION=1.3.0&BBOX=1000.0,400.0,2000.0,1400.0&styles='
                               '&WIDTH=200&QUERY_LAYERS=a_one&i=10&J=20&info_format=text/xml'},
                     {'body': fi_body1, 'headers': {'content-type': 'text/xml'}})
     expected_req2 = ({'path': r'/service_b?LAYERs=b_one&SERVICE=WMS&FORMAT=image%2Fpng'
                               '&REQUEST=GetFeatureInfo&HEIGHT=200&SRS=EPSG%3A900913'
                               '&VERSION=1.1.1&BBOX=1000.0,400.0,2000.0,1400.0&styles='
                               '&WIDTH=200&QUERY_LAYERS=b_one&X=10&Y=20&info_format=text/xml'},
                     {'body': fi_body2, 'headers': {'content-type': 'text/xml'}})
     expected_req3 = ({'path': r'/service_d?LAYERs=d_one&SERVICE=WMS&FORMAT=image%2Fpng'
                               '&REQUEST=GetFeatureInfo&HEIGHT=200&SRS=EPSG%3A900913'
                               '&VERSION=1.1.1&BBOX=1000.0,400.0,2000.0,1400.0&styles='
                               '&WIDTH=200&QUERY_LAYERS=d_one&X=10&Y=20&info_format=text/html'},
                     {'body': fi_body3, 'headers': {'content-type': 'text/html'}})
     with mock_httpd(('localhost', 42423), [expected_req1, expected_req2, expected_req3]):
         self.common_fi_req.params['layers'] = 'fi_multi_layer'
         self.common_fi_req.params['query_layers'] = 'fi_multi_layer'
         self.common_fi_req.params['info_format'] = 'text/html'
         resp = self.app.get(self.common_fi_req)
         eq_(resp.content_type, 'text/html')
         eq_(strip_whitespace(resp.body),
             '<html><body><h1>Bars</h1><p>Bar1</p><p>Bar2</p><p>Bar3</p></body></html>')
コード例 #8
0
 def test_mixed_featureinfo(self):
     fi_body1 = "Hello"
     fi_body2 = "<a><b>Bar2</b></a>"
     expected_req1 = (
         {
             "path": r"/service_c?LAYERs=c_one&SERVICE=WMS&FORMAT=image%2Fpng"
             "&REQUEST=GetFeatureInfo&HEIGHT=200&SRS=EPSG%3A900913"
             "&VERSION=1.1.1&BBOX=1000.0,400.0,2000.0,1400.0&styles="
             "&WIDTH=200&QUERY_LAYERS=c_one&X=10&Y=20"
         },
         {"body": fi_body1, "headers": {"content-type": "text/plain"}},
     )
     expected_req2 = (
         {
             "path": r"/service_a?LAYERs=a_one&SERVICE=WMS&FORMAT=image%2Fpng"
             "&REQUEST=GetFeatureInfo&HEIGHT=200&CRS=EPSG%3A900913"
             "&VERSION=1.3.0&BBOX=1000.0,400.0,2000.0,1400.0&styles="
             "&WIDTH=200&QUERY_LAYERS=a_one&i=10&J=20&info_format=text/xml"
         },
         {"body": fi_body2, "headers": {"content-type": "text/xml"}},
     )
     with mock_httpd(("localhost", 42423), [expected_req1, expected_req2]):
         self.common_fi_req.params["layers"] = "fi_without_xslt_layer,fi_layer"
         self.common_fi_req.params["query_layers"] = "fi_without_xslt_layer,fi_layer"
         resp = self.app.get(self.common_fi_req)
         eq_(resp.content_type, "text/plain")
         eq_(strip_whitespace(resp.body), "Hello<baz><foo>Bar2</foo></baz>")
コード例 #9
0
ファイル: test_seed.py プロジェクト: ChrisRenton/mapproxy
    def test_seed_refresh_remove_before_from_file(self):
        # tile already there but too old, will be refreshed and removed
        t000 = self.make_tile((0, 0, 0), timestamp=time.time() - (60*60*25))
        with tmp_image((256, 256), format='png') as img:
            img_data = img.read()
            expected_req = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                                  '&REQUEST=GetMap&VERSION=1.1.1&bbox=-180.0,-90.0,180.0,90.0'
                                  '&width=256&height=128&srs=EPSG:4326'},
                            {'body': img_data, 'headers': {'content-type': 'image/png'}})
            with mock_httpd(('localhost', 42423), [expected_req]):
                # touch the seed_conf file and refresh everything
                timestamp = time.time() - 60
                os.utime(self.seed_conf_file, (timestamp, timestamp))
                
                with local_base_config(self.mapproxy_conf.base_config):
                    seed_conf  = load_seed_tasks_conf(self.seed_conf_file, self.mapproxy_conf)
                    tasks = seed_conf.seeds(['refresh_from_file'])

                    seed(tasks, dry_run=False)

                assert os.path.exists(t000)
                assert os.path.getmtime(t000) - 5 < time.time() < os.path.getmtime(t000) + 5
        
                # now touch the seed_conf again and remove everything
                os.utime(self.seed_conf_file, None)
                with local_base_config(self.mapproxy_conf.base_config):
                    seed_conf  = load_seed_tasks_conf(self.seed_conf_file, self.mapproxy_conf)
                    cleanup_tasks = seed_conf.cleanups(['remove_from_file'])
                    cleanup(cleanup_tasks, verbose=False, dry_run=False)
コード例 #10
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)))
コード例 #11
0
ファイル: test_arcgis.py プロジェクト: tjay/mapproxy
    def test_get_tile_from_missing_arcgis_layer(self):
        expected_req = [({'path': '/arcgis/rest/services/NonExistentLayer/ImageServer/exportImage?f=image&format=png&imageSR=900913&bboxSR=900913&bbox=-20037508.342789244,-20037508.342789244,20037508.342789244,20037508.342789244&size=512,512'},
                 {'body': b'', 'status': 400}),
                ]

        with mock_httpd(('localhost', 42423), expected_req, bbox_aware_query_comparator=True):
            resp = self.app.get('/tms/1.0.0/app2_wrong_url_layer/0/0/1.png', status=500)
            eq_(resp.status_code, 500)
コード例 #12
0
 def test_get_tile_intersection_tms(self):
     with tmp_image((256, 256), format='jpeg') as img:
         expected_req = ({'path': r'/tms/1.0.0/foo/1/1/1.jpeg'},
                         {'body': img.read(), 'headers': {'content-type': 'image/jpeg'}})
         with mock_httpd(('localhost', 42423), [expected_req]):
             resp = self.app.get('/tms/1.0.0/tms_cache/0/1/1.jpeg')
             eq_(resp.content_type, 'image/jpeg')
             self.created_tiles.append('tms_cache_EPSG900913/01/000/000/001/000/000/001.jpeg')
コード例 #13
0
ファイル: test_client.py プロジェクト: Geodan/mapproxy
 def test_xyz(self):
     template = TileURLTemplate(TESTSERVER_URL + '/x=%(x)s&y=%(y)s&z=%(z)s&format=%(format)s')
     client = TileClient(template)
     with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/x=5&y=13&z=9&format=png'},
                                           {'body': b'tile',
                                            'headers': {'content-type': 'image/png'}})]):
         resp = client.get_tile((5, 13, 9)).source.read()
         eq_(resp, b'tile')
コード例 #14
0
ファイル: test_client.py プロジェクト: Geodan/mapproxy
 def test_arcgiscache_path(self):
     template = TileURLTemplate(TESTSERVER_URL + '/%(arcgiscache_path)s.png')
     client = TileClient(template)
     with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/L09/R0000000d/C00000005.png'},
                                           {'body': b'tile',
                                            'headers': {'content-type': 'image/png'}})]):
         resp = client.get_tile((5, 13, 9)).source.read()
         eq_(resp, b'tile')
コード例 #15
0
ファイル: test_sld.py プロジェクト: LKajan/mapproxy
 def test_sld_file(self):
     self.common_map_req.params['layers'] = 'sld_file'
     with mock_httpd(TESTSERVER_ADDRESS, [
       ({'path': self.common_wms_url + '&sld_body=' +quote('<sld>'), 'method': 'GET'},
        {'body': create_tmp_image((200, 200), format='png')}
       )]):
         resp = self.app.get(self.common_map_req)
         eq_(resp.content_type, 'image/png')
コード例 #16
0
ファイル: test_client.py プロジェクト: Geodan/mapproxy
 def test_internal_error_response(self):
     try:
         with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/'},
                                               {'status': '500', 'body': b''})]):
             self.client.open(TESTSERVER_URL + '/')
     except HTTPClientError as e:
         assert_re(e.args[0], r'HTTP Error ".*": 500')
     else:
         assert False, 'expected HTTPClientError'
コード例 #17
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)
コード例 #18
0
ファイル: test_client.py プロジェクト: Geodan/mapproxy
 def test_bbox(self):
     grid = tile_grid(4326)
     template = TileURLTemplate(TESTSERVER_URL + '/service?BBOX=%(bbox)s')
     client = TileClient(template, grid=grid)
     with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/service?BBOX=-180.00000000,0.00000000,-90.00000000,90.00000000'},
                                           {'body': b'tile',
                                            'headers': {'content-type': 'image/png'}})]):
         resp = client.get_tile((0, 1, 2)).source.read()
         eq_(resp, b'tile')
コード例 #19
0
ファイル: test_tiled_source.py プロジェクト: LKajan/mapproxy
    def test_image_response(self):
        error_handler = HTTPSourceErrorHandler()
        error_handler.add_handler(500, (255, 0, 0), cacheable=False)
        self.source = TiledSource(self.grid, self.client, error_handler=error_handler)

        with mock_httpd(TEST_SERVER_ADDRESS, [({'path': '/1/0/0.png'},
                                                {'body': b'error', 'status': 500, 'headers':{'content-type': 'text/plain'}})]):
            resp = self.source.get_map(MapQuery([-180, -90, 0, 90], (256, 256), SRS(4326), format='png'))
            assert not resp.cacheable
            eq_(resp.as_image().getcolors(), [((256*256), (255, 0, 0))])
コード例 #20
0
 def test_parse_130capabilities(self):
     self.args = ['command_dummy', '--host', TESTSERVER_URL + '/service?request=GetCapabilities', '--version', '1.3.0']
     with open(CAPABILITIES130_FILE, 'rb') as fp:
         capabilities_doc = fp.read()
         with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/service?request=GetCapabilities&version=1.3.0&service=WMS', 'method': 'GET'},
                                               {'status': '200', 'body': capabilities_doc})]):
             with capture() as (out,err):
                 wms_capabilities_command(self.args)
             lines = out.getvalue().split('\n')
             assert lines[1].startswith('Capabilities Document Version 1.3.0')
コード例 #21
0
ファイル: test_formats.py プロジェクト: LKajan/mapproxy
 def check_get_cached(self, layer, source, tms_format, cache_format, req_format):
     self.created_tiles.append((layer+'_EPSG900913/01/000/000/001/000/000/001.'+cache_format, cache_format))
     with tmp_image((256, 256), format=req_format) as img:
         expected_req = ({'path': self.expected_base_path +
                                  '&layers=' + source +
                                  '&format=image%2F' + req_format},
                         {'body': img.read(), 'headers': {'content-type': 'image/'+req_format}})
         with mock_httpd(('localhost', 42423), [expected_req], bbox_aware_query_comparator=True):
             resp = self.app.get('/tms/1.0.0/%s/0/1/1.%s' % (layer, tms_format))
             eq_(resp.content_type, 'image/'+tms_format)
コード例 #22
0
    def test_wms_unhandled_error_code(self):
        expected_req = [({'path': '/foo/1/1/0.png'},
                         {'body': 'error', 'status': 500, 'headers': {'content-type': 'text/plain'}}),
                        ]

        with mock_httpd(('localhost', 42423), expected_req):
            resp = self.app.get(self.common_map_req)
            assert 'Cache-Control' not in resp.headers
            eq_(resp.content_type, 'application/vnd.ogc.se_xml')
            assert '500' in resp.body
コード例 #23
0
def tile_server(tile_coords):
    with tmp_image((256, 256), format='jpeg') as img:
        img = img.read()
    expected_reqs = []
    for tile in tile_coords:
        expected_reqs.append(
            ({'path': r'/tiles/%d/%d/%d.png' % (tile[2], tile[0], tile[1])},
             {'body': img, 'headers': {'content-type': 'image/png'}}))
    with mock_httpd(('localhost', 42423), expected_reqs, unordered=True):
        yield
コード例 #24
0
 def test_service_exception(self):
     self.args = ['command_dummy', '--host', TESTSERVER_URL + '/service?request=GetCapabilitie']
     with open(SERVICE_EXCEPTION_FILE, 'r') as fp:
         capabilities_doc = fp.read()
         with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/service?request=GetCapabilitie', 'method': 'GET'},
                                               {'status': '200', 'body': capabilities_doc})]):
             with capture_out() as (out,err):
                 assert_raises(SystemExit, wms_capabilities_command, self.args)
             error_msg = err.getvalue().rsplit('-'*80, 1)[1].strip()
             assert 'Capability element not found' in error_msg
コード例 #25
0
 def test_parse_capabilities(self):
     self.args = ['command_dummy', '--host', TESTSERVER_URL + '/service?request=GetCapabilities']
     with open(CAPABILITIES_FILE, 'r') as fp:
         capabilities_doc = fp.read()
         with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/service?request=GetCapabilities', 'method': 'GET'},
                                               {'status': '200', 'body': capabilities_doc})]):
             with capture_out() as (out,err):
                 wms_capabilities_command(self.args)
             lines = out.getvalue().split('\n')
             assert lines[1].startswith('Root-Layer:')
コード例 #26
0
    def test_tile_catchall_error_no_image_response(self):
        expected_req = [({'path': '/foo/1/1/0.png'},
                         {'body': 'error', 'status': 200, 'headers': {'content-type': 'text/plain'}}),
                        ]

        with mock_httpd(('localhost', 42423), expected_req):
            resp = self.app.get(self.common_tile_req.replace('tilesource', 'tilesource_catchall'))
            assert_no_cache(resp)
            eq_(resp.content_type, 'image/png')
            img = img_from_buf(resp.body)
            eq_(img.getcolors(), [(256 * 256, (100, 50, 50))])
コード例 #27
0
 def test_key_error(self):
     self.args = ['command_dummy', '--host', TESTSERVER_URL + '/service?request=GetCapabilities']
     with open(CAPABILITIES_FILE, 'r') as fp:
         capabilities_doc = fp.read()
         capabilities_doc = capabilities_doc.replace('minx', 'foo')
         with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/service?request=GetCapabilities', 'method': 'GET'},
                                               {'status': '200', 'body': capabilities_doc})]):
             with capture_out() as (out,err):
                 assert_raises(SystemExit, wms_capabilities_command, self.args)
             error_msg = err.getvalue().rsplit('-'*80, 1)[1].strip()
             assert error_msg.startswith('XML-Element has no such attribute')
コード例 #28
0
 def test_get_tile(self):
     with tmp_image((256, 256), format='jpeg') as img:
         expected_req = ({'path': r'/service?LAYERs=bar&SERVICE=WMS&FORMAT=image%2Fjpeg'
                                   '&REQUEST=GetMap&HEIGHT=256&SRS=EPSG%3A25832&styles='
                                   '&VERSION=1.1.1&BBOX=283803.311362,5609091.90862,319018.942566,5644307.53982'
                                   '&WIDTH=256'},
                         {'body': img.read(), 'headers': {'content-type': 'image/jpeg'}})
         with mock_httpd(('localhost', 42423), [expected_req]):
             resp = self.app.get('/tms/1.0.0/wms_cache/utm32n/4/2/2.jpeg')
             eq_(resp.content_type, 'image/jpeg')
             self.created_tiles.append('wms_cache/utm32n/04/000/000/002/000/000/002.jpeg')
コード例 #29
0
 def test_get_featureinfo(self):
     fi_body = "<a><b>Bar</b></a>"
     expected_req = ({'path': r'/service_a?LAYERs=a_one&SERVICE=WMS&FORMAT=image%2Fpng'
                               '&REQUEST=GetFeatureInfo&HEIGHT=200&CRS=EPSG%3A900913'
                               '&VERSION=1.3.0&BBOX=1000.0,400.0,2000.0,1400.0&styles='
                               '&WIDTH=200&QUERY_LAYERS=a_one&i=10&J=20&info_format=text/xml'},
                     {'body': fi_body, 'headers': {'content-type': 'text/xml'}})
     with mock_httpd(('localhost', 42423), [expected_req]):
         resp = self.app.get(self.common_fi_req)
         eq_(resp.content_type, 'application/vnd.ogc.gml')
         eq_(strip_whitespace(resp.body), '<bars><bar>Bar</bar></bars>')
コード例 #30
0
ファイル: test_kml.py プロジェクト: ChrisRenton/mapproxy
 def test_get_tile(self):
     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=256&SRS=EPSG%3A900913&styles='
                                   '&VERSION=1.1.1&BBOX=-20037508.3428,-20037508.3428,0.0,0.0'
                                   '&WIDTH=256'},
                         {'body': img.read(), 'headers': {'content-type': 'image/jpeg'}})
         with mock_httpd(('localhost', 42423), [expected_req]):
             resp = self.app.get('/kml/wms_cache/1/0/0.jpeg')
             eq_(resp.content_type, 'image/jpeg')
             self.created_tiles.append('wms_cache_EPSG900913/01/000/000/000/000/000/000.jpeg')
コード例 #31
0
ファイル: test_arcgis.py プロジェクト: zstadler/mapproxy
    def test_transformed_identify(self):
        expected_req = [
            ({
                'path':
                '/arcgis/rest/services/ExampleLayer/MapServer/identify?f=json&'
                'geometry=573295.377585,6927820.884193&returnGeometry=true&imageDisplay=200,321,96'
                '&mapExtent=556597.453966,6446275.84102,890555.926346,6982997.92039&layers=show:1,2,3'
                '&tolerance=10&geometryType=esriGeometryPoint&sr=3857'
            }, {
                'body': b'{"results": []}',
                'headers': {
                    'content-type': 'application/json'
                }
            }),
        ]

        with mock_httpd(('localhost', 42423), expected_req):
            self.common_fi_req.params.bbox = '5,50,8,53'
            self.common_fi_req.params.srs = 'EPSG:4326'
            resp = self.app.get(self.common_fi_req)
            eq_(resp.content_type, 'application/json')
            eq_(resp.content_length, len(resp.body))
            eq_(resp.body, b'{"results": []}')
コード例 #32
0
ファイル: test_arcgis.py プロジェクト: zstadler/mapproxy
    def test_identify(self):
        expected_req = [
            ({
                'path':
                '/arcgis/rest/services/ExampleLayer/MapServer/identify?f=json&'
                'geometry=1050.000000,1300.000000&returnGeometry=true&imageDisplay=200,200,96'
                '&mapExtent=1000.0,400.0,2000.0,1400.0&layers=show:1,2,3'
                '&tolerance=10&geometryType=esriGeometryPoint&sr=3857'
            }, {
                'body': b'{"results": []}',
                'headers': {
                    'content-type': 'application/json'
                }
            }),
        ]

        with mock_httpd(('localhost', 42423),
                        expected_req,
                        bbox_aware_query_comparator=True):
            resp = self.app.get(self.common_fi_req)
            eq_(resp.content_type, 'application/json')
            eq_(resp.content_length, len(resp.body))
            eq_(resp.body, b'{"results": []}')
コード例 #33
0
 def check_get_cached(self, layer, source, wms_format, cache_format,
                      req_format):
     self.created_tiles.append(
         (layer + '_EPSG900913/01/000/000/001/000/000/001.' + cache_format,
          cache_format))
     with tmp_image((256, 256), format=req_format) as img:
         expected_req = ({
             'path':
             self.expected_base_path + '&layers=' + source +
             '&format=image%2F' + req_format
         }, {
             'body': img.read(),
             'headers': {
                 'content-type': 'image/' + req_format
             }
         })
         with mock_httpd(('localhost', 42423), [expected_req],
                         bbox_aware_query_comparator=True):
             self.common_map_req.params['layers'] = layer
             self.common_map_req.params['format'] = 'image/' + wms_format
             resp = self.app.get(self.common_map_req)
             eq_(resp.content_type, 'image/' + wms_format)
             check_format(BytesIO(resp.body), wms_format)
コード例 #34
0
ファイル: test_source_errors.py プロジェクト: wkke/mapproxy
    def test_online(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')

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

        with mock_httpd(('localhost', 42423), expected_req):
            self.common_map_req.params.layers = 'online'
            resp = self.app.get(self.common_map_req)
            assert 'Cache-Control' not in resp.headers
            eq_(resp.content_type, 'image/png')
            assert is_transparent(resp.body)
コード例 #35
0
ファイル: test_source_errors.py プロジェクト: wkke/mapproxy
    def test_mixed_layer_source(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')

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

        with mock_httpd(('localhost', 42423), expected_req):
            self.common_map_req.params.layers = 'mixed'
            resp = self.app.get(self.common_map_req)
            assert_no_cache(resp)
            eq_(resp.content_type, 'image/png')
            assert 0.99 > bgcolor_ratio(resp.body) > 0.95
コード例 #36
0
    def test_tile_cached_response(self, app, cache_dir):
        expected_req = [(
            {
                "path": "/foo/1/1/0.png"
            },
            {
                "body": b"no content",
                "status": 204,
                "headers": {
                    "content-type": "text/plain"
                },
            },
        )]

        with mock_httpd(("localhost", 42423), expected_req):
            resp = app.get(self.common_tile_req)
            assert "public" in resp.headers["Cache-Control"]
            assert resp.content_type == "image/png"
            img = img_from_buf(resp.body)
            assert img.getcolors() == [(256 * 256, (100, 200, 50, 250))]
            assert cache_dir.join(
                "tilesource_cache_EPSG4326/01/000/000/001/000/000/000.png"
            ).check()
コード例 #37
0
 def test_get_tile(self, app, cache_dir):
     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=256&SRS=EPSG%3A900913&styles="
                 "&VERSION=1.1.1&BBOX=-20037508.3428,-20037508.3428,0.0,0.0"
                 "&WIDTH=256"
             },
             {
                 "body": img.read(),
                 "headers": {
                     "content-type": "image/jpeg"
                 }
             },
         )
         with mock_httpd(("localhost", 42423), [expected_req],
                         bbox_aware_query_comparator=True):
             resp = app.get("/tms/1.0.0/wms_cache/0/0/0.jpeg")
             assert resp.content_type == "image/jpeg"
     assert cache_dir.join(
         "wms_cache_EPSG900913/01/000/000/000/000/000/000.jpeg").check()
コード例 #38
0
ファイル: test_formats.py プロジェクト: yili9111/mapproxy
 def test_get_direct(self, app, layer, source, wms_format, req_format):
     with tmp_image((256, 256), format=req_format) as img:
         expected_req = (
             {
                 "path":
                 self.expected_direct_base_path + "&layers=" + source +
                 "&format=image%2F" + req_format
             },
             {
                 "body": img.read(),
                 "headers": {
                     "content-type": "image/" + req_format
                 },
             },
         )
         with mock_httpd(("localhost", 42423), [expected_req],
                         bbox_aware_query_comparator=True):
             self.common_direct_map_req.params["layers"] = layer
             self.common_direct_map_req.params[
                 "format"] = "image/" + wms_format
             resp = app.get(self.common_direct_map_req)
             assert resp.content_type == "image/" + wms_format
             check_format(BytesIO(resp.body), wms_format)
コード例 #39
0
 def test_get_tile_no_grid_name(self):
     # access tiles with grid name from TMS but cache still uses old SRS-code path
     with tmp_image((256, 256), format='jpeg') as img:
         expected_req = ({
             'path':
             r'/service?LAYERs=bar&SERVICE=WMS&FORMAT=image%2Fjpeg'
             '&REQUEST=GetMap&HEIGHT=256&SRS=EPSG%3A25832&styles='
             '&VERSION=1.1.1&BBOX=283803.311362,5609091.90862,319018.942566,5644307.53982'
             '&WIDTH=256'
         }, {
             'body': img.read(),
             'headers': {
                 'content-type': 'image/jpeg'
             }
         })
         with mock_httpd(('localhost', 42423), [expected_req],
                         bbox_aware_query_comparator=True):
             resp = self.app.get(
                 '/tms/1.0.0/wms_cache_no_grid_name/utm32n/4/2/2.jpeg')
             eq_(resp.content_type, 'image/jpeg')
             self.created_tiles.append(
                 'wms_cache_no_grid_name_EPSG25832/04/000/000/002/000/000/002.jpeg'
             )
コード例 #40
0
 def test_get_tile(self, app, cache_dir):
     with tmp_image((256, 256), format="jpeg") as img:
         expected_req = (
             {
                 "path":
                 r"/service?LAYERs=bar&SERVICE=WMS&FORMAT=image%2Fjpeg"
                 "&REQUEST=GetMap&HEIGHT=256&SRS=EPSG%3A25832&styles="
                 "&VERSION=1.1.1&&WIDTH=256"
                 "&BBOX=283803.311362,5609091.90862,319018.942566,5644307.53982"
             },
             {
                 "body": img.read(),
                 "headers": {
                     "content-type": "image/jpeg"
                 }
             },
         )
         with mock_httpd(("localhost", 42423), [expected_req],
                         bbox_aware_query_comparator=True):
             resp = app.get("/tms/1.0.0/wms_cache/utm32n/4/2/2.jpeg")
             assert resp.content_type == "image/jpeg"
     assert cache_dir.join(
         "wms_cache/utm32n/04/000/000/002/000/000/002.jpeg").check()
コード例 #41
0
 def test_get_featureinfo_130(self, app):
     fi_body = b"<a><b>Bar</b></a>"
     expected_req = (
         {
             "path":
             r"/service_a?LAYERs=a_one&SERVICE=WMS&FORMAT=image%2Fpng"
             "&REQUEST=GetFeatureInfo&HEIGHT=200&CRS=EPSG%3A900913"
             "&VERSION=1.3.0&BBOX=1000.0,400.0,2000.0,1400.0&styles="
             "&WIDTH=200&QUERY_LAYERS=a_one&i=10&J=20&info_format=text/xml"
         },
         {
             "body": fi_body,
             "headers": {
                 "content-type": "text/xml"
             }
         },
     )
     with mock_httpd(TESTSERVER_ADDRESS, [expected_req]):
         req = WMS130FeatureInfoRequest(
             url="/service?").copy_with_request_params(self.common_fi_req)
         resp = app.get(req)
         assert resp.content_type == "text/xml"
         assert strip_whitespace(resp.body) == b"<baz><foo>Bar</foo></baz>"
コード例 #42
0
    def test_tile_uncached_response(self, app, cache_dir):
        expected_req = [(
            {
                "path": "/foo/1/1/0.png"
            },
            {
                "body": b"not found",
                "status": 404,
                "headers": {
                    "content-type": "text/plain"
                },
            },
        )]

        with mock_httpd(("localhost", 42423), expected_req):
            resp = app.get(self.common_tile_req)
            assert_no_cache(resp)
            assert resp.content_type == "image/png"
            img = img_from_buf(resp.body)
            assert img.getcolors() == [(256 * 256, (255, 0, 128))]
            assert not cache_dir.join(
                "tilesource_cache_EPSG4326/01/000/000/001/000/000/000.png"
            ).check()
コード例 #43
0
ファイル: test_coverage.py プロジェクト: yili9111/mapproxy
 def test_get_tile_intersections(self, app, cache_dir):
     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=25&SRS=EPSG%3A900913&styles="
                 "&VERSION=1.1.1&BBOX=1113194.90793,1689200.13961,3339584.7238,3632749.14338"
                 "&WIDTH=28"
             },
             {
                 "body": img.read(),
                 "headers": {
                     "content-type": "image/jpeg"
                 }
             },
         )
         with mock_httpd(("localhost", 42423), [expected_req],
                         bbox_aware_query_comparator=True):
             resp = app.get("/tms/1.0.0/wms_cache/0/1/1.jpeg")
             assert resp.content_type == "image/jpeg"
     cache_dir.join(
         "wms_cache_EPSG900913/01/000/000/001/000/000/001.jpeg").check()
コード例 #44
0
    def test_mixed_mode(self):
        with create_mixed_mode_img((512, 256)) as img:
            expected_req = ({
                'path':
                self.expected_base_path + '&layers=mixedsource' +
                '&format=image%2Fpng' + '&transparent=True'
            }, {
                'body': img.read(),
                'headers': {
                    'content-type': 'image/png'
                }
            })
            with mock_httpd(('localhost', 42423), [expected_req]):
                resp = self.app.get('/tms/1.0.0/mixed_mode/0/0/0.png')
                eq_(resp.content_type, 'image/png')
                assert is_transparent(resp.body)

                resp = self.app.get('/tms/1.0.0/mixed_mode/0/1/0.png')
                eq_(resp.content_type, 'image/jpeg')
                self.created_tiles.append(
                    'mixed_cache_EPSG900913/01/000/000/000/000/000/000.mixed')
                self.created_tiles.append(
                    'mixed_cache_EPSG900913/01/000/000/001/000/000/000.mixed')
コード例 #45
0
    def test_get_map_through_cache(self):
        map_req = WMS111MapRequest(
            url='/service?',
            param=dict(
                service='WMS',
                version='1.1.1',
                width='100',
                height='100',
                bbox='432890.564641,5872387.45834,466833.867667,5928359.08814',
                layers='tms_transf',
                srs='EPSG:25832',
                format='image/png',
                styles='',
                request='GetMap'))

        expected_reqs = []
        with tmp_image((256, 256), format='jpeg') as img:
            img = img.read()
            # tms_cache_out has meta_size of [2, 2] but we need larger extent for transformation
            for tile in [(132, 172, 8), (133, 172, 8), (134, 172, 8),
                         (132, 173, 8), (133, 173, 8), (134, 173, 8),
                         (132, 174, 8), (133, 174, 8), (134, 174, 8)]:
                expected_reqs.append(({
                    'path':
                    r'/tiles/%02d/000/000/%03d/000/000/%03d.png' %
                    (tile[2], tile[0], tile[1])
                }, {
                    'body': img,
                    'headers': {
                        'content-type': 'image/png'
                    }
                }))
            with mock_httpd(('localhost', 42423),
                            expected_reqs,
                            unordered=True):
                resp = self.app.get(map_req)
                eq_(resp.content_type, 'image/png')
コード例 #46
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)))
コード例 #47
0
ファイル: test_arcgis.py プロジェクト: yili9111/mapproxy
    def test_identify(self, app):
        expected_req = [(
            {
                "path":
                "/arcgis/rest/services/ExampleLayer/MapServer/identify?f=json&"
                "geometry=1050.000000,1300.000000&returnGeometry=true&imageDisplay=200,200,96"
                "&mapExtent=1000.0,400.0,2000.0,1400.0&layers=show:1,2,3"
                "&tolerance=10&geometryType=esriGeometryPoint&sr=3857"
            },
            {
                "body": b'{"results": []}',
                "headers": {
                    "content-type": "application/json"
                },
            },
        )]

        with mock_httpd(("localhost", 42423),
                        expected_req,
                        bbox_aware_query_comparator=True):
            resp = app.get(self.common_fi_req)
            assert resp.content_type == "application/json"
            assert resp.content_length == len(resp.body)
            assert resp.body == b'{"results": []}'
コード例 #48
0
ファイル: test_arcgis.py プロジェクト: yili9111/mapproxy
    def test_transformed_identify(self, app):
        expected_req = [(
            {
                "path":
                "/arcgis/rest/services/ExampleLayer/MapServer/identify?f=json&"
                "geometry=573295.377585,6927820.884193&returnGeometry=true&imageDisplay=200,321,96"
                "&mapExtent=556597.453966,6446275.84102,890555.926346,6982997.92039&layers=show:1,2,3"
                "&tolerance=10&geometryType=esriGeometryPoint&sr=3857"
            },
            {
                "body": b'{"results": []}',
                "headers": {
                    "content-type": "application/json"
                },
            },
        )]

        with mock_httpd(("localhost", 42423), expected_req):
            self.common_fi_req.params.bbox = "5,50,8,53"
            self.common_fi_req.params.srs = "EPSG:4326"
            resp = app.get(self.common_fi_req)
            assert resp.content_type == "application/json"
            assert resp.content_length == len(resp.body)
            assert resp.body == b'{"results": []}'
コード例 #49
0
ファイル: test_source_errors.py プロジェクト: wkke/mapproxy
    def test_tile_uncached_response(self):
        expected_req = [
            ({
                'path': '/foo/1/1/0.png'
            }, {
                'body': b'not found',
                'status': 404,
                'headers': {
                    'content-type': 'text/plain'
                }
            }),
        ]

        with mock_httpd(('localhost', 42423), expected_req):
            resp = self.app.get(self.common_tile_req)
            assert_no_cache(resp)
            eq_(resp.content_type, 'image/png')
            img = img_from_buf(resp.body)
            eq_(img.getcolors(), [(256 * 256, (255, 0, 128))])
            assert not os.path.exists(
                os.path.join(
                    self.base_config().cache.base_dir,
                    'tilesource_cache_EPSG4326/01/000/000/001/000/000/000.png')
            )
コード例 #50
0
ファイル: test_watermark.py プロジェクト: yili9111/mapproxy
 def test_watermark_tile(self, app):
     with tmp_image((256, 256), format="png", color=(0, 0, 0)) as img:
         expected_req = (
             {
                 "path":
                 r"/service?LAYERs=blank&SERVICE=WMS&FORMAT=image%2Fpng"
                 "&REQUEST=GetMap&HEIGHT=256&SRS=EPSG%3A4326&styles="
                 "&VERSION=1.1.1&BBOX=-180.0,-90.0,0.0,90.0"
                 "&WIDTH=256"
             },
             {
                 "body": img.read(),
                 "headers": {
                     "content-type": "image/jpeg"
                 }
             },
         )
         with mock_httpd(("localhost", 42423), [expected_req]):
             resp = app.get("/tms/1.0.0/watermark/EPSG4326/0/0/0.png")
             assert resp.content_type == "image/png"
             img = Image.open(BytesIO(resp.body))
             colors = img.getcolors()
             assert len(colors) >= 2
             assert sorted(colors)[-1][1] == (0, 0, 0)
コード例 #51
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')
コード例 #52
0
ファイル: test_seed.py プロジェクト: yili9111/mapproxy
    def test_reseed_mbtiles_with_refresh(self):
        seed_conf = load_seed_tasks_conf(self.seed_conf_file,
                                         self.mapproxy_conf)
        tasks, cleanup_tasks = seed_conf.seeds([
            'mbtile_cache_refresh'
        ]), seed_conf.cleanups(['cleanup_mbtile_cache'])

        cache = tasks[0].tile_manager.cache
        cache.store_tile(self.create_tile())

        expected_req = ({
            'path':
            r'/service?LAYERS=bar&SERVICE=WMS&FORMAT=image%2Fpng'
            '&REQUEST=GetMap&VERSION=1.1.1&bbox=-180.0,-90.0,180.0,90.0'
            '&width=256&height=128&srs=EPSG:4326'
        }, {
            'body': tile_image,
            'headers': {
                'content-type': 'image/png'
            }
        })
        with mock_httpd(('localhost', 42423), [expected_req]):
            # mbtiles does not support timestamps, refresh all tiles
            seed(tasks, dry_run=False)
コード例 #53
0
ファイル: test_client.py プロジェクト: yili9111/mapproxy
    def test_manage_cookies_on(self):
        """
        Test behavior of manage_cookies=True. Once the remote server sends a cookie back, it should
        be included in future requests
        """
        self.client = HTTPClient(manage_cookies=True)

        def assert_no_cookie(req_handler):
            return 'Cookie' not in req_handler.headers

        def assert_cookie(req_handler):
            assert 'Cookie' in req_handler.headers
            cookie_name, cookie_val = req_handler.headers['Cookie'].split(
                ';')[0].split('=')
            assert cookie_name == 'testcookie'
            assert cookie_val == '42'
            return True

        test_requests = [({
            'path': '/',
            'req_assert_function': assert_no_cookie
        }, {
            'body': b'nothing',
            'headers': {
                'Set-Cookie': "testcookie=42"
            }
        }),
                         ({
                             'path': '/',
                             'req_assert_function': assert_cookie
                         }, {
                             'body': b'nothing'
                         })]
        with mock_httpd(TESTSERVER_ADDRESS, test_requests):
            self.client.open(TESTSERVER_URL + '/')
            self.client.open(TESTSERVER_URL + '/')
コード例 #54
0
 def test_mixed_featureinfo(self):
     fi_body1 = b"Hello"
     fi_body2 = b"<a><b>Bar2</b></a>"
     expected_req1 = ({
         'path':
         r'/service_c?LAYERs=c_one&SERVICE=WMS&FORMAT=image%2Fpng'
         '&REQUEST=GetFeatureInfo&HEIGHT=200&SRS=EPSG%3A900913'
         '&VERSION=1.1.1&BBOX=1000.0,400.0,2000.0,1400.0&styles='
         '&WIDTH=200&QUERY_LAYERS=c_one&X=10&Y=20'
     }, {
         'body': fi_body1,
         'headers': {
             'content-type': 'text/plain'
         }
     })
     expected_req2 = ({
         'path':
         r'/service_a?LAYERs=a_one&SERVICE=WMS&FORMAT=image%2Fpng'
         '&REQUEST=GetFeatureInfo&HEIGHT=200&CRS=EPSG%3A900913'
         '&VERSION=1.3.0&BBOX=1000.0,400.0,2000.0,1400.0&styles='
         '&WIDTH=200&QUERY_LAYERS=a_one&i=10&J=20&info_format=text/xml'
     }, {
         'body': fi_body2,
         'headers': {
             'content-type': 'text/xml'
         }
     })
     with mock_httpd(('localhost', 42423), [expected_req1, expected_req2]):
         self.common_fi_req.params[
             'layers'] = 'fi_without_xslt_layer,fi_layer'
         self.common_fi_req.params[
             'query_layers'] = 'fi_without_xslt_layer,fi_layer'
         resp = self.app.get(self.common_fi_req)
         eq_(resp.content_type, 'text/plain')
         eq_(strip_whitespace(resp.body),
             b'Hello<baz><foo>Bar2</foo></baz>')
コード例 #55
0
    def test_mixed_mode(self):
        req_format = 'png'
        transparent = 'True'
        with create_mixed_mode_img((512, 256)) as img:
            expected_req = ({'path': self.expected_base_path +
                                     '&layers=mixedsource' +
                                     '&format=image%2F' + req_format +
                                     '&transparent=' + transparent},
                            {'body': img.read(), 'headers': {'content-type': 'image/'+req_format}})
            with mock_httpd(('localhost', 42423), [expected_req], bbox_aware_query_comparator=True):
                self.common_map_req.params['format'] = 'image/'+req_format
                resp = self.app.get(self.common_map_req)
                self.created_tiles.append('mixed_cache_EPSG900913/01/000/000/000/000/000/001.mixed')
                self.created_tiles.append('mixed_cache_EPSG900913/01/000/000/001/000/000/001.mixed')

                eq_(resp.content_type, 'image/'+req_format)
                check_format(BytesIO(resp.body), req_format)
                # GetMap Request is fully within the opaque tile
                assert not is_transparent(resp.body)

                # check cache formats
                cache_dir = base_config().cache.base_dir
                check_format(open(os.path.join(cache_dir, self.created_tiles[0]), 'rb'), 'png')
                check_format(open(os.path.join(cache_dir, self.created_tiles[1]), 'rb'), 'jpeg')
コード例 #56
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)
コード例 #57
0
    def test_mixed_layer_source(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")

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

        with mock_httpd(("localhost", 42423), expected_req):
            self.common_map_req.params.layers = "mixed"
            resp = app.get(self.common_map_req)
            assert_no_cache(resp)
            assert resp.content_type == "image/png"
            assert 0.99 > bgcolor_ratio(resp.body) > 0.95
コード例 #58
0
    def test_online(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")

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

        with mock_httpd(("localhost", 42423), expected_req):
            self.common_map_req.params.layers = "online"
            resp = app.get(self.common_map_req)
            assert "Cache-Control" not in resp.headers
            assert resp.content_type == "image/png"
            assert is_transparent(resp.body)
コード例 #59
0
ファイル: test_http_helper.py プロジェクト: yili9111/mapproxy
 def test_no_requests(self):
     with mock_httpd(('localhost', 42423), []):
         pass
コード例 #60
0
ファイル: test_seed.py プロジェクト: yili9111/mapproxy
    def test_seed_refresh_remove_before_from_file(self):
        # tile already there but old
        t000 = self.make_tile((0, 0, 0),
                              timestamp=time.time() - (60 * 60 * 25))

        # mtime is older than tile, no create of the tile
        timestamp = time.time() - (60 * 60 * 30)
        os.utime(self.seed_conf_file, (timestamp, timestamp))
        with local_base_config(self.mapproxy_conf.base_config):
            seed_conf = load_seed_tasks_conf(self.seed_conf_file,
                                             self.mapproxy_conf)
            tasks = seed_conf.seeds(['refresh_from_file'])
            seed(tasks, dry_run=False)

        # touch the seed_conf file and refresh everything
        os.utime(self.seed_conf_file, None)
        img_data = create_tmp_image((256, 256), format='png')
        expected_req = ({
            'path':
            r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
            '&REQUEST=GetMap&VERSION=1.1.1&bbox=-180.0,-90.0,180.0,90.0'
            '&width=256&height=128&srs=EPSG:4326'
        }, {
            'body': img_data,
            'headers': {
                'content-type': 'image/png'
            }
        })
        with mock_httpd(('localhost', 42423), [expected_req]):
            # touch the seed_conf file and refresh everything
            timestamp = time.time() - 60
            os.utime(self.seed_conf_file, (timestamp, timestamp))

            with local_base_config(self.mapproxy_conf.base_config):
                seed_conf = load_seed_tasks_conf(self.seed_conf_file,
                                                 self.mapproxy_conf)
                tasks = seed_conf.seeds(['refresh_from_file'])
                seed(tasks, dry_run=False)

                assert os.path.exists(t000)
                assert os.path.getmtime(t000) - 5 < time.time(
                ) < os.path.getmtime(t000) + 5

        # mtime is older than tile, no cleanup
        timestamp = time.time() - 5
        os.utime(self.seed_conf_file, (timestamp, timestamp))
        with local_base_config(self.mapproxy_conf.base_config):
            seed_conf = load_seed_tasks_conf(self.seed_conf_file,
                                             self.mapproxy_conf)
            cleanup_tasks = seed_conf.cleanups(['remove_from_file'])
            cleanup(cleanup_tasks, verbose=False, dry_run=False)
        assert os.path.exists(t000)

        # now touch the seed_conf again and remove everything
        timestamp = time.time() + 5
        os.utime(self.seed_conf_file, (timestamp, timestamp))
        with local_base_config(self.mapproxy_conf.base_config):
            seed_conf = load_seed_tasks_conf(self.seed_conf_file,
                                             self.mapproxy_conf)
            cleanup_tasks = seed_conf.cleanups(['remove_from_file'])
            cleanup(cleanup_tasks, verbose=False, dry_run=False)
        assert not os.path.exists(t000)