def test_get_map_error(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') self.send_response(200) self.send_header('Content-type', 'application/json') self.end_headers() self.wfile.write(b'{"status": "error", "error_message": "barf"}') 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) eq_(resp.content_type, 'application/vnd.ogc.se_xml') is_111_exception(resp.lxml, re_msg='Error from renderd: barf')
def test_get_map_error(self, app): 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" self.send_response(200) self.send_header("Content-type", "application/json") self.end_headers() self.wfile.write( b'{"status": "error", "error_message": "barf"}') 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) assert resp.content_type == "application/vnd.ogc.se_xml" is_111_exception(resp.lxml, re_msg="Error from renderd: barf")
def test_get_map_error(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') self.send_response(200) self.send_header('Content-type', 'application/json') self.end_headers() self.wfile.write( '{"status": "error", "error_message": "barf"}') 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) eq_(resp.content_type, 'application/vnd.ogc.se_xml') is_111_exception(resp.lxml, re_msg='Error from renderd: barf')
def test_get_map_connection_error(self): self.common_map_req.params['bbox'] = '0,0,9,9' resp = self.app.get(self.common_map_req) eq_(resp.content_type, 'application/vnd.ogc.se_xml') is_111_exception(resp.lxml, re_msg='Error while communicating with renderd:')
def test_get_map_connection_error(self, app): self.common_map_req.params["bbox"] = "0,0,9,9" resp = app.get(self.common_map_req) assert resp.content_type == "application/vnd.ogc.se_xml" is_111_exception(resp.lxml, re_msg="Error while communicating with renderd:")
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) is_111_exception(resp.lxml, re_msg='no response from url')
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) is_111_exception(resp.lxml, re_msg='no response from url')
def test_get_map_non_json_response(self): class req_handler(BaseHTTPRequestHandler): def do_POST(self): length = int(self.headers['content-length']) json_data = self.rfile.read(length) json.loads(json_data.decode('utf-8')) self.send_response(200) self.send_header('Content-type', 'application/json') self.end_headers() self.wfile.write(b'{"invalid') 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) eq_(resp.content_type, 'application/vnd.ogc.se_xml') is_111_exception(resp.lxml, re_msg='Error while communicating with renderd: invalid JSON')
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) is_111_exception(resp.lxml, re_msg="no response from url")
def test_get_map_non_json_response(self, app): class req_handler(BaseHTTPRequestHandler): def do_POST(self): length = int(self.headers["content-length"]) json_data = self.rfile.read(length) json.loads(json_data.decode("utf-8")) self.send_response(200) self.send_header("Content-type", "application/json") self.end_headers() self.wfile.write(b'{"invalid') 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) assert resp.content_type == "application/vnd.ogc.se_xml" is_111_exception( resp.lxml, re_msg="Error while communicating with renderd: invalid JSON")
def test_get_tile_wrong_size(self): self.common_map_req.params.size = (256, 255) resp = self.app.get(str(self.common_map_req) + '&tiled=true') assert 'Cache-Control' not in resp.headers is_111_exception(resp.lxml, re_msg='Invalid request: invalid.*size.*256x256')
def test_get_tile_wrong_bbox(self): self.common_map_req.params.bbox = '-20037508,0.0,200000.0,20037508' resp = self.app.get(str(self.common_map_req) + '&tiled=true') assert 'Cache-Control' not in resp.headers is_111_exception(resp.lxml, re_msg='.*invalid bbox')
def test_all_offline(self): self.common_map_req.params.layers = 'all_offline' resp = self.app.get(self.common_map_req) eq_(resp.content_type, 'application/vnd.ogc.se_xml') is_111_exception(resp.lxml, re_msg='no response from url')
def test_get_tile_wrong_fromat(self): self.common_map_req.params.format = 'image/png' resp = self.app.get(str(self.common_map_req) + '&tiled=true') assert 'Cache-Control' not in resp.headers is_111_exception(resp.lxml, re_msg='Invalid request: invalid.*format.*jpeg')
def test_get_tile_wrong_fromat(self, app): self.common_map_req.params.format = "image/png" resp = app.get(str(self.common_map_req) + "&tiled=true") assert "Cache-Control" not in resp.headers is_111_exception(resp.lxml, re_msg="Invalid request: invalid.*format.*jpeg")
def test_get_tile_wrong_size(self, app): self.common_map_req.params.size = (256, 255) resp = app.get(str(self.common_map_req) + "&tiled=true") assert "Cache-Control" not in resp.headers is_111_exception(resp.lxml, re_msg="Invalid request: invalid.*size.*256x256")
def test_get_tile_wrong_bbox(self, app): self.common_map_req.params.bbox = "-20037508,0.0,200000.0,20037508" resp = app.get(str(self.common_map_req) + "&tiled=true") assert "Cache-Control" not in resp.headers is_111_exception(resp.lxml, re_msg=".*invalid bbox")
def test_all_offline(self, app): self.common_map_req.params.layers = "all_offline" resp = app.get(self.common_map_req) assert resp.content_type == "application/vnd.ogc.se_xml" is_111_exception(resp.lxml, re_msg="no response from url")