def test_combine(self): docs = [ XMLFeatureInfoDoc("<root><a>foo</a></root>"), XMLFeatureInfoDoc("<root><b>bar</b></root>"), XMLFeatureInfoDoc("<other_root><a>baz</a></other_root>"), ] result = XMLFeatureInfoDoc.combine(docs) assert strip_whitespace(result.as_string()) == strip_whitespace( b"<root><a>foo</a><b>bar</b><a>baz</a></root>") assert result.info_type == "xml"
def test_combine(self): docs = [ XMLFeatureInfoDoc('<root><a>foo</a></root>'), XMLFeatureInfoDoc('<root><b>bar</b></root>'), XMLFeatureInfoDoc('<other_root><a>baz</a></other_root>'), ] result = XMLFeatureInfoDoc.combine(docs) eq_(strip_whitespace(result.as_string()), strip_whitespace(b'<root><a>foo</a><b>bar</b><a>baz</a></root>')) eq_(result.info_type, 'xml')
def test_multiple(self): t = XSLTransformer(self.xsl_script) doc = t.transform(XMLFeatureInfoDoc.combine([ XMLFeatureInfoDoc(x) for x in [b'<a><b>ab</b></a>', b'<a><b>ab1</b><b>ab2</b><b>ab3</b></a>', b'<a><b>ab1</b><c>ac</c><b>ab2</b></a>', ]])) eq_(strip_whitespace(doc.as_string()), strip_whitespace(b''' <root> <foo>ab</foo> <foo>ab1</foo><foo>ab2</foo><foo>ab3</foo> <foo>ab1</foo><foo>ab2</foo> </root>''')) eq_(doc.info_type, 'xml')
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>')
def test_get_multiple_featureinfo_html_out(self, app): fi_body1 = b"<a><b>Bar1</b></a>" fi_body2 = b"<a><b>Bar2</b></a>" fi_body3 = b"<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(TESTSERVER_ADDRESS, [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 = app.get(self.common_fi_req) assert resp.content_type == "text/html" assert ( strip_whitespace(resp.body) == b"<html><body><h1>Bars</h1><p>Bar1</p><p>Bar2</p><p>Bar3</p></body></html>" )
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>')
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>")
def test_multiple(self): t = XSLTransformer(self.xsl_script) doc = t.transform( XMLFeatureInfoDoc.combine([ XMLFeatureInfoDoc(x) for x in [ b"<a><b>ab</b></a>", b"<a><b>ab1</b><b>ab2</b><b>ab3</b></a>", b"<a><b>ab1</b><c>ac</c><b>ab2</b></a>", ] ])) assert strip_whitespace(doc.as_string()) == strip_whitespace(b""" <root> <foo>ab</foo> <foo>ab1</foo><foo>ab2</foo><foo>ab3</foo> <foo>ab1</foo><foo>ab2</foo> </root>""") assert doc.info_type == "xml"
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>')
def test_get_multiple_featureinfo_html_out(self): fi_body1 = b"<a><b>Bar1</b></a>" fi_body2 = b"<a><b>Bar2</b></a>" fi_body3 = b"<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), b'<html><body><h1>Bars</h1><p>Bar1</p><p>Bar2</p><p>Bar3</p></body></html>' )
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; charset=UTF-8"}}, ) 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>")
def test_get_featureinfo(self): 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; charset=UTF-8' } }) 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), b'<bars><bar>Bar</bar></bars>')
def test_mixed_featureinfo(self, app): 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(TESTSERVER_ADDRESS, [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 = app.get(self.common_fi_req) assert resp.content_type == "text/plain" assert strip_whitespace( resp.body) == b"Hello<baz><foo>Bar2</foo></baz>"
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>')
def test_get_featureinfo(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; charset=UTF-8" } }, ) with mock_httpd(TESTSERVER_ADDRESS, [expected_req]): resp = app.get(self.common_fi_req) assert resp.content_type == "application/vnd.ogc.gml" assert strip_whitespace(resp.body) == b"<baz><foo>Bar</foo></baz>"
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>")
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"<bars><bar>Bar</bar></bars>"
def test_as_string(self): input_tree = etree.fromstring('<root></root>') doc = XMLFeatureInfoDoc(input_tree) eq_(strip_whitespace(doc.as_string()), b'<root/>')
def test_transformer(self): t = XSLTransformer(self.xsl_script) doc = t.transform(XMLFeatureInfoDoc('<a><b>Text</b></a>')) eq_(strip_whitespace(doc.as_string()), b'<root><foo>Text</foo></root>')
def test_as_string(self): input_tree = html.fromstring('<p>Foo') doc = HTMLFeatureInfoDoc(input_tree) assert b'<body><p>Foo</p></body>' in strip_whitespace(doc.as_string())
def test_transformer(self): t = XSLTransformer(self.xsl_script) doc = t.transform(XMLFeatureInfoDoc("<a><b>Text</b></a>")) assert strip_whitespace( doc.as_string()) == b"<root><foo>Text</foo></root>"
def test_as_string(self): input_tree = etree.fromstring("<root></root>") doc = XMLFeatureInfoDoc(input_tree) assert strip_whitespace(doc.as_string()) == b"<root/>"