def test_cascading_delete(self): """Verify that the gs_helpers.cascading_delete() method is working properly """ gs_cat = Layer.objects.gs_catalog # Upload a Shapefile shp_file = os.path.join(gisdata.VECTOR_DATA, 'san_andres_y_providencia_poi.shp') shp_layer = file_upload(shp_file) # Save the names of the Resource/Store/Styles resource_name = shp_layer.name ws = gs_cat.get_workspace(shp_layer.workspace) store = gs_cat.get_store(shp_layer.store, ws) store_name = store.name layer = gs_cat.get_layer(resource_name) styles = layer.styles + [layer.default_style] # Delete the Layer using cascading_delete() cascading_delete(gs_cat, shp_layer.typename) # Verify that the styles were deleted for style in styles: s = gs_cat.get_style(style.name) assert s == None # Verify that the resource was deleted self.assertRaises(FailedRequestError, lambda: gs_cat.get_resource(resource_name, store=store)) # Verify that the store was deleted self.assertRaises(FailedRequestError, lambda: gs_cat.get_store(store_name)) # Clean up by deleting the layer from GeoNode's DB and GeoNetwork shp_layer.delete()
def test_cascading_delete(self): """Verify that the gs_helpers.cascading_delete() method is working properly """ gs_cat = Layer.objects.gs_catalog # Upload a Shapefile shp_file = os.path.join(gisdata.VECTOR_DATA, 'san_andres_y_providencia_poi.shp') shp_layer = file_upload(shp_file) # Save the names of the Resource/Store/Styles resource_name = shp_layer.name ws = gs_cat.get_workspace(shp_layer.workspace) store = gs_cat.get_store(shp_layer.store, ws) store_name = store.name layer = gs_cat.get_layer(resource_name) styles = layer.styles + [layer.default_style] # Delete the Layer using cascading_delete() cascading_delete(gs_cat, shp_layer.typename) # Verify that the styles were deleted for style in styles: s = gs_cat.get_style(style.name) assert s == None # Verify that the resource was deleted self.assertRaises( FailedRequestError, lambda: gs_cat.get_resource(resource_name, store=store)) # Verify that the store was deleted self.assertRaises(FailedRequestError, lambda: gs_cat.get_store(store_name)) # Clean up by deleting the layer from GeoNode's DB and GeoNetwork shp_layer.delete()
def geoserver_pre_delete(instance, sender, **kwargs): """Removes the layer from GeoServer """ ct = ContentType.objects.get_for_model(instance) OverallRating.objects.filter(content_type = ct, object_id = instance.id).delete() cascading_delete(Layer.objects.gs_catalog, instance.typename)
-90 <= miny <= 90 and -90 <= maxy <= 90: logger.info( 'GeoServer failed to detect the projection for layer ' '[%s]. Guessing EPSG:4326', name) # If GeoServer couldn't figure out the projection, we just # assume it's lat/lon to avoid a bad GeoServer configuration gs_resource.latlon_bbox = gs_resource.native_bbox gs_resource.projection = "EPSG:4326" cat.save(gs_resource) else: msg = ('GeoServer failed to detect the projection for layer ' '[%s]. It doesn\'t look like EPSG:4326, so backing out ' 'the layer.') logger.info(msg, name) cascading_delete(cat, name) raise GeoNodeException(msg % name) # Step 7. Create the style and assign it to the created resource # FIXME: Put this in gsconfig.py logger.info('>>> Step 7. Creating style for [%s]' % name) publishing = cat.get_layer(name) if 'sld' in files: f = open(files['sld'], 'r') sld = f.read() f.close() else: sld = get_sld_for(publishing) if sld is not None:
if -180 <= minx <= 180 and -180 <= maxx <= 180 and \ -90 <= miny <= 90 and -90 <= maxy <= 90: logger.info('GeoServer failed to detect the projection for layer ' '[%s]. Guessing EPSG:4326', name) # If GeoServer couldn't figure out the projection, we just # assume it's lat/lon to avoid a bad GeoServer configuration gs_resource.latlon_bbox = gs_resource.native_bbox gs_resource.projection = "EPSG:4326" cat.save(gs_resource) else: msg = ('GeoServer failed to detect the projection for layer ' '[%s]. It doesn\'t look like EPSG:4326, so backing out ' 'the layer.') logger.info(msg, name) cascading_delete(cat, name) raise GeoNodeException(msg % name) # Step 7. Create the style and assign it to the created resource # FIXME: Put this in gsconfig.py logger.info('>>> Step 7. Creating style for [%s]' % name) publishing = cat.get_layer(name) if 'sld' in files: f = open(files['sld'], 'r') sld = f.read() f.close() else: sld = get_sld_for(publishing) if sld is not None: