Beispiel #1
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
            assert resp.as_image().getcolors() == [((256 * 256), (255, 0, 0))]
Beispiel #2
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))])
Beispiel #3
0
class TestTileClientOnError(object):
    def setup(self):
        self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
        self.client = TMSClient(TESTSERVER_URL)

    def test_cacheable_response(self):
        error_handler = HTTPSourceErrorHandler()
        error_handler.add_handler(500, (255, 0, 0), cacheable=True)
        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 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_multiple_image_responses(self):
        error_handler = HTTPSourceErrorHandler()
        error_handler.add_handler(500, (255, 0, 0), cacheable=False)
        error_handler.add_handler(204, (255, 0, 127, 200), cacheable=True)
        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"}}),
                ({"path": "/1/0/0.png"}, {"body": b"error", "status": 204, "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))])

            resp = self.source.get_map(MapQuery([-180, -90, 0, 90], (256, 256), SRS(4326), format="png"))
            assert resp.cacheable
            eq_(resp.as_image().getcolors(), [((256 * 256), (255, 0, 127, 200))])
Beispiel #4
0
 def setup(self):
     self.cache_dir = tempfile.mkdtemp()
     self.file_cache = FileCache(cache_dir=self.cache_dir, file_ext='png')
     self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     self.client = MockTileClient()
     self.source = TiledSource(self.grid, self.client)
     self.tile_mgr = TileManager(self.grid, self.file_cache, [self.source], 'png')
def create_wmts_source(raster_source, app_state):
    url = raster_source.url
    username = raster_source.username
    password = raster_source.password

    http_client = create_http_client(username, password)

    grid = DEFAULT_GRID
    image_opts = None
    coverage = coverage_from_geojson(raster_source.download_coverage)
    format = raster_source.format

    tpl_url = url.replace('{TileMatrix}', '%(z)s')
    tpl_url = tpl_url.replace('{TileCol}', '%(x)s')
    tpl_url = tpl_url.replace('{TileRow}', '%(y)s')

    url_template = TileURLTemplate(tpl_url, format=format)
    client = TileClient(url_template, http_client=http_client, grid=grid)

    if app_state.tilebox.is_running():
        port = app_state.config.get('tilebox', 'port')
        url_template = TileURLTemplate(
            'http://127.0.0.1:%d/%s/%s-%%(z)s-%%(x)s-%%(y)s/tile' %
            (port, raster_source.layer, raster_source.matrix_set),
            format=format)
        tilebox_client = TileClient(url_template,
                                    http_client=RequestsHTTPClient(),
                                    grid=grid)
        client = FallbackTileClient(tilebox_client, client)

    return TiledSource(grid, client, coverage=coverage, image_opts=image_opts)
Beispiel #6
0
def create_source(raster_source, app_state):
    url = raster_source.url
    username = raster_source.username
    password = raster_source.password

    http_client = HTTPClient(url, username, password)
                            # , insecure=insecure,
                             # ssl_ca_certs=ssl_ca_certs, timeout=timeout,
                             # headers=headers)

    grid = DEFAULT_GRID
    image_opts = None
    coverage = coverage_from_geojson(raster_source.download_coverage)
    format = raster_source.format

    url_template = TileURLTemplate(
        '%s/%s/%s-%%(z)s-%%(x)s-%%(y)s/tile' % (url, raster_source.layer, raster_source.matrix_set),
        format=format)
    client = TileClient(url_template, http_client=http_client, grid=grid)

    if app_state.tilebox.is_running():
        port = app_state.config.get('tilebox', 'port')
        url_template = TileURLTemplate(
            'http://127.0.0.1:%d/%s/%s-%%(z)s-%%(x)s-%%(y)s/tile' % (port, raster_source.layer, raster_source.matrix_set),
            format=format)
        tilebox_client =  TileClient(url_template, http_client=RequestsHTTPClient(), grid=grid)
        client = FallbackTileClient(tilebox_client, client)

    return TiledSource(grid, client, coverage=coverage, image_opts=image_opts)
Beispiel #7
0
 def tile_mgr(self, tile_locker, mock_file_cache, mock_tile_client):
     grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     source = TiledSource(grid, mock_tile_client)
     image_opts = ImageOptions(format='image/png')
     return TileManager(grid, mock_file_cache, [source], 'png',
         image_opts=image_opts,
         locker=tile_locker,
     )
Beispiel #8
0
 def setup(self):
     self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     self.source = TiledSource(self.grid, None)
     self.tile_mgr = TileManager(self.grid,
                                 MockCache(), [self.source],
                                 "png",
                                 locker=DummyLocker())
     self.seed_pool = MockSeedPool()
Beispiel #9
0
 def setup(self):
     self.file_cache = MockFileCache('/dev/null', 'png', lock_dir=tmp_lock_dir)
     self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     self.client = MockTileClient()
     self.source = TiledSource(self.grid, self.client)
     self.image_opts = ImageOptions(format='image/png')
     self.tile_mgr = TileManager(self.grid, self.file_cache, [self.source], 'png',
         image_opts=self.image_opts)
Beispiel #10
0
 def tile_mgr(self, file_cache, tile_locker):
     grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     client = MockTileClient()
     source = TiledSource(grid, client)
     tile_mgr = TileManager(grid,
                            file_cache, [source],
                            'png',
                            locker=tile_locker)
     return tile_mgr
Beispiel #11
0
class TestTileClientOnError(object):
    def setup(self):
        self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
        self.client = TileClient(TileURLTemplate(TESTSERVER_URL))

    def test_cacheable_response(self):
        error_handler = HTTPSourceErrorHandler()
        error_handler.add_handler(500, (255, 0, 0), cacheable=True)
        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 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_multiple_image_responses(self):
        error_handler = HTTPSourceErrorHandler()
        error_handler.add_handler(500, (255, 0, 0), cacheable=False)
        error_handler.add_handler(204, (255, 0, 127, 200), cacheable=True)
        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'}}),
            ({'path': '/1/0/0.png'}, {'body': b'error', 'status': 204, '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))])

            resp = self.source.get_map(MapQuery([-180, -90, 0, 90], (256, 256), SRS(4326), format='png'))
            assert resp.cacheable
            eq_(resp.as_image().getcolors(), [((256*256), (255, 0, 127, 200))])
Beispiel #12
0
 def setup(self):
     self.cache_dir = tempfile.mkdtemp()
     self.file_cache = FileCache(cache_dir=self.cache_dir, file_ext='png')
     self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     self.client = MockTileClient()
     self.source = TiledSource(self.grid, self.client)
     self.image_opts = ImageOptions(format='image/png')
     self.locker = TileLocker(tmp_lock_dir, 10, "id")
     self.tile_mgr = TileManager(self.grid, self.file_cache, [self.source], 'png',
         image_opts=self.image_opts,
         locker=self.locker)
Beispiel #13
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))])
Beispiel #14
0
class TestTiledSourceGlobalGeodetic(object):
    def setup(self):
        self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
        self.client = MockTileClient()
        self.source = TiledSource(self.grid, self.client)
    def test_match(self):
        self.source.get_map(MapQuery([-180, -90, 0, 90], (256, 256), SRS(4326)))
        self.source.get_map(MapQuery([0, -90, 180, 90], (256, 256), SRS(4326)))
        eq_(self.client.requested_tiles, [(0, 0, 1), (1, 0, 1)])
    @raises(InvalidSourceQuery)
    def test_wrong_size(self):
        self.source.get_map(MapQuery([-180, -90, 0, 90], (512, 256), SRS(4326)))
    @raises(InvalidSourceQuery)
    def test_wrong_srs(self):
        self.source.get_map(MapQuery([-180, -90, 0, 90], (512, 256), SRS(4326)))
Beispiel #15
0
class TestTiledSourceGlobalGeodetic(object):
    def setup(self):
        self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
        self.client = MockTileClient()
        self.source = TiledSource(self.grid, self.client)
    def test_match(self):
        self.source.get_map(MapQuery([-180, -90, 0, 90], (256, 256), SRS(4326)))
        self.source.get_map(MapQuery([0, -90, 180, 90], (256, 256), SRS(4326)))
        assert self.client.requested_tiles == [(0, 0, 1), (1, 0, 1)]
    def test_wrong_size(self):
        with pytest.raises(InvalidSourceQuery):
            self.source.get_map(MapQuery([-180, -90, 0, 90], (512, 256), SRS(4326)))
    def test_wrong_srs(self):
        with pytest.raises(InvalidSourceQuery):
            self.source.get_map(MapQuery([-180, -90, 0, 90], (512, 256), SRS(4326)))
Beispiel #16
0
 def setup(self):
     self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     self.client = MockTileClient()
     self.source = TiledSource(self.grid, self.client)
Beispiel #17
0
 def setup(self):
     self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
     self.client = MockTileClient()
     self.source = TiledSource(self.grid, self.client)
Beispiel #18
0
class TestTileClientOnError(object):
    def setup(self):
        self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90])
        self.client = TileClient(TileURLTemplate(TESTSERVER_URL))

    def test_cacheable_response(self):
        error_handler = HTTPSourceErrorHandler()
        error_handler.add_handler(500, (255, 0, 0), cacheable=True)
        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 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
            assert resp.as_image().getcolors() == [((256 * 256), (255, 0, 0))]

    def test_multiple_image_responses(self):
        error_handler = HTTPSourceErrorHandler()
        error_handler.add_handler(500, (255, 0, 0), cacheable=False)
        error_handler.add_handler(204, (255, 0, 127, 200), cacheable=True)
        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"
                        },
                    },
                ),
                (
                    {
                        "path": "/1/0/0.png"
                    },
                    {
                        "body": b"error",
                        "status": 204,
                        "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))]

            resp = self.source.get_map(
                MapQuery([-180, -90, 0, 90], (256, 256),
                         SRS(4326),
                         format="png"))
            assert resp.cacheable
            assert resp.as_image().getcolors() == [((256 * 256), (255, 0, 127,
                                                                  200))]