def test_same_source(self): layers = [ WMSSource( WMSClient(create_request({"url": "http://foo/", "layers": "a"}, {})) ), WMSSource( WMSClient(create_request({"url": "http://foo/", "layers": "b"}, {})) ), ] combined = combined_layers(layers, self.q) assert len(combined) == 1 assert combined[0].client.request_template.params.layers == ["a", "b"]
def test_combine_different_url(self): req1 = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=bar', param={'layers':'foo', 'transparent': 'true'}) wms1 = WMSClient(req1, http_client=self.http) req2 = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo', param={'layers':'bar', 'transparent': 'true'}) wms2 = WMSClient(req2, http_client=self.http) req = MapQuery((-200000, -200000, 200000, 200000), (512, 512), SRS(900913), 'png') combined = wms1.combined_client(wms2, req) assert combined is None
def source(self, mock_http_client): req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo', param={'layers': 'foo'}) wms = WMSClient(req, http_client=mock_http_client) return WMSSource(wms, supported_srs=[SRS(4326)], image_opts=ImageOptions(resampling='bilinear'))
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 wms_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_no_image(self, caplog): try: with mock_httpd(TESTSERVER_ADDRESS, [({ 'path': '/service?map=foo&layers=foo&transparent=true&bbox=-200000,-200000,200000,200000&width=512&height=512&srs=EPSG%3A900913&format=image%2Fpng&request=GetMap&version=1.1.1&service=WMS&styles=' }, { 'status': '200', 'body': b'x' * 1000, 'headers': { 'content-type': 'application/foo' }, })]): req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo', param={ 'layers': 'foo', 'transparent': 'true' }) query = MapQuery((-200000, -200000, 200000, 200000), (512, 512), SRS(900913), 'png') wms = WMSClient(req).retrieve(query, 'png') except SourceError: assert len(caplog.record_tuples) == 1 assert ( "'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' [output truncated]" in caplog.record_tuples[0][2]) else: assert False, 'expected no image returned error'
def source(self, mock_http_client): req_template = WMS111MapRequest(url='http://localhost/service?', param={ 'format': 'image/png', 'layers': 'foo' }) client = WMSClient(req_template, http_client=mock_http_client) return WMSSource(client, supported_srs=SupportedSRS([SRS(4326)]), image_opts=ImageOptions(resampling='bilinear'))
def create_wms_source(raster_source, app_state): url = raster_source.url username = raster_source.username password = raster_source.password http_client = create_http_client(username, password) coverage = coverage_from_geojson(raster_source.download_coverage) if coverage: # wrap to prevent partial tiles coverage = AlwaysContainsCoverage(coverage) request = create_request({ 'url': url, 'layers': raster_source.layer }, {}, version='1.1.1') image_opts = ImageOptions(resampling='bicubic', transparent=True) supported_srs = None if raster_source.srs != 'EPSG:3857': supported_srs = [SRS(raster_source.srs)] client = WMSClient(request, http_client=http_client) source = WMSSource( client, coverage=coverage, supported_srs=supported_srs, image_opts=image_opts, ) # wrap to prevent partial tiles source.extent = AlwaysContainsMapExtent(source.extent) return source
def setup(self): self.req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo', param={'layers': 'foo'}) self.http = MockHTTPClient() self.wms = WMSClient(self.req, http_client=self.http) self.source = WMSSource(self.wms, supported_srs=[SRS(4326)], image_opts=ImageOptions(resampling='bilinear'))
def setup(self): self.http_client = MockHTTPClient() self.req_template = WMS111MapRequest(url='http://localhost/service?', param={ 'format': 'image/png', 'layers': 'foo' }) self.client = WMSClient(self.req_template, http_client=self.http_client) self.source = WMSSource(self.client, supported_srs=[SRS(4326)], image_opts=ImageOptions(resampling='bilinear'))
def test_same_source(self): layers = [ WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'a' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'b' }, {}))), ] combined = combined_layers(layers, self.q) eq_(len(combined), 1) eq_(combined[0].client.request_template.params.layers, ['a', 'b'])
def setup(self): self.req_template = WMS111MapRequest(url='http://%s:%d/service?' % TEST_SERVER_ADDRESS, param={ 'format': 'image/png', 'layers': 'foo' }) self.client = WMSClient(self.req_template) self.source = WMSSource(self.client)
def test_combine(self): req1 = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo', param={ 'layers': 'foo', 'transparent': 'true' }) wms1 = WMSClient(req1, http_client=self.http) req2 = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo', param={ 'layers': 'bar', 'transparent': 'true' }) wms2 = WMSClient(req2, http_client=self.http) req = MapQuery((-200000, -200000, 200000, 200000), (512, 512), SRS(900913), 'png') combined = wms1.combined_client(wms2, req) eq_(combined.request_template.params.layers, ['foo', 'bar']) eq_(combined.request_template.url, TESTSERVER_URL + '/service?map=foo')
def test_mixed_hosts(self): layers = [ WMSSource( WMSClient(create_request({"url": "http://foo/", "layers": "a"}, {})) ), WMSSource( WMSClient(create_request({"url": "http://foo/", "layers": "b"}, {})) ), WMSSource( WMSClient(create_request({"url": "http://bar/", "layers": "c"}, {})) ), WMSSource( WMSClient(create_request({"url": "http://bar/", "layers": "d"}, {})) ), WMSSource( WMSClient(create_request({"url": "http://foo/", "layers": "e"}, {})) ), WMSSource( WMSClient(create_request({"url": "http://foo/", "layers": "f"}, {})) ), ] combined = combined_layers(layers, self.q) assert len(combined) == 3 assert combined[0].client.request_template.params.layers == ["a", "b"] assert combined[1].client.request_template.params.layers == ["c", "d"] assert combined[2].client.request_template.params.layers == ["e", "f"]
def test_mixed_params(self): layers = [ WMSSource( WMSClient(create_request({"url": "http://foo/", "layers": "a"}, {})) ), WMSSource( WMSClient(create_request({"url": "http://foo/", "layers": "b"}, {})) ), WMSSource( WMSClient(create_request({"url": "http://foo/", "layers": "c"}, {})) ), WMSSource( WMSClient(create_request({"url": "http://foo/", "layers": "d"}, {})) ), WMSSource( WMSClient(create_request({"url": "http://foo/", "layers": "e"}, {})) ), WMSSource( WMSClient(create_request({"url": "http://foo/", "layers": "f"}, {})) ), ] layers[0].supported_srs = ["EPSG:4326"] layers[1].supported_srs = ["EPSG:4326"] layers[2].supported_formats = ["image/png"] layers[3].supported_formats = ["image/png"] combined = combined_layers(layers, self.q) assert len(combined) == 3 assert combined[0].client.request_template.params.layers == ["a", "b"] assert combined[1].client.request_template.params.layers == ["c", "d"] assert combined[2].client.request_template.params.layers == ["e", "f"]
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_mixed_params(self): layers = [ WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'a' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'b' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'c' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'd' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'e' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'f' }, {}))), ] layers[0].supported_srs = ["EPSG:4326"] layers[1].supported_srs = ["EPSG:4326"] layers[2].supported_formats = ["image/png"] layers[3].supported_formats = ["image/png"] combined = combined_layers(layers, self.q) eq_(len(combined), 3) eq_(combined[0].client.request_template.params.layers, ['a', 'b']) eq_(combined[1].client.request_template.params.layers, ['c', 'd']) eq_(combined[2].client.request_template.params.layers, ['e', 'f'])
def test_mixed_hosts(self): layers = [ WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'a' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'b' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://bar/', 'layers': 'c' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://bar/', 'layers': 'd' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'e' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'f' }, {}))), ] combined = combined_layers(layers, self.q) eq_(len(combined), 3) eq_(combined[0].client.request_template.params.layers, ['a', 'b']) eq_(combined[1].client.request_template.params.layers, ['c', 'd']) eq_(combined[2].client.request_template.params.layers, ['e', 'f'])
def client(self, req_template): return WMSClient(req_template)