def test_get_map_transformed(self): self.source.get_map(MapQuery( (556597, 4865942, 1669792, 7361866), (300, 150), SRS(900913))) assert_query_eq(self.http_client.requested[0], "http://localhost/service?" "layers=foo&width=300&version=1.1.1" "&bbox=4.99999592195,39.9999980766,14.999996749,54.9999994175&service=WMS" "&format=image%2Fpng&styles=&srs=EPSG%3A4326&request=GetMap&height=450")
def test_transformed_request_transparent(self): self.req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo', param={ 'layers': 'foo', 'transparent': 'true' }) self.wms = WMSClient(self.req, http_client=self.http) self.source = WMSSource(self.wms, supported_srs=[SRS(4326)], image_opts=ImageOptions(resampling='bilinear')) req = MapQuery((-200000, -200000, 200000, 200000), (512, 512), SRS(900913), 'png') resp = self.source.get_map(req) eq_(len(self.http.requested), 1) assert_query_eq( self.http.requested[0], TESTSERVER_URL + '/service?map=foo&LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng' '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326' '&VERSION=1.1.1&WIDTH=512&STYLES=&transparent=true' '&BBOX=-1.79663056824,-1.7963362121,1.79663056824,1.7963362121') img = resp.as_image() assert img.mode in ('P', 'RGBA') img = img.convert('RGBA') eq_(img.getpixel((5, 5))[3], 0)
def test_request(self): req = MapQuery((-180.0, -90.0, 180.0, 90.0), (512, 256), SRS(4326), 'png') self.source.get_map(req) eq_(len(self.http.requested), 1) assert_query_eq(self.http.requested[0], TESTSERVER_URL+'/service?map=foo&LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng' '&REQUEST=GetMap&HEIGHT=256&SRS=EPSG%3A4326' '&VERSION=1.1.1&BBOX=-180.0,-90.0,180.0,90.0&WIDTH=512&STYLES=')
def test_request(self, source, mock_http_client): req = MapQuery((-180.0, -90.0, 180.0, 90.0), (512, 256), SRS(4326), 'png') source.get_map(req) assert len(mock_http_client.requested) == 1 assert_query_eq(mock_http_client.requested[0], TESTSERVER_URL+'/service?map=foo&LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng' '&REQUEST=GetMap&HEIGHT=256&SRS=EPSG%3A4326' '&VERSION=1.1.1&BBOX=-180.0,-90.0,180.0,90.0&WIDTH=512&STYLES=')
def test_transformed_request(self): req = MapQuery((-200000, -200000, 200000, 200000), (512, 512), SRS(900913), 'png') resp = self.source.get_map(req) eq_(len(self.http.requested), 1) assert_query_eq(self.http.requested[0], TESTSERVER_URL+'/service?map=foo&LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng' '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326' '&VERSION=1.1.1&WIDTH=512&STYLES=' '&BBOX=-1.79663056824,-1.7963362121,1.79663056824,1.7963362121') img = resp.as_image() assert img.mode in ('P', 'RGB')
def test_transform_fi_request_supported_srs(self): req = ArcGISIdentifyRequest(url=TESTSERVER_URL + '/MapServer/export?map=foo', param={'layers':'foo'}) http = MockHTTPClient() wms = ArcGISInfoClient(req, http_client=http, supported_srs=[SRS(25832)]) fi_req = InfoQuery((8, 50, 9, 51), (512, 512), SRS(4326), (128, 64), 'text/plain') wms.get_info(fi_req) assert_query_eq(http.requested[0], TESTSERVER_URL+'/MapServer/identify?map=foo' '&imageDisplay=512,797,96&sr=25832&f=json' '&layers=foo&tolerance=5&returnGeometry=false' '&geometryType=esriGeometryPoint&geometry=447229.979084,5636149.370634' '&mapExtent=428333.552496,5538630.70275,500000.0,5650300.78652', fuzzy_number_compare=True)
def test_fi_request(self): req = ArcGISIdentifyRequest(url=TESTSERVER_URL + '/MapServer/export?map=foo', param={'layers':'foo'}) http = MockHTTPClient() wms = ArcGISInfoClient(req, http_client=http, supported_srs=[SRS(4326)]) fi_req = InfoQuery((8, 50, 9, 51), (512, 512), SRS(4326), (128, 64), 'text/plain') wms.get_info(fi_req) assert_query_eq(http.requested[0], TESTSERVER_URL+'/MapServer/identify?map=foo' '&imageDisplay=512,512,96&sr=4326&f=json' '&layers=foo&tolerance=5&returnGeometry=false' '&geometryType=esriGeometryPoint&geometry=8.250000,50.875000' '&mapExtent=8,50,9,51', fuzzy_number_compare=True)
def test_similar_srs(self): # request in 3857 and source supports only 900913 # 3857 and 900913 are equal but the client requests must use 900913 self.req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo', param={'layers':'foo', 'transparent': 'true'}) self.wms = WMSClient(self.req, http_client=self.http) self.source = WMSSource(self.wms, supported_srs=[SRS(900913)], image_opts=ImageOptions(resampling='bilinear')) req = MapQuery((-200000, -200000, 200000, 200000), (512, 512), SRS(3857), 'png') self.source.get_map(req) eq_(len(self.http.requested), 1) assert_query_eq(self.http.requested[0], TESTSERVER_URL+'/service?map=foo&LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng' '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A900913' '&VERSION=1.1.1&WIDTH=512&STYLES=&transparent=true' '&BBOX=-200000,-200000,200000,200000')
def test_transformed_request_transparent(self): self.req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo', param={'layers':'foo', 'transparent': 'true'}) self.wms = WMSClient(self.req, http_client=self.http) self.source = WMSSource(self.wms, supported_srs=[SRS(4326)], image_opts=ImageOptions(resampling='bilinear')) req = MapQuery((-200000, -200000, 200000, 200000), (512, 512), SRS(900913), 'png') resp = self.source.get_map(req) eq_(len(self.http.requested), 1) assert_query_eq(self.http.requested[0], TESTSERVER_URL+'/service?map=foo&LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng' '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326' '&VERSION=1.1.1&WIDTH=512&STYLES=&transparent=true' '&BBOX=-1.79663056824,-1.7963362121,1.79663056824,1.7963362121') img = resp.as_image() assert img.mode in ('P', 'RGBA') img = img.convert('RGBA') eq_(img.getpixel((5, 5))[3], 0)
def test_query_string(self): print(self.m.query_string) assert_query_eq(self.m.query_string, 'layers=bar,foo&WIdth=100&bBOx=-90,-80,70.0,+80' '&format=image%2Fpng&srs=EPSG%3A0815&heIGHT=200')
def test_str(self): assert_query_eq(str(self.r.params), 'layers=foo&styles=&request=map&wmtver=1.0.0')
def test_wms_capabilities_url(): assert_query_eq(wms_capabilities_url('http://foo/'), 'http://foo/?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1') assert_query_eq(wms_capabilities_url('http://foo/service'), 'http://foo/service?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1') assert_query_eq(wms_capabilities_url('http://foo/service?'), 'http://foo/service?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1') assert_query_eq(wms_capabilities_url('http://foo:8080/bar/service?'), 'http://foo:8080/bar/service?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1') assert_query_eq(wms_capabilities_url('http://foo:8080/bar/service?REQUEST=getcapabilities'), 'http://foo:8080/bar/service?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1') assert_query_eq(wms_capabilities_url('http://foo:8080/bar/service?Version=1.3.0'), 'http://foo:8080/bar/service?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1') assert_query_eq(wms_capabilities_url('http://foo:8080/bar/service?key=value'), 'http://foo:8080/bar/service?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1&key=value')
def test_query_string(self): print(self.m.query_string) assert_query_eq( self.m.query_string, 'layers=bar,foo&WIdth=100&bBOx=-90,-80,70.0,+80' '&format=image%2Fpng&srs=EPSG%3A0815&heIGHT=200')
def test_wms_capabilities_url(): assert_query_eq( wms_capabilities_url('http://foo/'), 'http://foo/?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1') assert_query_eq( wms_capabilities_url('http://foo/service'), 'http://foo/service?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1') assert_query_eq( wms_capabilities_url('http://foo/service?'), 'http://foo/service?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1') assert_query_eq( wms_capabilities_url('http://foo:8080/bar/service?'), 'http://foo:8080/bar/service?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1' ) assert_query_eq( wms_capabilities_url( 'http://foo:8080/bar/service?REQUEST=getcapabilities'), 'http://foo:8080/bar/service?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1' ) assert_query_eq( wms_capabilities_url('http://foo:8080/bar/service?Version=1.3.0'), 'http://foo:8080/bar/service?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1' ) assert_query_eq( wms_capabilities_url('http://foo:8080/bar/service?key=value'), 'http://foo:8080/bar/service?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1&key=value' )