def check_invalid_parameter(self): resp = self.app.get(str(self.common_tile_req), status=400) xml = resp.lxml eq_(resp.content_type, 'text/xml') assert validate_with_xsd(xml, xsd_name='ows/1.1.0/owsExceptionReport.xsd') eq_xpath_wmts(xml, '/ows:ExceptionReport/ows:Exception/@exceptionCode', 'InvalidParameterValue')
def test_capabilities(self): resp = self.app.get('/wmts/myrest/1.0.0/WMTSCapabilities.xml') xml = resp.lxml assert validate_with_xsd(xml, xsd_name='wmts/1.0/wmtsGetCapabilities_response.xsd') eq_(len(xml.xpath('//wmts:Layer', namespaces=ns_wmts)), 2) eq_(len(xml.xpath('//wmts:Contents/wmts:TileMatrixSet', namespaces=ns_wmts)), 1) eq_(set(xml.xpath('//wmts:Contents/wmts:Layer/wmts:ResourceURL/@template', namespaces=ns_wmts)), set(['http://localhost/wmts/myrest/dimension_layer/{TileMatrixSet}/{Time}/{Elevation}/{TileMatrix}/{TileCol}/{TileRow}.png', 'http://localhost/wmts/myrest/no_dimension_layer/{TileMatrixSet}/{Time}/{Elevation}/{TileMatrix}/{TileCol}/{TileRow}.png'])) # check dimension values for dimension_layer dimension_elems = xml.xpath( '//wmts:Layer/ows:Identifier[text()="dimension_layer"]/following-sibling::wmts:Dimension', namespaces=ns_wmts, ) dimensions = {} for elem in dimension_elems: dim = elem.find('{http://www.opengis.net/ows/1.1}Identifier').text default = elem.find('{http://www.opengis.net/wmts/1.0}Default').text values = [e.text for e in elem.findall('{http://www.opengis.net/wmts/1.0}Value')] dimensions[dim] = (values, default) eq_(dimensions['Time'][0], ["2012-11-12T00:00:00", "2012-11-13T00:00:00", "2012-11-14T00:00:00", "2012-11-15T00:00:00"] ) eq_(dimensions['Time'][1], '2012-11-15T00:00:00') eq_(dimensions['Elevation'][1], '0') eq_(dimensions['Elevation'][0], ["0", "1000", "3000"] )
def test_endpoints(self): for endpoint in ('service', 'ows'): req = WMTS100CapabilitiesRequest(url='/%s?' % endpoint).copy_with_request_params(self.common_cap_req) resp = self.app.get(req) eq_(resp.content_type, 'application/xml') xml = resp.lxml assert validate_with_xsd(xml, xsd_name='wmts/1.0/wmtsGetCapabilities_response.xsd')
def test_get_tile_source_error(self): self.common_tile_req.params["layer"] = "tms_cache" self.common_tile_req.params["format"] = "image/png" resp = self.app.get(str(self.common_tile_req), status=500) xml = resp.lxml assert validate_with_xsd(xml, xsd_name="ows/1.1.0/owsExceptionReport.xsd") eq_xpath_wmts(xml, "/ows:ExceptionReport/ows:Exception/@exceptionCode", "NoApplicableCode")
def test_get_tile_out_of_range(self): self.common_tile_req.params.coord = -1, 1, 1 resp = self.app.get(str(self.common_tile_req), status=400) xml = resp.lxml eq_(resp.content_type, "text/xml") assert validate_with_xsd(xml, xsd_name="ows/1.1.0/owsExceptionReport.xsd") eq_xpath_wmts(xml, "/ows:ExceptionReport/ows:Exception/@exceptionCode", "TileOutOfRange")
def test_capabilities(self): req = str(self.common_cap_req) resp = self.app.get(req) xml = resp.lxml assert validate_with_xsd(xml, xsd_name='wmts/1.0/wmtsGetCapabilities_response.xsd') eq_(len(xml.xpath('//wmts:Layer', namespaces=ns_wmts)), 4) eq_(len(xml.xpath('//wmts:Contents/wmts:TileMatrixSet', namespaces=ns_wmts)), 4)
def test_get_kml(self): resp = self.app.get('/kml/wms_cache/0/0/0.kml') xml = resp.lxml assert validate_with_xsd(xml, 'kml/2.2.0/ogckml22.xsd') eq_(xml.xpath('/kml:kml/kml:Document/kml:GroundOverlay/kml:Icon/kml:href/text()', namespaces=ns), ['http://localhost/kml/wms_cache/EPSG900913/1/0/1.jpeg', 'http://localhost/kml/wms_cache/EPSG900913/1/1/1.jpeg', 'http://localhost/kml/wms_cache/EPSG900913/1/0/0.jpeg', 'http://localhost/kml/wms_cache/EPSG900913/1/1/0.jpeg'] ) eq_(xml.xpath('/kml:kml/kml:Document/kml:NetworkLink/kml:Link/kml:href/text()', namespaces=ns), ['http://localhost/kml/wms_cache/EPSG900913/1/0/1.kml', 'http://localhost/kml/wms_cache/EPSG900913/1/1/1.kml', 'http://localhost/kml/wms_cache/EPSG900913/1/0/0.kml', 'http://localhost/kml/wms_cache/EPSG900913/1/1/0.kml'] ) etag = hashlib.md5(resp.body).hexdigest() max_age = base_config().tiles.expires_hours * 60 * 60 self._check_cache_control_headers(resp, etag, max_age, None) resp = self.app.get('/kml/wms_cache/0/0/0.kml', headers={'If-None-Match': etag}) eq_(resp.status, '304 Not Modified')
def test_get_tile_out_of_range(self): resp = self.app.get('/wmts/myrest/wms_cache/GLOBAL_MERCATOR/01/-1/0.jpeg', status=400) xml = resp.lxml eq_(resp.content_type, 'text/xml') assert validate_with_xsd(xml, xsd_name='ows/1.1.0/owsExceptionReport.xsd') eq_xpath_wmts(xml, '/ows:ExceptionReport/ows:Exception/@exceptionCode', 'TileOutOfRange')
def test_get_kml_nw(self): resp = self.app.get('/kml/wms_cache_nw/1/0/0.kml') xml = resp.lxml assert validate_with_xsd(xml, 'kml/2.2.0/ogckml22.xsd') assert bbox_equals( self._bbox(xml.xpath('/kml:kml/kml:Document', namespaces=ns)[0]), (-180, -90, 0, 0) ) assert bbox_equals( self._bbox(xml.xpath('/kml:kml/kml:Document/kml:GroundOverlay', namespaces=ns)[0]), (-180, -66.51326, -90, 0) ) eq_(xml.xpath('/kml:kml/kml:Document/kml:GroundOverlay/kml:Icon/kml:href/text()', namespaces=ns), ['http://localhost/kml/wms_cache_nw/EPSG900913/2/0/1.jpeg', 'http://localhost/kml/wms_cache_nw/EPSG900913/2/1/1.jpeg', 'http://localhost/kml/wms_cache_nw/EPSG900913/2/0/0.jpeg', 'http://localhost/kml/wms_cache_nw/EPSG900913/2/1/0.jpeg'] ) eq_(xml.xpath('/kml:kml/kml:Document/kml:NetworkLink/kml:Link/kml:href/text()', namespaces=ns), ['http://localhost/kml/wms_cache_nw/EPSG900913/2/0/1.kml', 'http://localhost/kml/wms_cache_nw/EPSG900913/2/1/1.kml', 'http://localhost/kml/wms_cache_nw/EPSG900913/2/0/0.kml', 'http://localhost/kml/wms_cache_nw/EPSG900913/2/1/0.kml'] )
def test_get_legendgraphic_missing_params_130(self): req = str(self.common_lg_req_130).replace('format', 'invalid') resp = self.app.get(req) eq_(resp.content_type, 'text/xml') xml = resp.lxml eq_xpath_wms130(xml, '/ogc:ServiceExceptionReport/@version', '1.3.0') eq_xpath_wms130(xml, '//ogc:ServiceException/text()', "missing parameters ['format']") assert validate_with_xsd(xml, xsd_name='wms/1.3.0/exceptions_1_3_0.xsd')
def test_get_legendgraphic_invalid_sld_version_130(self): req = str(self.common_lg_req_130).replace('sld_version=1.1.0', 'sld_version=1.0.0') resp = self.app.get(req) eq_(resp.content_type, 'text/xml') xml = resp.lxml eq_xpath_wms130(xml, '/ogc:ServiceExceptionReport/@version', '1.3.0') eq_xpath_wms130(xml, '//ogc:ServiceException/text()', 'invalid sld_version 1.0.0') assert validate_with_xsd(xml, xsd_name='wms/1.3.0/exceptions_1_3_0.xsd')
def test_get_tile_out_of_range(self): self.common_tile_req.params.coord = -1, 1, 1 resp = self.app.get(str(self.common_tile_req), status=400) xml = resp.lxml eq_(resp.content_type, 'text/xml') assert validate_with_xsd(xml, xsd_name='ows/1.1.0/owsExceptionReport.xsd') eq_xpath_wmts(xml, '/ows:ExceptionReport/ows:Exception/@exceptionCode', 'TileOutOfRange')
def test_get_tile_source_error(self): resp = self.app.get( '/wmts/myrest/tms_cache/GLOBAL_MERCATOR/01/0/0.png', status=500) xml = resp.lxml assert validate_with_xsd(xml, xsd_name='ows/1.1.0/owsExceptionReport.xsd') eq_xpath_wmts(xml, '/ows:ExceptionReport/ows:Exception/@exceptionCode', 'NoApplicableCode')
def test_get_tile_source_error(self): self.common_tile_req.params['layer'] = 'tms_cache' self.common_tile_req.params['format'] = 'image/png' resp = self.app.get(str(self.common_tile_req), status=500) xml = resp.lxml assert validate_with_xsd(xml, xsd_name='ows/1.1.0/owsExceptionReport.xsd') eq_xpath_wmts(xml, '/ows:ExceptionReport/ows:Exception/@exceptionCode', 'NoApplicableCode')
def test_get_legendgraphic_no_legend_130(self): self.common_lg_req_130.params['layer'] = 'wms_no_legend' resp = self.app.get(self.common_lg_req_130) eq_(resp.content_type, 'text/xml') xml = resp.lxml eq_xpath_wms130(xml, '/ogc:ServiceExceptionReport/@version', '1.3.0') eq_xpath_wms130(xml, '//ogc:ServiceException/text()', 'layer wms_no_legend has no legend graphic') assert validate_with_xsd(xml, xsd_name='wms/1.3.0/exceptions_1_3_0.xsd')
def test_get_tile_source_error(self, app): resp = app.get("/wmts/myrest/tms_cache/GLOBAL_MERCATOR/01/0/0.png", status=500) xml = resp.lxml assert validate_with_xsd(xml, xsd_name="ows/1.1.0/owsExceptionReport.xsd") assert_xpath_wmts(xml, "/ows:ExceptionReport/ows:Exception/@exceptionCode", "NoApplicableCode")
def test_get_tile_out_of_range(self): resp = self.app.get( '/wmts/myrest/wms_cache/GLOBAL_MERCATOR/01/-1/0.jpeg', status=400) xml = resp.lxml eq_(resp.content_type, 'text/xml') assert validate_with_xsd(xml, xsd_name='ows/1.1.0/owsExceptionReport.xsd') eq_xpath_wmts(xml, '/ows:ExceptionReport/ows:Exception/@exceptionCode', 'TileOutOfRange')
def test_get_tile_out_of_range(self, app): self.common_tile_req.params.coord = -1, 1, 1 resp = app.get(str(self.common_tile_req), status=400) xml = resp.lxml assert resp.content_type == "text/xml" assert validate_with_xsd(xml, xsd_name="ows/1.1.0/owsExceptionReport.xsd") assert_xpath_wmts(xml, "/ows:ExceptionReport/ows:Exception/@exceptionCode", "TileOutOfRange")
def test_get_tile_source_error(self, app): self.common_tile_req.params["layer"] = "tms_cache" self.common_tile_req.params["format"] = "image/png" resp = app.get(str(self.common_tile_req), status=500) xml = resp.lxml assert validate_with_xsd(xml, xsd_name="ows/1.1.0/owsExceptionReport.xsd") assert_xpath_wmts(xml, "/ows:ExceptionReport/ows:Exception/@exceptionCode", "NoApplicableCode")
def test_endpoints(self, app): for endpoint in ("service", "ows"): req = WMTS100CapabilitiesRequest( url="/%s?" % endpoint).copy_with_request_params( self.common_cap_req) resp = app.get(req) assert resp.content_type == "application/xml" xml = resp.lxml assert validate_with_xsd( xml, xsd_name="wmts/1.0/wmtsGetCapabilities_response.xsd")
def test_get_tile_out_of_range(self, app): resp = app.get("/wmts/myrest/wms_cache/GLOBAL_MERCATOR/01/-1/0.jpeg", status=400) xml = resp.lxml assert resp.content_type == "text/xml" assert validate_with_xsd(xml, xsd_name="ows/1.1.0/owsExceptionReport.xsd") assert_xpath_wmts(xml, "/ows:ExceptionReport/ows:Exception/@exceptionCode", "TileOutOfRange")
def check_invalid_parameter(self, app, url): resp = app.get(url, status=400) xml = resp.lxml assert resp.content_type == "text/xml" assert validate_with_xsd(xml, xsd_name="ows/1.1.0/owsExceptionReport.xsd") assert_xpath_wmts( xml, "/ows:ExceptionReport/ows:Exception/@exceptionCode", "InvalidParameterValue", )
def test_endpoints(self): for endpoint in ('service', 'ows'): req = WMTS100CapabilitiesRequest( url='/%s?' % endpoint).copy_with_request_params( self.common_cap_req) resp = self.app.get(req) eq_(resp.content_type, 'application/xml') xml = resp.lxml assert validate_with_xsd( xml, xsd_name='wmts/1.0/wmtsGetCapabilities_response.xsd')
def test_capabilities(self): resp = self.app.get('/wmts/myrest/1.0.0/WMTSCapabilities.xml') xml = resp.lxml assert validate_with_xsd( xml, xsd_name='wmts/1.0/wmtsGetCapabilities_response.xsd') eq_(len(xml.xpath('//wmts:Layer', namespaces=ns_wmts)), 4) eq_( len( xml.xpath('//wmts:Contents/wmts:TileMatrixSet', namespaces=ns_wmts)), 4)
def test_get_legendgraphic_missing_params_130(self, app): req = str(self.common_lg_req_130).replace("format", "invalid") resp = app.get(req) assert resp.content_type == "text/xml" xml = resp.lxml assert_xpath_wms130(xml, "/ogc:ServiceExceptionReport/@version", "1.3.0") assert_xpath_wms130(xml, "//ogc:ServiceException/text()", "missing parameters ['format']") assert validate_with_xsd(xml, xsd_name="wms/1.3.0/exceptions_1_3_0.xsd")
def test_capabilities(self, app): resp = app.get("/wmts/1.0.0/WMTSCapabilities.xml") xml = resp.lxml assert validate_with_xsd( xml, xsd_name="wmts/1.0/wmtsGetCapabilities_response.xsd") assert len(xml.xpath("//wmts:Layer", namespaces=ns_wmts)) == 5 assert (len( xml.xpath("//wmts:Contents/wmts:TileMatrixSet", namespaces=ns_wmts)) == 5) # check InfoFormat for queryable layers for layer in xml.xpath("//wmts:Layer", namespaces=ns_wmts): if layer.findtext("ows:Identifier", namespaces=ns_wmts) in ( "wms_cache", "wms_cache_multi", "gk3_cache", "tms_cache", ): assert layer.xpath("wmts:InfoFormat/text()", namespaces=ns_wmts) == [ "application/gml+xml; version=3.1", "application/json", ] else: assert layer.xpath("wmts:InfoFormat/text()", namespaces=ns_wmts) == [] # check ResourceURL for wms_cache layer = xml.xpath('//wmts:Layer[ows:Identifier/text()="wms_cache"]', namespaces=ns_wmts)[0] resourceURLs = layer.xpath("wmts:ResourceURL", namespaces=ns_wmts) for rurl, format, type, template in [ [ resourceURLs[0], "image/jpeg", "tile", "http://localhost/wmts/myrest/wms_cache/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.jpeg", ], [ resourceURLs[1], "application/gml+xml; version=3.1", "FeatureInfo", "http://localhost/wmts/myrest/wms_cache/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}/{I}/{J}.gml", ], [ resourceURLs[2], "application/json", "FeatureInfo", "http://localhost/wmts/myrest/wms_cache/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}/{I}/{J}.geojson", ], ]: assert rurl.attrib["format"] == format assert rurl.attrib["resourceType"] == type assert rurl.attrib["template"] == template
def test_get_legendgraphic_invalid_sld_version_130(self, app): req = str(self.common_lg_req_130).replace("sld_version=1.1.0", "sld_version=1.0.0") resp = app.get(req) assert resp.content_type == "text/xml" xml = resp.lxml assert_xpath_wms130(xml, "/ogc:ServiceExceptionReport/@version", "1.3.0") assert_xpath_wms130(xml, "//ogc:ServiceException/text()", "invalid sld_version 1.0.0") assert validate_with_xsd(xml, xsd_name="wms/1.3.0/exceptions_1_3_0.xsd")
def test_wmts_capabilities(self): req = str(self.common_cap_req) resp = self.app.get(req) eq_(resp.content_type, 'application/xml') xml = resp.lxml assert validate_with_xsd( xml, xsd_name='wmts/1.0/wmtsGetCapabilities_response.xsd') eq_(set(xml.xpath('//wmts:Layer/ows:Identifier/text()', namespaces=ns_wmts)), set(['cache', 'multi_cache'])) eq_(set(xml.xpath('//wmts:Contents/wmts:TileMatrixSet/ows:Identifier/text()', namespaces=ns_wmts)), set(['gk3', 'GLOBAL_WEBMERCATOR', 'utm32', 'InspireCrs84Quad']))
def test_capabilities(self): req = str(self.common_cap_req) resp = self.app.get(req) eq_(resp.content_type, 'application/xml') xml = resp.lxml assert validate_with_xsd( xml, xsd_name='wmts/1.0/wmtsGetCapabilities_response.xsd') eq_(len(xml.xpath('//wmts:Layer', namespaces=ns_wmts)), 4) eq_( len( xml.xpath('//wmts:Contents/wmts:TileMatrixSet', namespaces=ns_wmts)), 4)
def test_get_legendgraphic_no_legend_130(self, app): self.common_lg_req_130.params["layer"] = "wms_no_legend" resp = app.get(self.common_lg_req_130) assert resp.content_type == "text/xml" xml = resp.lxml assert_xpath_wms130(xml, "/ogc:ServiceExceptionReport/@version", "1.3.0") assert_xpath_wms130( xml, "//ogc:ServiceException/text()", "layer wms_no_legend has no legend graphic", ) assert validate_with_xsd(xml, xsd_name="wms/1.3.0/exceptions_1_3_0.xsd")
def test_capabilities(self, app): resp = app.get("/wmts/1.0.0/WMTSCapabilities.xml") xml = resp.lxml assert validate_with_xsd( xml, xsd_name="wmts/1.0/wmtsGetCapabilities_response.xsd" ) assert len(xml.xpath("//wmts:Layer", namespaces=ns_wmts)) == 2 assert ( len(xml.xpath("//wmts:Contents/wmts:TileMatrixSet", namespaces=ns_wmts)) == 1 ) assert set( xml.xpath( "//wmts:Contents/wmts:Layer/wmts:ResourceURL/@template", namespaces=ns_wmts, ) ) == set( [ "http://localhost/wmts/dimension_layer/{TileMatrixSet}/{Time}/{Elevation}/{TileMatrix}/{TileCol}/{TileRow}.png", "http://localhost/wmts/no_dimension_layer/{TileMatrixSet}/{Time}/{Elevation}/{TileMatrix}/{TileCol}/{TileRow}.png", ] ) # check dimension values for dimension_layer dimension_elems = xml.xpath( '//wmts:Layer/ows:Identifier[text()="dimension_layer"]/following-sibling::wmts:Dimension', namespaces=ns_wmts, ) dimensions = {} for elem in dimension_elems: dim = elem.find("{http://www.opengis.net/ows/1.1}Identifier").text default = elem.find("{http://www.opengis.net/wmts/1.0}Default").text values = [ e.text for e in elem.findall("{http://www.opengis.net/wmts/1.0}Value") ] dimensions[dim] = (values, default) assert dimensions["Time"][0] == [ "2012-11-12T00:00:00", "2012-11-13T00:00:00", "2012-11-14T00:00:00", "2012-11-15T00:00:00", ] assert dimensions["Time"][1] == "2012-11-15T00:00:00" assert dimensions["Elevation"][1] == "0" assert dimensions["Elevation"][0] == ["0", "1000", "3000"]
def test_capabilities(self): resp = self.app.get('/wmts/myrest/1.0.0/WMTSCapabilities.xml') xml = resp.lxml assert validate_with_xsd( xml, xsd_name='wmts/1.0/wmtsGetCapabilities_response.xsd') eq_(len(xml.xpath('//wmts:Layer', namespaces=ns_wmts)), 2) eq_( len( xml.xpath('//wmts:Contents/wmts:TileMatrixSet', namespaces=ns_wmts)), 1) eq_( set( xml.xpath( '//wmts:Contents/wmts:Layer/wmts:ResourceURL/@template', namespaces=ns_wmts)), set([ 'http://localhost/wmts/myrest/dimension_layer/{TileMatrixSet}/{Time}/{Elevation}/{TileMatrix}/{TileCol}/{TileRow}.png', 'http://localhost/wmts/myrest/no_dimension_layer/{TileMatrixSet}/{Time}/{Elevation}/{TileMatrix}/{TileCol}/{TileRow}.png' ])) # check dimension values for dimension_layer dimension_elems = xml.xpath( '//wmts:Layer/ows:Identifier[text()="dimension_layer"]/following-sibling::wmts:Dimension', namespaces=ns_wmts, ) dimensions = {} for elem in dimension_elems: dim = elem.find('{http://www.opengis.net/ows/1.1}Identifier').text default = elem.find( '{http://www.opengis.net/wmts/1.0}Default').text values = [ e.text for e in elem.findall('{http://www.opengis.net/wmts/1.0}Value') ] dimensions[dim] = (values, default) eq_(dimensions['Time'][0], [ "2012-11-12T00:00:00", "2012-11-13T00:00:00", "2012-11-14T00:00:00", "2012-11-15T00:00:00" ]) eq_(dimensions['Time'][1], '2012-11-15T00:00:00') eq_(dimensions['Elevation'][1], '0') eq_(dimensions['Elevation'][0], ["0", "1000", "3000"])
def test_get_kml_multi_layer(self): resp = self.app.get('/kml/wms_cache_multi/1/0/0.kml') xml = resp.lxml assert validate_with_xsd(xml, 'kml/2.2.0/ogckml22.xsd') eq_(xml.xpath('/kml:kml/kml:Document/kml:GroundOverlay/kml:Icon/kml:href/text()', namespaces=ns), ['http://localhost/kml/wms_cache_multi/EPSG4326/2/0/1.jpeg', 'http://localhost/kml/wms_cache_multi/EPSG4326/2/1/1.jpeg', 'http://localhost/kml/wms_cache_multi/EPSG4326/2/0/0.jpeg', 'http://localhost/kml/wms_cache_multi/EPSG4326/2/1/0.jpeg'] ) eq_(xml.xpath('/kml:kml/kml:Document/kml:NetworkLink/kml:Link/kml:href/text()', namespaces=ns), ['http://localhost/kml/wms_cache_multi/EPSG4326/2/0/1.kml', 'http://localhost/kml/wms_cache_multi/EPSG4326/2/1/1.kml', 'http://localhost/kml/wms_cache_multi/EPSG4326/2/0/0.kml', 'http://localhost/kml/wms_cache_multi/EPSG4326/2/1/0.kml'] )
def test_wmts_capabilities(self, app): req = str(self.common_cap_req) resp = app.get(req) assert resp.content_type == "application/xml" xml = resp.lxml assert validate_with_xsd( xml, xsd_name="wmts/1.0/wmtsGetCapabilities_response.xsd" ) assert set( xml.xpath("//wmts:Layer/ows:Identifier/text()", namespaces=ns_wmts) ) == set(["cache", "multi_cache"]) assert set( xml.xpath( "//wmts:Contents/wmts:TileMatrixSet/ows:Identifier/text()", namespaces=ns_wmts, ) ) == set(["gk3", "GLOBAL_WEBMERCATOR", "utm32", "InspireCrs84Quad"])
def test_capabilities(self): req = str(self.common_cap_req) resp = self.app.get(req) eq_(resp.content_type, 'application/xml') xml = resp.lxml assert validate_with_xsd(xml, xsd_name='wmts/1.0/wmtsGetCapabilities_response.xsd') eq_(len(xml.xpath('//wmts:Layer', namespaces=ns_wmts)), 5) eq_(len(xml.xpath('//wmts:Contents/wmts:TileMatrixSet', namespaces=ns_wmts)), 5) goog_matrixset = xml.xpath('//wmts:Contents/wmts:TileMatrixSet[./ows:Identifier/text()="GoogleMapsCompatible"]', namespaces=ns_wmts)[0] eq_(goog_matrixset.findtext('ows:Identifier', namespaces=ns_wmts), 'GoogleMapsCompatible') # top left corner: min X first then max Y assert re.match('-20037508\.\d+ 20037508\.\d+', goog_matrixset.findtext('./wmts:TileMatrix[1]/wmts:TopLeftCorner', namespaces=ns_wmts)) gk_matrixset = xml.xpath('//wmts:Contents/wmts:TileMatrixSet[./ows:Identifier/text()="gk3"]', namespaces=ns_wmts)[0] eq_(gk_matrixset.findtext('ows:Identifier', namespaces=ns_wmts), 'gk3') # Gauß-Krüger uses "reverse" axis order -> top left corner: max Y first then min X assert re.match('6000000.0+ 3000000.0+', gk_matrixset.findtext('./wmts:TileMatrix[1]/wmts:TopLeftCorner', namespaces=ns_wmts))
def test_capabilities(self): req = str(self.common_cap_req) resp = self.app.get(req) eq_(resp.content_type, 'application/xml') xml = resp.lxml assert validate_with_xsd(xml, xsd_name='wmts/1.0/wmtsGetCapabilities_response.xsd') eq_(xml.xpath('//wmts:Layer/ows:Identifier/text()', namespaces=ns_wmts), ['wms_cache','wms_cache_multi','tms_cache','tms_cache_ul','gk3_cache'], ) eq_(len(xml.xpath('//wmts:Contents/wmts:TileMatrixSet', namespaces=ns_wmts)), 5) goog_matrixset = xml.xpath('//wmts:Contents/wmts:TileMatrixSet[./ows:Identifier/text()="GoogleMapsCompatible"]', namespaces=ns_wmts)[0] eq_(goog_matrixset.findtext('ows:Identifier', namespaces=ns_wmts), 'GoogleMapsCompatible') # top left corner: min X first then max Y assert re.match('-20037508\.\d+ 20037508\.\d+', goog_matrixset.findtext('./wmts:TileMatrix[1]/wmts:TopLeftCorner', namespaces=ns_wmts)) gk_matrixset = xml.xpath('//wmts:Contents/wmts:TileMatrixSet[./ows:Identifier/text()="gk3"]', namespaces=ns_wmts)[0] eq_(gk_matrixset.findtext('ows:Identifier', namespaces=ns_wmts), 'gk3') # Gauß-Krüger uses "reverse" axis order -> top left corner: max Y first then min X assert re.match('6000000.0+ 3000000.0+', gk_matrixset.findtext('./wmts:TileMatrix[1]/wmts:TopLeftCorner', namespaces=ns_wmts))
def test_render_w_code(self): req = self.mock(WMSMapRequest) req_ex = RequestError("the exception message", code="InvalidFormat", request=req) ex_handler = WMS130ExceptionHandler() self.expect(req.exception_handler).result(ex_handler) self.replay() response = req_ex.render() assert response.content_type == "text/xml; charset=utf-8" expected_resp = """ <?xml version='1.0' encoding="UTF-8"?> <ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd"> <ServiceException code="InvalidFormat">the exception message</ServiceException> </ServiceExceptionReport> """ assert expected_resp.strip() == response.data assert validate_with_xsd(response.data, "wms/1.3.0/exceptions_1_3_0.xsd")
def test_render(self): req = self.mock(WMSMapRequest) req_ex = RequestError('the exception message', request=req) ex_handler = WMS130ExceptionHandler() self.expect(req.exception_handler).result(ex_handler) self.replay() response = req_ex.render() assert response.content_type == 'text/xml; charset=utf-8' expected_resp = b""" <?xml version="1.0"?> <ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd"> <ServiceException>the exception message</ServiceException> </ServiceExceptionReport> """ assert expected_resp.strip() == response.data assert validate_with_xsd(response.data, 'wms/1.3.0/exceptions_1_3_0.xsd')
def test_get_kml(self, app, base_config): resp = app.get("/kml/wms_cache/0/0/0.kml") xml = resp.lxml assert validate_with_xsd(xml, "kml/2.2.0/ogckml22.xsd") assert bbox_equals( self._bbox(xml.xpath("/kml:kml/kml:Document", namespaces=ns)[0]), (-180, -90, 180, 90), ) assert bbox_equals( self._bbox( xml.xpath("/kml:kml/kml:Document/kml:GroundOverlay", namespaces=ns)[0]), (-180, 0, 0, 90), ) assert xml.xpath( "/kml:kml/kml:Document/kml:GroundOverlay/kml:Icon/kml:href/text()", namespaces=ns, ) == [ "http://localhost/kml/wms_cache/EPSG900913/1/0/1.jpeg", "http://localhost/kml/wms_cache/EPSG900913/1/1/1.jpeg", "http://localhost/kml/wms_cache/EPSG900913/1/0/0.jpeg", "http://localhost/kml/wms_cache/EPSG900913/1/1/0.jpeg", ] assert xml.xpath( "/kml:kml/kml:Document/kml:NetworkLink/kml:Link/kml:href/text()", namespaces=ns, ) == [ "http://localhost/kml/wms_cache/EPSG900913/1/0/1.kml", "http://localhost/kml/wms_cache/EPSG900913/1/1/1.kml", "http://localhost/kml/wms_cache/EPSG900913/1/0/0.kml", "http://localhost/kml/wms_cache/EPSG900913/1/1/0.kml", ] etag = hashlib.md5(resp.body).hexdigest() max_age = base_config.tiles.expires_hours * 60 * 60 self._check_cache_control_headers(resp, etag, max_age, None) resp = app.get("/kml/wms_cache/0/0/0.kml", headers={"If-None-Match": etag}) assert resp.status == "304 Not Modified"
def test_get_kml_multi_layer(self, app): resp = app.get("/kml/wms_cache_multi/1/0/0.kml") xml = resp.lxml assert validate_with_xsd(xml, "kml/2.2.0/ogckml22.xsd") assert xml.xpath( "/kml:kml/kml:Document/kml:GroundOverlay/kml:Icon/kml:href/text()", namespaces=ns, ) == [ "http://localhost/kml/wms_cache_multi/EPSG4326/2/0/1.jpeg", "http://localhost/kml/wms_cache_multi/EPSG4326/2/1/1.jpeg", "http://localhost/kml/wms_cache_multi/EPSG4326/2/0/0.jpeg", "http://localhost/kml/wms_cache_multi/EPSG4326/2/1/0.jpeg", ] assert xml.xpath( "/kml:kml/kml:Document/kml:NetworkLink/kml:Link/kml:href/text()", namespaces=ns, ) == [ "http://localhost/kml/wms_cache_multi/EPSG4326/2/0/1.kml", "http://localhost/kml/wms_cache_multi/EPSG4326/2/1/1.kml", "http://localhost/kml/wms_cache_multi/EPSG4326/2/0/0.kml", "http://localhost/kml/wms_cache_multi/EPSG4326/2/1/0.kml", ]
def test_get_kml2(self): resp = self.app.get('/kml/wms_cache/1/0/1.kml') xml = resp.lxml assert validate_with_xsd(xml, 'kml/2.2.0/ogckml22.xsd')
def test_get_tile_source_error(self): resp = self.app.get("/wmts/myrest/tms_cache/GLOBAL_MERCATOR/01/0/0.png", status=500) xml = resp.lxml assert validate_with_xsd(xml, xsd_name="ows/1.1.0/owsExceptionReport.xsd") eq_xpath_wmts(xml, "/ows:ExceptionReport/ows:Exception/@exceptionCode", "NoApplicableCode")
def test_capabilities(self): resp = self.app.get("/wmts/myrest/1.0.0/WMTSCapabilities.xml") xml = resp.lxml assert validate_with_xsd(xml, xsd_name="wmts/1.0/wmtsGetCapabilities_response.xsd") eq_(len(xml.xpath("//wmts:Layer", namespaces=ns_wmts)), 5) eq_(len(xml.xpath("//wmts:Contents/wmts:TileMatrixSet", namespaces=ns_wmts)), 5)
def check_invalid_parameter(self, url): resp = self.app.get(url, status=400) xml = resp.lxml eq_(resp.content_type, "text/xml") assert validate_with_xsd(xml, xsd_name="ows/1.1.0/owsExceptionReport.xsd") eq_xpath_wmts(xml, "/ows:ExceptionReport/ows:Exception/@exceptionCode", "InvalidParameterValue")
def is_130_capa(xml): return validate_with_xsd(xml, xsd_name='sld/1.1.0/sld_capabilities.xsd')
def is_inpire_vs_capa(xml): return validate_with_xsd(xml, xsd_name='inspire/inspire_vs/1.0/inspire_vs.xsd')