def create_wm_thumbnail(instance, overwrite=False): """ WorldMap doesn't use thumbnails from GeoServer, but just the ones from html. """ # we use the standard way just for layers, not for maps if isinstance(instance, Layer): # layer created by createlayer application don't need a thumbnail if not instance.data_quality_statement == DATA_QUALITY_MESSAGE: create_gs_thumbnail_geonode(instance) else: return None
def create_gs_thumbnail_mapstory_tx_aware(instance, overwrite): # if this is a map (i.e. multiple layers), handoff to original implementation if instance.class_name == 'Map': return create_gs_thumbnail_geonode(instance, overwrite) # because layer hasn't actually been committed yet, we don't create the thumbnail until the transaction commits # if the task were to run now, it wouldnt be able to retreive layer from the database connection.on_commit(lambda: run_task(instance.pk, overwrite))
def create_gs_thumbnail_mapstory_tx_aware(instance, overwrite): if instance.class_name == "Map": return create_gs_thumbnail_geonode(instance, overwrite) # because layer hasn't actually been committed yet, we don't create the thumbnail until the transaction commits # if the task were to run now, it wouldnt be able to retrieve layer from the database connection.on_commit(lambda: run_task(instance.pk, overwrite))
def test_ogc_server_defaults(self): """ Tests that OGC_SERVER_SETTINGS are built if they do not exist in the settings. """ OGC_SERVER = {'default': dict()} defaults = self.OGC_DEFAULT_SETTINGS.get('default') ogc_settings = OGC_Servers_Handler(OGC_SERVER)['default'] self.assertEqual(ogc_settings.server, defaults) self.assertEqual(ogc_settings.rest, defaults['LOCATION'] + 'rest') self.assertEqual(ogc_settings.ows, defaults['LOCATION'] + 'ows') # Make sure we get None vs a KeyError when the key does not exist self.assertIsNone(ogc_settings.SFDSDFDSF) # Testing OWS endpoints from django.urls import reverse from ..ows import _wcs_get_capabilities, _wfs_get_capabilities, _wms_get_capabilities wcs = _wcs_get_capabilities() logger.debug(wcs) self.assertIsNotNone(wcs) try: wcs_url = urljoin(settings.SITEURL, reverse('ows_endpoint')) except BaseException: wcs_url = urljoin(ogc_settings.PUBLIC_LOCATION, 'ows') self.assertTrue(wcs.startswith(wcs_url)) self.assertIn("service=WCS", wcs) self.assertIn("request=GetCapabilities", wcs) self.assertIn("version=2.0.1", wcs) wfs = _wfs_get_capabilities() logger.debug(wfs) self.assertIsNotNone(wfs) try: wfs_url = urljoin(settings.SITEURL, reverse('ows_endpoint')) except BaseException: wfs_url = urljoin(ogc_settings.PUBLIC_LOCATION, 'ows') self.assertTrue(wfs.startswith(wfs_url)) self.assertIn("service=WFS", wfs) self.assertIn("request=GetCapabilities", wfs) self.assertIn("version=1.1.0", wfs) wms = _wms_get_capabilities() logger.debug(wms) self.assertIsNotNone(wms) try: wms_url = urljoin(settings.SITEURL, reverse('ows_endpoint')) except BaseException: wms_url = urljoin(ogc_settings.PUBLIC_LOCATION, 'ows') self.assertTrue(wms.startswith(wms_url)) self.assertIn("service=WMS", wms) self.assertIn("request=GetCapabilities", wms) self.assertIn("version=1.3.0", wms) # Test OWS Download Links from geonode.geoserver.ows import wcs_links, wfs_links, wms_links instance = Layer.objects.all()[0] bbox = instance.bbox srid = instance.srid height = 512 width = 512 # Default Style (expect exception since we are offline) style = None with self.assertRaises(GeoNodeException): style = get_sld_for(gs_catalog, instance) self.assertIsNone(style) style = gs_catalog.get_style("line") self.assertIsNotNone(style) instance.default_style, _ = Style.objects.get_or_create( name=style.name, defaults=dict( sld_title=style.sld_title, sld_body=style.sld_body ) ) self.assertIsNotNone(instance.default_style) self.assertIsNotNone(instance.default_style.name) # WMS Links wms_links = wms_links(ogc_settings.public_url + 'wms?', instance.alternate, bbox, srid, height, width) self.assertIsNotNone(wms_links) self.assertEquals(len(wms_links), 3) wms_url = urljoin(ogc_settings.PUBLIC_LOCATION, 'wms') identifier = urlencode({'layers': instance.alternate}) for _link in wms_links: logger.debug('%s --> %s' % (wms_url, _link[3])) self.assertTrue(wms_url in _link[3]) logger.debug('%s --> %s' % (identifier, _link[3])) self.assertTrue(identifier in _link[3]) # WFS Links wfs_links = wfs_links(ogc_settings.public_url + 'wfs?', instance.alternate, bbox, srid) self.assertIsNotNone(wfs_links) self.assertEquals(len(wfs_links), 6) wfs_url = urljoin(ogc_settings.PUBLIC_LOCATION, 'wfs') identifier = urlencode({'typename': instance.alternate}) for _link in wfs_links: logger.debug('%s --> %s' % (wfs_url, _link[3])) self.assertTrue(wfs_url in _link[3]) logger.debug('%s --> %s' % (identifier, _link[3])) self.assertTrue(identifier in _link[3]) # WCS Links wcs_links = wcs_links(ogc_settings.public_url + 'wcs?', instance.alternate, bbox, srid) self.assertIsNotNone(wcs_links) self.assertEquals(len(wcs_links), 2) wcs_url = urljoin(ogc_settings.PUBLIC_LOCATION, 'wcs') identifier = urlencode({'coverageid': instance.alternate}) for _link in wcs_links: logger.debug('%s --> %s' % (wcs_url, _link[3])) self.assertTrue(wcs_url in _link[3]) logger.debug('%s --> %s' % (identifier, _link[3])) self.assertTrue(identifier in _link[3]) # Thumbnails Generation Default create_gs_thumbnail(instance, overwrite=True) self.assertIsNotNone(instance.get_thumbnail_url()) # Thumbnails Generation Through "remote url" create_gs_thumbnail_geonode(instance, overwrite=True, check_bbox=True) # Thumbnails Generation Through "image" request_body = { 'width': width, 'height': height, 'layers': instance.alternate } if hasattr(instance, 'default_style'): if instance.default_style: request_body['styles'] = instance.default_style.name self.assertIsNotNone(request_body['styles']) try: image = _prepare_thumbnail_body_from_opts(request_body) except BaseException as e: logger.exception(e) image = None # We are offline here, the layer does not exists in GeoServer # - we expect the image is None self.assertIsNone(image)