def test_get_map_authorized_global_limited(self): def auth(service, layers, query_extent, **kw): eq_(query_extent, ('EPSG:4326', (-80.0, -40.0, 0.0, 0.0))) eq_(service, 'wms.map') eq_(len(layers), 1) return { 'authorized': 'partial', 'limited_to': { 'srs': 'EPSG:4326', 'geometry': [-20.0, -40.0, 0.0, 0.0] }, 'layers': { 'layer1': { 'map': True, 'limited_to': { 'srs': 'EPSG:4326', 'geometry': [-40.0, -40.0, 0.0, 0.0] }, }, } } resp = self.app.get(MAP_REQ + 'layers=layer1', extra_environ={'mapproxy.authorize': auth}) eq_(resp.content_type, 'image/png') img = img_from_buf(resp.body) # left part not authorized, only bgcolor assert len(img.crop((0, 0, 100, 100)).getcolors()) == 1 # right part authorized, bgcolor + text assert len(img.crop((100, 0, 200, 100)).getcolors()) >= 2
def test_get_tile_limited_to_inside(self): def auth(service, layers, environ, **kw): eq_(environ['PATH_INFO'], '/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg') eq_(service, 'wmts') eq_(len(layers), 1) return { 'authorized': 'partial', 'limited_to': { 'geometry': [-180, -89, 180, 89], 'srs': 'EPSG:4326', }, 'layers': { 'layer3': {'tile': True}, } } serv = MockServ(port=42423) serv.expects('/1/0/1.png') serv.returns(create_tmp_image((256, 256), color=(255, 0, 0)), headers={'content-type': 'image/png'}) with serv: resp = self.app.get('/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg', extra_environ={'mapproxy.authorize': auth}) eq_(resp.content_type, 'image/jpeg') img = img_from_buf(resp.body) eq_(img.getcolors()[0], (256*256, (255, 0, 0)))
def test_get_tile_limited_to_inside(self): def auth(service, layers, environ, **kw): eq_(environ['PATH_INFO'], '/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg') eq_(service, 'wmts') eq_(len(layers), 1) return { 'authorized': 'partial', 'limited_to': { 'geometry': [-180, -89, 180, 89], 'srs': 'EPSG:4326', }, 'layers': { 'layer3': { 'tile': True }, } } serv = MockServ(port=42423) serv.expects('/1/0/1.png') serv.returns(create_tmp_image((256, 256), color=(255, 0, 0)), headers={'content-type': 'image/png'}) with serv: resp = self.app.get('/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg', extra_environ={'mapproxy.authorize': auth}) eq_(resp.content_type, 'image/jpeg') img = img_from_buf(resp.body) eq_(img.getcolors()[0], (256 * 256, (255, 0, 0)))
def test_clipped_bgcolor(self): with tmp_image((256, 256), format='png', color=(255, 0, 0)) as img: expected_req = ({ 'path': r'/service?LAYERs=bar&SERVICE=WMS&FORMAT=image%2Fpng' '&REQUEST=GetMap&HEIGHT=100&SRS=EPSG%3A25832&styles=' '&VERSION=1.1.1&BBOX=0.0,3500000.0,100.0,3500100.0' '&WIDTH=50' }, { 'body': img.read(), 'headers': { 'content-type': 'image/png' } }) with mock_httpd(('localhost', 42423), [expected_req]): resp = self.app.get( 'http://localhost/service?SERVICE=WMS&REQUEST=GetMap' '&LAYERS=direct&STYLES=' '&WIDTH=100&HEIGHT=100&FORMAT=image/png' '&BBOX=-100,3500000,100,3500100&SRS=EPSG:25832' '&VERSION=1.1.0&TRANSPARENT=FALSE&BGCOLOR=0x00ff00') eq_(resp.content_type, 'image/png') assert is_png(resp.body) assert_colors_equal( img_from_buf(resp.body).convert('RGBA'), [(50 * 100, [255, 0, 0, 255]), (50 * 100, [0, 255, 0, 255])])
def test_clipped(self): with tmp_image((256, 256), format='png', color=(255, 0, 0)) as img: expected_req = ({ 'path': r'/service?LAYERs=bar&SERVICE=WMS&FORMAT=image%2Fpng' '&REQUEST=GetMap&HEIGHT=100&SRS=EPSG%3A25832&styles=' '&VERSION=1.1.1&BBOX=0.0,3500000.0,150.0,3500100.0' '&WIDTH=75' }, { 'body': img.read(), 'headers': { 'content-type': 'image/png' } }) with mock_httpd(('localhost', 42423), [expected_req]): resp = self.app.get( 'http://localhost/service?SERVICE=WMS&REQUEST=GetMap' '&LAYERS=direct&STYLES=' '&WIDTH=100&HEIGHT=100&FORMAT=image/png' '&BBOX=-50,3500000,150,3500100&SRS=EPSG:25832' '&VERSION=1.1.0&TRANSPARENT=TRUE') eq_(resp.content_type, 'image/png') assert is_png(resp.body) colors = sorted( img_from_buf(resp.body).convert('RGBA').getcolors()) # quarter is clipped, check if it's transparent eq_(colors[0][0], (25 * 100)) eq_(colors[0][1][3], 0) eq_(colors[1], (75 * 100, (255, 0, 0, 255)))
def test_clipped(self, app): with tmp_image((256, 256), format="png", color=(255, 0, 0)) as img: expected_req = ( { "path": r"/service?LAYERs=bar&SERVICE=WMS&FORMAT=image%2Fpng" "&REQUEST=GetMap&HEIGHT=100&SRS=EPSG%3A25832&styles=" "&VERSION=1.1.1&BBOX=0.0,3500000.0,150.0,3500100.0" "&WIDTH=75" }, { "body": img.read(), "headers": { "content-type": "image/png" } }, ) with mock_httpd(("localhost", 42423), [expected_req]): resp = app.get( "http://localhost/service?SERVICE=WMS&REQUEST=GetMap" "&LAYERS=direct&STYLES=" "&WIDTH=100&HEIGHT=100&FORMAT=image/png" "&BBOX=-50,3500000,150,3500100&SRS=EPSG:25832" "&VERSION=1.1.0&TRANSPARENT=TRUE") assert resp.content_type == "image/png" assert is_png(resp.body) colors = sorted( img_from_buf(resp.body).convert("RGBA").getcolors()) # quarter is clipped, check if it's transparent assert colors[0][0] == (25 * 100) assert colors[0][1][3] == 0 assert colors[1] == (75 * 100, (255, 0, 0, 255))
def test_clipped_bgcolor(self, app): with tmp_image((256, 256), format="png", color=(255, 0, 0)) as img: expected_req = ( { "path": r"/service?LAYERs=bar&SERVICE=WMS&FORMAT=image%2Fpng" "&REQUEST=GetMap&HEIGHT=100&SRS=EPSG%3A25832&styles=" "&VERSION=1.1.1&BBOX=0.0,3500000.0,100.0,3500100.0" "&WIDTH=50" }, { "body": img.read(), "headers": { "content-type": "image/png" } }, ) with mock_httpd(("localhost", 42423), [expected_req]): resp = app.get( "http://localhost/service?SERVICE=WMS&REQUEST=GetMap" "&LAYERS=direct&STYLES=" "&WIDTH=100&HEIGHT=100&FORMAT=image/png" "&BBOX=-100,3500000,100,3500100&SRS=EPSG:25832" "&VERSION=1.1.0&TRANSPARENT=FALSE&BGCOLOR=0x00ff00") assert resp.content_type == "image/png" assert is_png(resp.body) assert_colors_equal( img_from_buf(resp.body).convert("RGBA"), [(50 * 100, [255, 0, 0, 255]), (50 * 100, [0, 255, 0, 255])], )
def test_get_tile_limited_to(self): def auth(service, layers, environ, query_extent, **kw): eq_(environ['PATH_INFO'], '/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg') eq_(service, 'wmts') eq_(len(layers), 1) eq_(query_extent[0], 'EPSG:900913') assert bbox_equals(query_extent[1], (-20037508.342789244, 0, 0, 20037508.342789244)) return { 'authorized': 'partial', 'limited_to': { 'geometry': [-180, -89, -90, 89], 'srs': 'EPSG:4326', }, 'layers': { 'layer3': {'tile': True}, } } serv = MockServ(port=42423) serv.expects('/1/0/1.png') serv.returns(create_tmp_image((256, 256), color=(255, 0, 0)), headers={'content-type': 'image/png'}) with serv: resp = self.app.get('/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg', extra_environ={'mapproxy.authorize': auth}) eq_(resp.content_type, 'image/png') img = img_from_buf(resp.body) img = img.convert('RGBA') # left part authorized, red eq_(img.crop((0, 0, 127, 255)).getcolors()[0], (127*255, (255, 0, 0, 255))) # right part not authorized, transparent eq_(img.crop((129, 0, 255, 255)).getcolors()[0][1][3], 0)
def check_get_tile_limited_to(self, auth_dict): def auth(service, layers, environ, query_extent, **kw): eq_(environ['PATH_INFO'], '/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg') eq_(service, 'wmts') eq_(len(layers), 1) eq_(query_extent[0], 'EPSG:900913') assert bbox_equals(query_extent[1], (-20037508.342789244, 0, 0, 20037508.342789244)) return auth_dict serv = MockServ(port=42423) serv.expects('/1/0/1.png') serv.returns(create_tmp_image((256, 256), color=(255, 0, 0)), headers={'content-type': 'image/png'}) with serv: resp = self.app.get('/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg', extra_environ={'mapproxy.authorize': auth}) eq_(resp.content_type, 'image/png') img = img_from_buf(resp.body) img = img.convert('RGBA') # left part authorized, red eq_( img.crop((0, 0, 127, 255)).getcolors()[0], (127 * 255, (255, 0, 0, 255))) # right part not authorized, transparent eq_(img.crop((129, 0, 255, 255)).getcolors()[0][1][3], 0)
def test_get_map_l_jpeg(self): self.common_map_req.params.format = 'image/jpeg' resp = self.app.get(str(self.common_map_req)) eq_(resp.content_type, 'image/jpeg') img = img_from_buf(resp.body) eq_(img.mode, 'RGB') # L converted to RGB for jpeg eq_(img.getpixel((0, 0)), (92, 92, 92))
def test_get_map_l_jpeg(self, app): self.common_map_req.params.format = "image/jpeg" resp = app.get(str(self.common_map_req)) assert resp.content_type == "image/jpeg" img = img_from_buf(resp.body) assert img.mode == "RGB" # L converted to RGB for jpeg assert img.getpixel((0, 0)) == (92, 92, 92)
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))])
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])])
def test_tile_cached_response(self): expected_req = [({'path': '/foo/1/1/0.png'}, {'body': 'no content', 'status': 204, 'headers': {'content-type': 'text/plain'}}), ] with mock_httpd(('localhost', 42423), expected_req): resp = self.app.get(self.common_tile_req) assert 'public' in resp.headers['Cache-Control'] eq_(resp.content_type, 'image/png') img = img_from_buf(resp.body) eq_(img.getcolors(), [(256 * 256, (100, 200, 50, 250))]) self.created_tiles.append('tilesource_cache_EPSG4326/01/000/000/001/000/000/000.png')
def test_out_of_extent_bgcolor(self, app): resp = 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 assert 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])])
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])])
def test_tile_uncached_response(self): expected_req = [({'path': '/foo/1/1/0.png'}, {'body': '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'))
def test_get_map(self): test_self = self class req_handler(BaseHTTPRequestHandler): def do_POST(self): length = int(self.headers['content-length']) json_data = self.rfile.read(length) task = json.loads(json_data) eq_(task['command'], 'tile') # request main tile of metatile eq_(task['tiles'], [[15, 17, 5]]) eq_(task['cache_identifier'], 'wms_cache_GLOBAL_MERCATOR') eq_(task['priority'], 100) # this id should not change for the same tile/cache_identifier combination eq_(task['id'], 'aeb52b506e4e82d0a1edf649d56e0451cfd5862c') # manually create tile renderd should create tile_filename = os.path.join( test_self.config['cache_dir'], 'wms_cache_EPSG900913/05/000/000/016/000/000/016.jpeg') ensure_directory(tile_filename) with open(tile_filename, 'w') as f: f.write( create_tmp_image((256, 256), format='jpeg', color=(255, 0, 100))) self.send_response(200) self.send_header('Content-type', 'application/json') self.end_headers() self.wfile.write('{"status": "ok"}') def log_request(self, code, size=None): pass with mock_single_req_httpd(('localhost', 42423), req_handler): self.common_map_req.params['bbox'] = '0,0,9,9' resp = self.app.get(self.common_map_req) img = img_from_buf(resp.body) main_color = sorted(img.convert('RGBA').getcolors())[-1] # check for red color (jpeg/png conversion requires fuzzy comparision) assert main_color[0] == 40000 assert main_color[1][0] > 250 assert main_color[1][1] < 5 assert 95 < main_color[1][2] < 105 assert main_color[1][3] == 255 eq_(resp.content_type, 'image/png') self.created_tiles.append( 'wms_cache_EPSG900913/05/000/000/016/000/000/016.jpeg')
def test_get_map(self, app, cache_dir): class req_handler(BaseHTTPRequestHandler): def do_POST(self): length = int(self.headers["content-length"]) json_data = self.rfile.read(length) task = json.loads(json_data.decode("utf-8")) assert task["command"] == "tile" # request main tile of metatile assert task["tiles"] == [[15, 17, 5]] assert task["cache_identifier"] == "wms_cache_GLOBAL_MERCATOR" assert task["priority"] == 100 # this id should not change for the same tile/cache_identifier combination assert task["id"] == "aeb52b506e4e82d0a1edf649d56e0451cfd5862c" # manually create tile renderd should create cache_dir.join( "wms_cache_EPSG900913/05/000/000/016/000/000/016.jpeg" ).write_binary( create_tmp_image((256, 256), format="jpeg", color=(255, 0, 100)), ensure=True, ) self.send_response(200) self.send_header("Content-type", "application/json") self.end_headers() self.wfile.write(b'{"status": "ok"}') def log_request(self, code, size=None): pass with mock_single_req_httpd(("localhost", 42423), req_handler): self.common_map_req.params["bbox"] = "0,0,9,9" resp = app.get(self.common_map_req) img = img_from_buf(resp.body) main_color = sorted(img.convert("RGBA").getcolors())[-1] # check for red color (jpeg/png conversion requires fuzzy comparision) assert main_color[0] == 40000 assert main_color[1][0] > 250 assert main_color[1][1] < 5 assert 95 < main_color[1][2] < 105 assert main_color[1][3] == 255 assert resp.content_type == "image/png" assert cache_dir.join( "wms_cache_EPSG900913/05/000/000/016/000/000/016.jpeg").check()
def test_get_map(self): test_self = self class req_handler(BaseHTTPRequestHandler): def do_POST(self): length = int(self.headers['content-length']) json_data = self.rfile.read(length) task = json.loads(json_data.decode('utf-8')) eq_(task['command'], 'tile') # request main tile of metatile eq_(task['tiles'], [[15, 17, 5]]) eq_(task['cache_identifier'], 'wms_cache_GLOBAL_MERCATOR') eq_(task['priority'], 100) # this id should not change for the same tile/cache_identifier combination eq_(task['id'], 'aeb52b506e4e82d0a1edf649d56e0451cfd5862c') # manually create tile renderd should create tile_filename = os.path.join(test_self.config['cache_dir'], 'wms_cache_EPSG900913/05/000/000/016/000/000/016.jpeg') ensure_directory(tile_filename) with open(tile_filename, 'wb') as f: f.write(create_tmp_image((256, 256), format='jpeg', color=(255, 0, 100))) self.send_response(200) self.send_header('Content-type', 'application/json') self.end_headers() self.wfile.write(b'{"status": "ok"}') def log_request(self, code, size=None): pass with mock_single_req_httpd(('localhost', 42423), req_handler): self.common_map_req.params['bbox'] = '0,0,9,9' resp = self.app.get(self.common_map_req) img = img_from_buf(resp.body) main_color = sorted(img.convert('RGBA').getcolors())[-1] # check for red color (jpeg/png conversion requires fuzzy comparision) assert main_color[0] == 40000 assert main_color[1][0] > 250 assert main_color[1][1] < 5 assert 95 < main_color[1][2] < 105 assert main_color[1][3] == 255 eq_(resp.content_type, 'image/png') self.created_tiles.append('wms_cache_EPSG900913/05/000/000/016/000/000/016.jpeg')
def test_clipped_bgcolor(self): with tmp_image((256, 256), format='png', color=(255, 0, 0)) as img: expected_req = ({'path': r'/service?LAYERs=bar&SERVICE=WMS&FORMAT=image%2Fpng' '&REQUEST=GetMap&HEIGHT=100&SRS=EPSG%3A25832&styles=' '&VERSION=1.1.1&BBOX=0.0,3500000.0,100.0,3500100.0' '&WIDTH=50'}, {'body': img.read(), 'headers': {'content-type': 'image/png'}}) with mock_httpd(('localhost', 42423), [expected_req]): resp = self.app.get('http://localhost/service?SERVICE=WMS&REQUEST=GetMap' '&LAYERS=direct&STYLES=' '&WIDTH=100&HEIGHT=100&FORMAT=image/png' '&BBOX=-100,3500000,100,3500100&SRS=EPSG:25832' '&VERSION=1.1.0&TRANSPARENT=FALSE&BGCOLOR=0x00ff00') eq_(resp.content_type, 'image/png') assert is_png(resp.body) assert_colors_equal(img_from_buf(resp.body).convert('RGBA'), [(50 * 100, [255, 0, 0, 255]), (50 * 100, [0, 255, 0, 255])])
def test_get_map_authorized_limited(self): def auth(service, layers, query_extent, **kw): eq_(query_extent, ('EPSG:4326', (-80.0, -40.0, 0.0, 0.0))) eq_(service, 'wms.map') eq_(len(layers), 1) return { 'authorized': 'partial', 'layers': { 'layer1': { 'map': True, 'limited_to': {'srs': 'EPSG:4326', 'geometry': [-40.0, -40.0, 0.0, 0.0]}, }, } } resp = self.app.get(MAP_REQ + 'layers=layer1', extra_environ={'mapproxy.authorize': auth}) eq_(resp.content_type, 'image/png') img = img_from_buf(resp.body) # left part not authorized, only bgcolor assert len(img.crop((0, 0, 100, 100)).getcolors()) == 1 # right part authorized, bgcolor + text assert len(img.crop((100, 0, 200, 100)).getcolors()) >= 2
def test_clipped(self): with tmp_image((256, 256), format='png', color=(255, 0, 0)) as img: expected_req = ({'path': r'/service?LAYERs=bar&SERVICE=WMS&FORMAT=image%2Fpng' '&REQUEST=GetMap&HEIGHT=100&SRS=EPSG%3A25832&styles=' '&VERSION=1.1.1&BBOX=0.0,3500000.0,150.0,3500100.0' '&WIDTH=75'}, {'body': img.read(), 'headers': {'content-type': 'image/png'}}) with mock_httpd(('localhost', 42423), [expected_req]): resp = self.app.get('http://localhost/service?SERVICE=WMS&REQUEST=GetMap' '&LAYERS=direct&STYLES=' '&WIDTH=100&HEIGHT=100&FORMAT=image/png' '&BBOX=-50,3500000,150,3500100&SRS=EPSG:25832' '&VERSION=1.1.0&TRANSPARENT=TRUE') eq_(resp.content_type, 'image/png') assert is_png(resp.body) colors = sorted(img_from_buf(resp.body).convert('RGBA').getcolors()) # quarter is clipped, check if it's transparent eq_(colors[0][0], (25 * 100)) eq_(colors[0][1][3], 0) eq_(colors[1], (75 * 100, (255, 0, 0, 255)))
def test_wms_catchall_error_no_image_response(self, app): expected_req = [( { "path": "/foo/1/1/0.png" }, { "body": b"error", "status": 200, "headers": { "content-type": "text/plain" }, }, )] with mock_httpd(("localhost", 42423), expected_req): self.common_map_req.params["layers"] = "tilesource_catchall" resp = app.get(self.common_map_req) assert_no_cache(resp) assert resp.content_type == "image/png" img = img_from_buf(resp.body) assert img.getcolors() == [(250 * 250, (100, 50, 50))]
def check_get_tile_limited_to(self, auth_dict): def auth(service, layers, environ, query_extent, **kw): eq_(environ['PATH_INFO'], '/kml/layer3_EPSG900913/1/0/0.jpeg') eq_(service, 'kml') eq_(len(layers), 1) eq_(query_extent[0], 'EPSG:900913') assert bbox_equals(query_extent[1], (-20037508.342789244, -20037508.342789244, 0, 0)) return auth_dict serv = MockServ(port=42423) serv.expects('/1/0/0.png') serv.returns(create_tmp_image((256, 256), color=(255, 0, 0)), headers={'content-type': 'image/png'}) with serv: resp = self.app.get('/kml/layer3_EPSG900913/1/0/0.jpeg', extra_environ={'mapproxy.authorize': auth}) eq_(resp.content_type, 'image/png') img = img_from_buf(resp.body) img = img.convert('RGBA') # left part authorized, red eq_(img.crop((0, 0, 127, 255)).getcolors()[0], (127*255, (255, 0, 0, 255))) # right part not authorized, transparent eq_(img.crop((129, 0, 255, 255)).getcolors()[0][1][3], 0)
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()
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()
def test_get_map_l(self, app): resp = app.get(str(self.common_map_req)) assert resp.content_type == "image/png" img = img_from_buf(resp.body) assert img.mode == "L" assert img.getpixel((0, 0)) == int(50 * 0.25 + 0.7 * 100 + 0.05 * 200)
def test_get_tile_021(self): resp = self.app.get("/wmts/dop_021/GLOBAL_WEBMERCATOR/0/0/0.png") eq_(resp.content_type, "image/png") img = img_from_buf(resp.body) eq_(img.mode, "RGB") eq_(img.getpixel((0, 0)), (50, 200, 100))
def test_get_tile_l(self): resp = self.app.get('/wmts/dop_l/GLOBAL_WEBMERCATOR/0/0/0.png') eq_(resp.content_type, 'image/png') img = img_from_buf(resp.body) eq_(img.mode, 'L') eq_(img.getpixel((0, 0)), int(50*0.25+0.7*100+0.05*200))
def test_get_map_l(self): resp = self.app.get(str(self.common_map_req)) eq_(resp.content_type, 'image/png') img = img_from_buf(resp.body) eq_(img.mode, 'L') eq_(img.getpixel((0, 0)), int(50*0.25+0.7*100+0.05*200))
def test_get_tile_0(self): resp = self.app.get('/wmts/dop_0/GLOBAL_WEBMERCATOR/0/0/0.png') eq_(resp.content_type, 'image/png') img = img_from_buf(resp.body) eq_(img.mode, 'RGB') # forced with image.mode eq_(img.getpixel((0, 0)), (50, 50, 50))
def test_get_tile_0122(self): resp = self.app.get('/wmts/dop_0122/GLOBAL_WEBMERCATOR/0/0/0.png') eq_(resp.content_type, 'image/png') img = img_from_buf(resp.body) eq_(img.mode, 'RGBA') eq_(img.getpixel((0, 0)), (50, 100, 200, 50))
def test_get_tile_0122(self, app): resp = app.get("/wmts/dop_0122/GLOBAL_WEBMERCATOR/0/0/0.png") assert resp.content_type == "image/png" img = img_from_buf(resp.body) assert img.mode == "RGBA" assert img.getpixel((0, 0)) == (50, 100, 200, 50)
def test_get_tile_l(self, app): resp = app.get("/wmts/dop_l/GLOBAL_WEBMERCATOR/0/0/0.png") assert resp.content_type == "image/png" img = img_from_buf(resp.body) assert img.mode == "L" assert img.getpixel((0, 0)) == int(50 * 0.25 + 0.7 * 100 + 0.05 * 200)