def clean_config(self): config = self.cleaned_data.get('config') service_type = self.cleaned_data.get('export_provider_type').type_name if service_type in ['wms', 'wmts', 'tms']: from eventkit_cloud.utils.mapproxy import MapproxyGeopackage, \ ConfigurationError service = MapproxyGeopackage( layer=self.cleaned_data.get('layer'), service_type=self.cleaned_data.get('export_provider_type'), config=config) try: service.get_check_config() except ConfigurationError as e: raise forms.ValidationError(str(e)) elif service_type in ['osm', 'osm-generic']: if not config: raise forms.ValidationError( "Configuration is required for OSM data providers") from eventkit_cloud.feature_selection.feature_selection import FeatureSelection feature_selection = FeatureSelection(config) feature_selection.valid if feature_selection.errors: raise forms.ValidationError( "Invalid configuration: {0}".format( feature_selection.errors)) return config
def clean_config(self): config = self.cleaned_data.get("config") service_type = self.cleaned_data.get("export_provider_type").type_name if service_type in ["wms", "wmts", "tms", "arcgis-raster"]: from eventkit_cloud.utils.mapproxy import ConfigurationError, MapproxyGeopackage service = MapproxyGeopackage( layer=self.cleaned_data.get("layer"), service_type=self.cleaned_data.get("export_provider_type"), config=config, ) try: service.get_check_config() except ConfigurationError as e: raise forms.ValidationError(str(e)) elif service_type in ["osm", "osm-generic"]: if not config: raise forms.ValidationError( "Configuration is required for OSM data providers") from eventkit_cloud.feature_selection.feature_selection import FeatureSelection feature_selection = FeatureSelection(clean_config_as_str(config)) if feature_selection.errors: raise forms.ValidationError( "Invalid configuration: {0}".format( feature_selection.errors)) elif service_type in ["ogcapi-process"]: if not config: raise forms.ValidationError( "Configuration is required for OGC API Process") cleaned_config = clean_config(config) assert isinstance(cleaned_config, dict) ogcapi_process = cleaned_config.get("ogcapi_process") if not ogcapi_process: raise forms.ValidationError( "OGC API Process requires an ogcapi_process key with valid configuration" ) area = ogcapi_process.get("area") if not area: raise forms.ValidationError( "OGC API Process requires an area key with a name and a type." ) if not area.get("name"): raise forms.ValidationError( "OGC API Process requires the name of the field to submit the area." ) if area.get("type") not in ["geojson", "bbox", "wkt"]: raise forms.ValidationError( "OGC API Process requires an area type of geojson, bbox, or wkt." ) if not ogcapi_process.get("id"): raise forms.ValidationError( "OGC API Process requires a process id.") return config
def test_convert(self, seed_template, cache_template, load_config, seeder, seeding_config, connections, remove_zoom_levels, mock_check_zoom_levels, mock_set_gpkg_contents_bounds, patch_https, mock_retry): gpkgfile = '/var/lib/eventkit/test.gpkg' config = "layers:\r\n - name: imagery\r\n title: imagery\r\n sources: [cache]\r\n\r\nsources:\r\n imagery:\r\n type: tile\r\n grid: webmercator\r\n url: http://a.tile.openstreetmap.fr/hot/%(z)s/%(x)s/%(y)s.png\r\n\r\ngrids:\r\n webmercator:\r\n srs: EPSG:3857\r\n tile_size: [256, 256]\r\n origin: nw" json_config = real_yaml.load(config) mapproxy_config = load_default_config() bbox = [-2, -2, 2, 2] cache_template.return_value = {'sources': ['imagery'], 'cache': {'type': 'geopackage', 'filename': '/var/lib/eventkit/test.gpkg'}, 'grids': ['webmercator']} seed_template.return_value = {'coverages': {'geom': {'srs': 'EPSG:4326', 'bbox': [-2, -2, 2, 2]}}, 'seeds': {'seed': {'coverages': ['geom'], 'refresh_before': {'minutes': 0}, 'levels': {'to': 10, 'from': 0}, 'caches': ['cache']}}} self.task_process.return_value = Mock(exitcode=0) w2g = MapproxyGeopackage(config=config, gpkgfile=gpkgfile, bbox=bbox, service_url='http://generic.server/WMTS?SERVICE=WMTS&REQUEST=GetTile&TILEMATRIXSET=default028mm&TILEMATRIX=%(z)s&TILEROW=%(y)s&TILECOL=%(x)s&FORMAT=image%%2Fpng', layer='imagery', debug=True, name='imagery', level_from=0, level_to=10, service_type='wmts', task_uid=self.task_uid) result = w2g.convert() mock_check_zoom_levels.assert_called_once() connections.close_all.assert_called_once() self.assertEqual(result, gpkgfile) cache_template.assert_called_once_with(["imagery"], [grids for grids in json_config.get('grids')], gpkgfile, table_name='imagery') json_config['caches'] = {'cache': {'sources': ['imagery'], 'cache': {'type': 'geopackage', 'filename': '/var/lib/eventkit/test.gpkg'}, 'grids': ['webmercator']}} json_config['services'] = ['demo'] patch_https.assert_called_once_with('imagery') load_config.assert_called_once_with(mapproxy_config, config_dict=json_config) remove_zoom_levels.assert_called_once_with(gpkgfile) mock_set_gpkg_contents_bounds.assert_called_once_with(gpkgfile, 'imagery', bbox) seed_template.assert_called_once_with(bbox=bbox, coverage_file=None, level_from=0, level_to=10) self.task_process.side_effect = Exception() with self.assertRaises(Exception): w2g.convert()
def clean_config(self): config = self.cleaned_data.get('config') service_type = self.cleaned_data.get('export_provider_type').type_name if service_type in ['wms', 'wmts', 'tms']: from eventkit_cloud.utils.mapproxy import MapproxyGeopackage, \ ConfigurationError service = MapproxyGeopackage(layer=self.cleaned_data.get('layer'), service_type=self.cleaned_data.get('export_provider_type'), config=config) try: service.get_check_config() except ConfigurationError as e: raise forms.ValidationError(str(e)) elif service_type in ['osm', 'osm-generic']: if not config: raise forms.ValidationError("Configuration is required for OSM data providers") from eventkit_cloud.feature_selection.feature_selection import FeatureSelection feature_selection = FeatureSelection(config) feature_selection.valid if feature_selection.errors: raise forms.ValidationError("Invalid configuration: {0}".format(feature_selection.errors)) return config
def test_convert( self, seed_template, cache_template, load_config, seeder, seeding_config, connections, remove_zoom_levels, mock_check_zoom_levels, mock_set_gpkg_contents_bounds, patch_https, ): with self.settings(SSL_VERIFICATION=True): gpkgfile = "/var/lib/eventkit/test.gpkg" config = ( "layers:\r\n - name: default\r\n title: imagery\r\n sources: [default]\r\n\r\nsources:\r\n " "default:\r\n type: tile\r\n grid: default\r\n " "url: http://a.tile.openstreetmap.fr/hot/%(z)s/%(x)s/%(y)s.png\r\n\r\ngrids:\r\n default:\r\n " "srs: WGS84:3857\r\n tile_size: [256, 256]\r\n origin: nw" ) json_config = real_yaml.safe_load(config) mapproxy_config = load_default_config() bbox = [-2, -2, 2, 2] cache_template.return_value = { "sources": ["default"], "cache": { "type": "geopackage", "filename": "/var/lib/eventkit/test.gpkg" }, "grids": ["default"], } seed_template.return_value = { "coverages": { "geom": { "srs": "EPSG:4326", "bbox": [-2, -2, 2, 2] } }, "seeds": { "seed": { "coverages": ["geom"], "refresh_before": { "minutes": 0 }, "levels": { "to": 10, "from": 0 }, "caches": ["default"], } }, } self.task_process.return_value = Mock(exitcode=0) w2g = MapproxyGeopackage( config=config, gpkgfile=gpkgfile, bbox=bbox, service_url= "http://generic.server/WMTS?SERVICE=WMTS&REQUEST=GetTile&TILEMATRIXSET=default028mm&" "TILEMATRIX=%(z)s&TILEROW=%(y)s&TILECOL=%(x)s&FORMAT=image%%2Fpng", layer="imagery", debug=True, name="imagery", level_from=0, level_to=10, service_type="wmts", task_uid=self.task_uid, ) result = w2g.convert() mock_check_zoom_levels.assert_called_once() connections.close_all.assert_called_once() self.assertEqual(result, gpkgfile) cache_template.assert_called_once_with( ["imagery"], [grids for grids in json_config.get("grids")], gpkgfile, table_name="imagery") json_config["caches"] = { "default": { "sources": ["default"], "cache": { "type": "geopackage", "filename": "/var/lib/eventkit/test.gpkg" }, "grids": ["default"], } } json_config["services"] = ["demo"] patch_https.assert_called_once_with(cert_info=None) load_config.assert_called_once_with(mapproxy_config, config_dict=json_config) remove_zoom_levels.assert_called_once_with(gpkgfile) mock_set_gpkg_contents_bounds.assert_called_once_with( gpkgfile, "imagery", bbox) seed_template.assert_called_once_with(bbox=bbox, coverage_file=None, level_from=0, level_to=10, projection=None) self.task_process.side_effect = Exception() with self.assertRaises(Exception): w2g.convert()