Exemplo n.º 1
0
    def test_get_colorbars(self):
        ctx = ServiceContext()

        response = get_color_bars(ctx, 'application/json')
        self.assertIsInstance(response, str)
        self.assertTrue(len(response) > 40)
        self.assertEqual('[\n  [\n    "Perceptually Uniform Sequenti', response[0:40])

        response = get_color_bars(ctx, 'text/html')
        self.assertIsInstance(response, str)
        self.assertTrue(len(response) > 40)
        self.assertEqual('<!DOCTYPE html>\n<html lang="en">\n<head><', response[0:40])

        with self.assertRaises(ServiceBadRequestError) as cm:
            get_color_bars(ctx, 'text/xml')
        self.assertEqual(400, cm.exception.status_code)
        self.assertEqual("Format 'text/xml' not supported for color bars", cm.exception.reason)
Exemplo n.º 2
0
    def test_get_ne2_tile_grid(self):
        ctx = ServiceContext()
        tile_grid = get_ne2_tile_grid(ctx, 'ol4', 'http://bibo')
        self.assertEqual(
            {
                'url': self.base_url + '/ne2/tiles/{z}/{x}/{y}.jpg',
                'projection': 'EPSG:4326',
                'minZoom': 0,
                'maxZoom': 2,
                'tileGrid': {
                    'extent': [-180.0, -90.0, 180.0, 90.0],
                    'origin': [-180.0, 90.0],
                    'resolutions': [0.703125, 0.3515625, 0.17578125],
                    'tileSize': [256, 256]
                },
            }, tile_grid)

        with self.assertRaises(ServiceBadRequestError) as cm:
            get_ne2_tile_grid(ctx, 'cesium', 'http://bibo')
        self.assertEqual(400, cm.exception.status_code)
        self.assertEqual("Unknown tile client 'cesium'", cm.exception.reason)
Exemplo n.º 3
0
def new_demo_service_context() -> ServiceContext:
    ctx = ServiceContext(base_dir=get_res_demo_dir())
    config_file = os.path.join(ctx.base_dir, 'config.yml')
    with open(config_file) as fp:
        ctx.config = yaml.safe_load(fp)
    return ctx