def test_url_pattern_fail(self): with self.assertRaises(ValueError) as cm: service.url_pattern('/open/{{ws/name}}') self.assertEqual(str(cm.exception), 'name in {{name}} must be a valid identifier, but got "ws/name"') with self.assertRaises(ValueError) as cm: service.url_pattern('/info/{{id}') self.assertEqual(str(cm.exception), 'no matching "}}" after "{{" in "/info/{{id}"')
def test_url_pattern_ok(self): self.assertEqual(service.url_pattern('/version'), '/version') self.assertEqual(service.url_pattern('{{num}}/get'), '(?P<num>[^\;\/\?\:\@\&\=\+\$\,]+)/get') self.assertEqual(service.url_pattern('/open/{{ws_name}}'), '/open/(?P<ws_name>[^\;\/\?\:\@\&\=\+\$\,]+)') self.assertEqual(service.url_pattern('/open/ws{{id1}}/wf{{id2}}'), '/open/ws(?P<id1>[^\;\/\?\:\@\&\=\+\$\,]+)/wf(?P<id2>[^\;\/\?\:\@\&\=\+\$\,]+)')
def test_url_pattern_works(self): re_pattern = service.url_pattern('/open/{{id1}}ws/{{id2}}wf') matcher = re.fullmatch(re_pattern, '/open/34ws/a66wf') self.assertIsNotNone(matcher) self.assertEqual(matcher.groupdict(), {'id1': '34', 'id2': 'a66'}) re_pattern = service.url_pattern('/open/ws{{id1}}/wf{{id2}}') matcher = re.fullmatch(re_pattern, '/open/ws34/wfa66') self.assertIsNotNone(matcher) self.assertEqual(matcher.groupdict(), {'id1': '34', 'id2': 'a66'}) x = 'C%3A%5CUsers%5CNorman%5CIdeaProjects%5Cccitools%5Cect-core%5Ctest%5Cui%5CTEST_WS_3' re_pattern = service.url_pattern('/ws/{{base_dir}}/res/{{res_name}}/add') matcher = re.fullmatch(re_pattern, '/ws/%s/res/SST/add' % x) self.assertIsNotNone(matcher) self.assertEqual(matcher.groupdict(), {'base_dir': x, 'res_name': 'SST'})
def new_application(name: str = DEFAULT_NAME): prefix = f"/{name}{API_PREFIX}" application = Application([ (prefix + '/res/(.*)', StaticFileHandler, { 'path': os.path.join(os.path.dirname(__file__), 'res') }), (prefix + url_pattern('/'), InfoHandler), (prefix + url_pattern('/wmts/kvp'), WMTSKvpHandler), (prefix + url_pattern('/wmts/1.0.0/WMTSCapabilities.xml'), GetWMTSCapabilitiesXmlHandler), (prefix + url_pattern( '/wmts/1.0.0/tile/{{ds_name}}/{{var_name}}/{{z}}/{{y}}/{{x}}.png'), GetTileDatasetHandler), (prefix + url_pattern('/tile/{{ds_name}}/{{var_name}}/{{z}}/{{x}}/{{y}}.png'), GetTileDatasetHandler), (prefix + url_pattern('/tile/ne2/{{z}}/{{x}}/{{y}}.jpg'), GetTileNE2Handler), (prefix + url_pattern('/tilegrid/{{ds_name}}/{{var_name}}/{{format_name}}'), GetTileGridDatasetHandler), (prefix + url_pattern('/tilegrid/ne2/{{format_name}}'), GetTileGridNE2Handler), (prefix + url_pattern('/datasets'), GetDatasetsJsonHandler), (prefix + url_pattern('/variables/{{ds_name}}'), GetVariablesJsonHandler), (prefix + url_pattern('/coords/{{ds_name}}/{{dim_name}}'), GetCoordinatesJsonHandler), (prefix + url_pattern('/legend/{{ds_name}}/{{var_name}}.png'), GetLegendHandler), (prefix + url_pattern('/colorbars'), GetColorBarsJsonHandler), (prefix + url_pattern('/colorbars.html'), GetColorBarsHtmlHandler), (prefix + url_pattern('/ts'), TimeSeriesInfoHandler), (prefix + url_pattern('/ts/{{ds_name}}/{{var_name}}/point'), TimeSeriesForPointHandler), (prefix + url_pattern('/ts/{{ds_name}}/{{var_name}}/geometry'), TimeSeriesForGeometryHandler), (prefix + url_pattern('/ts/{{ds_name}}/{{var_name}}/geometries'), TimeSeriesForGeometriesHandler), (prefix + url_pattern('/ts/{{ds_name}}/{{var_name}}/features'), TimeSeriesForFeaturesHandler), (prefix + url_pattern('/features'), GetFeatureCollectionsHandler), (prefix + url_pattern('/features/{{collection_name}}'), FindFeaturesHandler), (prefix + url_pattern('/features/{{collection_name}}/{{ds_name}}'), FindDatasetFeaturesHandler), ]) return application
def new_application(name: str = DEFAULT_NAME): prefix = f"/{name}{API_PREFIX}" application = Application([ (prefix + '/res/(.*)', StaticFileHandler, {'path': os.path.join(os.path.dirname(__file__), 'res')}), (prefix + url_pattern('/'), InfoHandler), (prefix + url_pattern('/wmts/1.0.0/WMTSCapabilities.xml'), GetWMTSCapabilitiesXmlHandler), (prefix + url_pattern('/wmts/1.0.0/tile/{{ds_id}}/{{var_name}}/{{z}}/{{y}}/{{x}}.png'), GetDatasetVarTileHandler), (prefix + url_pattern('/wmts/kvp'), WMTSKvpHandler), # Natural Earth 2 tiles for testing (prefix + url_pattern('/datasets'), GetDatasetsHandler), (prefix + url_pattern('/datasets/{{ds_id}}'), GetDatasetHandler), (prefix + url_pattern('/datasets/{{ds_id}}/coords/{{dim_name}}'), GetDatasetCoordsHandler), (prefix + url_pattern('/datasets/{{ds_id}}/vars/{{var_name}}/legend.png'), GetDatasetVarLegendHandler), (prefix + url_pattern('/datasets/{{ds_id}}/vars/{{var_name}}/tiles/{{z}}/{{x}}/{{y}}.png'), GetDatasetVarTileHandler), (prefix + url_pattern('/datasets/{{ds_id}}/vars/{{var_name}}/tilegrid'), GetDatasetVarTileGridHandler), # Natural Earth 2 tiles for testing (prefix + url_pattern('/ne2/tilegrid'), GetNE2TileGridHandler), (prefix + url_pattern('/ne2/tiles/{{z}}/{{x}}/{{y}}.jpg'), GetNE2TileHandler), # Color Bars API (prefix + url_pattern('/colorbars'), GetColorBarsJsonHandler), (prefix + url_pattern('/colorbars.html'), GetColorBarsHtmlHandler), # Places API (PRELIMINARY & UNSTABLE - will be revised soon) (prefix + url_pattern('/places'), GetPlaceGroupsHandler), (prefix + url_pattern('/places/{{collection_name}}'), FindPlacesHandler), (prefix + url_pattern('/places/{{collection_name}}/{{ds_id}}'), FindDatasetPlacesHandler), # Time-series API (for VITO's DCS4COP viewer only, PRELIMINARY & UNSTABLE - will be revised soon) (prefix + url_pattern('/ts'), GetTimeSeriesInfoHandler), (prefix + url_pattern('/ts/{{ds_id}}/{{var_name}}/point'), GetTimeSeriesForPointHandler), (prefix + url_pattern('/ts/{{ds_id}}/{{var_name}}/geometry'), GetTimeSeriesForGeometryHandler), (prefix + url_pattern('/ts/{{ds_id}}/{{var_name}}/geometries'), GetTimeSeriesForGeometriesHandler), (prefix + url_pattern('/ts/{{ds_id}}/{{var_name}}/places'), GetTimeSeriesForFeaturesHandler), ]) return application