def test_image_response(self): error_handler = HTTPSourceErrorHandler() error_handler.add_handler(500, (255, 0, 0), cacheable=False) self.source = TiledSource(self.grid, self.client, error_handler=error_handler) with mock_httpd( TEST_SERVER_ADDRESS, [( { "path": "/1/0/0.png" }, { "body": b"error", "status": 500, "headers": { "content-type": "text/plain" }, }, )], ): resp = self.source.get_map( MapQuery([-180, -90, 0, 90], (256, 256), SRS(4326), format="png")) assert not resp.cacheable assert resp.as_image().getcolors() == [((256 * 256), (255, 0, 0))]
def test_image_response(self): error_handler = HTTPSourceErrorHandler() error_handler.add_handler(500, (255, 0, 0), cacheable=False) self.source = TiledSource(self.grid, self.client, error_handler=error_handler) with mock_httpd(TEST_SERVER_ADDRESS, [({'path': '/1/0/0.png'}, {'body': b'error', 'status': 500, 'headers':{'content-type': 'text/plain'}})]): resp = self.source.get_map(MapQuery([-180, -90, 0, 90], (256, 256), SRS(4326), format='png')) assert not resp.cacheable eq_(resp.as_image().getcolors(), [((256*256), (255, 0, 0))])
def test_image_response(self): error_handler = HTTPSourceErrorHandler() error_handler.add_handler(500, (255, 0, 0), cacheable=False) self.source = TiledSource(self.grid, self.client, error_handler=error_handler) with mock_httpd( TEST_SERVER_ADDRESS, [({"path": "/1/0/0.png"}, {"body": b"error", "status": 500, "headers": {"content-type": "text/plain"}})], ): resp = self.source.get_map(MapQuery([-180, -90, 0, 90], (256, 256), SRS(4326), format="png")) assert not resp.cacheable eq_(resp.as_image().getcolors(), [((256 * 256), (255, 0, 0))])
def test_http_error_handler(self, client): error_handler = HTTPSourceErrorHandler() error_handler.add_handler(500, (255, 0, 0), cacheable=True) error_handler.add_handler(400, (0, 0, 0), cacheable=False) source = WMSSource(client, error_handler=error_handler) expected_req = [ ( { 'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng' '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326' '&VERSION=1.1.1&BBOX=0.0,10.0,10.0,20.0&WIDTH=512&STYLES=' }, { 'body': b'error', 'status': 500, 'headers': { 'content-type': 'text/plain' }, }, ), ( { 'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng' '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326' '&VERSION=1.1.1&BBOX=0.0,10.0,10.0,20.0&WIDTH=512&STYLES=' }, { 'body': b'error', 'status': 400, 'headers': { 'content-type': 'text/plain' }, }, ), ] with mock_httpd(TEST_SERVER_ADDRESS, expected_req): query = MapQuery((0.0, 10.0, 10.0, 20.0), (512, 512), SRS(4326)) resp = source.get_map(query) assert resp.cacheable assert resp.as_image().getcolors() == [((512 * 512), (255, 0, 0))] resp = source.get_map(query) assert not resp.cacheable assert resp.as_image().getcolors() == [((512 * 512), (0, 0, 0))]