Ejemplo n.º 1
0
 def on_geoserver_messages(self, body, message):
     logger.info("on_geoserver_messages: RECEIVED MSG - body: %r" % (body,))
     layer_id = body.get("id")
     geoserver_post_save2(layer_id)
     # Not sure if we need to send ack on this fanout version.
     message.ack()
     logger.info("on_geoserver_messages: finished")
     return
Ejemplo n.º 2
0
 def on_geoserver_messages(self, body, message):
     logger.info("on_geoserver_messages: RECEIVED MSG - body: %r" %
                 (body, ))
     layer_id = body.get("id")
     geoserver_post_save2(layer_id)
     # Not sure if we need to send ack on this fanout version.
     message.ack()
     logger.info("on_geoserver_messages: finished")
     return
Ejemplo n.º 3
0
    def test_raster_upload(self):
        """Test that the wcs links are correctly created for a raster"""
        filename = os.path.join(gisdata.GOOD_DATA, 'raster/test_grid.tif')
        uploaded = file_upload(filename)

        geoserver_post_save2(uploaded.id)

        wcs_link = False
        for link in uploaded.link_set.all():
            if link.mime == 'image/tiff':
                wcs_link = True
        self.assertTrue(wcs_link)
Ejemplo n.º 4
0
    def test_raster_upload(self):
        """Test that the wcs links are correctly created for a raster"""
        filename = os.path.join(gisdata.GOOD_DATA, 'raster/test_grid.tif')
        uploaded = file_upload(filename)

        geoserver_post_save2(uploaded.id)

        wcs_link = False
        for link in uploaded.link_set.all():
            if link.mime == 'image/tiff':
                wcs_link = True
        self.assertTrue(wcs_link)
Ejemplo n.º 5
0
    def test_layer_delete_from_geoserver(self):
        """Verify that layer is correctly deleted from GeoServer
        """
        # Layer.delete() calls the pre_delete hook which uses cascading_delete()
        # Should we explicitly test that the styles and store are
        # deleted as well as the resource itself?
        # There is already an explicit test for cascading delete

        gs_cat = gs_catalog

        # Test Uploading then Deleting a Shapefile from GeoServer
        shp_file = os.path.join(
            gisdata.VECTOR_DATA,
            'san_andres_y_providencia_poi.shp')
        shp_layer = file_upload(shp_file, overwrite=True)

        shp_layer = geoserver_post_save2(shp_layer.id)

        ws = gs_cat.get_workspace(shp_layer.workspace)
        shp_store = gs_cat.get_store(shp_layer.store, ws)
        shp_store_name = shp_store.name
        shp_layer.delete()
        # self.assertIsNone(gs_cat.get_resource(shp_layer.name, store=shp_store))
        self.assertRaises(
            FailedRequestError,
            lambda: gs_cat.get_store(shp_store_name))

        # Test Uploading then Deleting a TIFF file from GeoServer
        tif_file = os.path.join(gisdata.RASTER_DATA, 'test_grid.tif')
        tif_layer = file_upload(tif_file)

        tif_layer = geoserver_post_save2(tif_layer.id)

        ws = gs_cat.get_workspace(tif_layer.workspace)
        tif_store = gs_cat.get_store(tif_layer.store, ws)
        tif_layer.delete()
        self.assertRaises(
            FailedRequestError,
            lambda: gs_cat.get_resource(
                shp_layer.name,
                store=tif_store))
Ejemplo n.º 6
0
    def test_layer_delete_from_geoserver(self):
        """Verify that layer is correctly deleted from GeoServer
        """
        # Layer.delete() calls the pre_delete hook which uses cascading_delete()
        # Should we explicitly test that the styles and store are
        # deleted as well as the resource itself?
        # There is already an explicit test for cascading delete

        gs_cat = gs_catalog

        # Test Uploading then Deleting a Shapefile from GeoServer
        shp_file = os.path.join(gisdata.VECTOR_DATA,
                                'san_andres_y_providencia_poi.shp')
        shp_layer = file_upload(shp_file, overwrite=True)

        shp_layer = geoserver_post_save2(shp_layer.id)

        ws = gs_cat.get_workspace(shp_layer.workspace)
        shp_store = gs_cat.get_store(shp_layer.store, ws)
        shp_store_name = shp_store.name
        shp_layer.delete()
        # self.assertIsNone(gs_cat.get_resource(shp_layer.name, store=shp_store))
        self.assertRaises(FailedRequestError,
                          lambda: gs_cat.get_store(shp_store_name))

        # Test Uploading then Deleting a TIFF file from GeoServer
        tif_file = os.path.join(gisdata.RASTER_DATA, 'test_grid.tif')
        tif_layer = file_upload(tif_file)

        tif_layer = geoserver_post_save2(tif_layer.id)

        ws = gs_cat.get_workspace(tif_layer.workspace)
        tif_store = gs_cat.get_store(tif_layer.store, ws)
        tif_layer.delete()
        self.assertRaises(
            FailedRequestError,
            lambda: gs_cat.get_resource(shp_layer.name, store=tif_store))
Ejemplo n.º 7
0
    def test_cascading_delete(self):
        """Verify that the helpers.cascading_delete() method is working properly
        """
        gs_cat = 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)

        shp_layer = geoserver_post_save2(shp_layer.id)

        time.sleep(20)

        # Save the names of the Resource/Store/Styles
        self.assertIsNotNone(shp_layer.name)
        resource_name = shp_layer.name
        self.assertIsNotNone(shp_layer.workspace)
        ws = gs_cat.get_workspace(shp_layer.workspace)
        self.assertIsNotNone(shp_layer.store)
        store = gs_cat.get_store(shp_layer.store, ws)
        store_name = store.name
        self.assertIsNotNone(resource_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 is 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()
Ejemplo n.º 8
0
    def test_delete_layer(self):
        """Verify that the 'delete_layer' pre_delete hook is functioning
        """

        gs_cat = gs_catalog

        # Upload a Shapefile Layer
        shp_file = os.path.join(
            gisdata.VECTOR_DATA,
            'san_andres_y_providencia_poi.shp')
        shp_layer = file_upload(shp_file)

        shp_layer = geoserver_post_save2(shp_layer.id)

        time.sleep(20)

        shp_layer_id = shp_layer.pk
        ws = gs_cat.get_workspace(shp_layer.workspace)
        shp_store = gs_cat.get_store(shp_layer.store, ws)
        shp_store_name = shp_store.name

        uuid = shp_layer.uuid

        # Delete it with the Layer.delete() method
        shp_layer.delete()

        geoserver_delete(shp_layer.typename)

        # Verify that it no longer exists in GeoServer
        # self.assertIsNone(gs_cat.get_resource(name, store=shp_store))
        # self.assertIsNone(gs_cat.get_layer(shp_layer.name))
        self.assertRaises(
            FailedRequestError,
            lambda: gs_cat.get_store(shp_store_name))

        # Check that it was also deleted from GeoNodes DB
        self.assertRaises(ObjectDoesNotExist,
                          lambda: Layer.objects.get(pk=shp_layer_id))

    # geonode.geoserver.helpers
        # If catalogue is installed, then check that it is deleted from there
        # too.
        if 'geonode.catalogue' in settings.INSTALLED_APPS:
            from geonode.catalogue import get_catalogue
            catalogue = get_catalogue()

            # Verify that it no longer exists in GeoNetwork
            shp_layer_gn_info = catalogue.get_record(uuid)
            assert shp_layer_gn_info is None
Ejemplo n.º 9
0
    def test_delete_layer(self):
        """Verify that the 'delete_layer' pre_delete hook is functioning
        """

        gs_cat = gs_catalog

        # Upload a Shapefile Layer
        shp_file = os.path.join(gisdata.VECTOR_DATA,
                                'san_andres_y_providencia_poi.shp')
        shp_layer = file_upload(shp_file)

        shp_layer = geoserver_post_save2(shp_layer.id)

        time.sleep(20)

        shp_layer_id = shp_layer.pk
        ws = gs_cat.get_workspace(shp_layer.workspace)
        shp_store = gs_cat.get_store(shp_layer.store, ws)
        shp_store_name = shp_store.name

        uuid = shp_layer.uuid

        # Delete it with the Layer.delete() method
        shp_layer.delete()

        geoserver_delete(shp_layer.typename)

        # Verify that it no longer exists in GeoServer
        # self.assertIsNone(gs_cat.get_resource(name, store=shp_store))
        # self.assertIsNone(gs_cat.get_layer(shp_layer.name))
        self.assertRaises(FailedRequestError,
                          lambda: gs_cat.get_store(shp_store_name))

        # Check that it was also deleted from GeoNodes DB
        self.assertRaises(ObjectDoesNotExist,
                          lambda: Layer.objects.get(pk=shp_layer_id))

        # geonode.geoserver.helpers
        # If catalogue is installed, then check that it is deleted from there
        # too.
        if 'geonode.catalogue' in settings.INSTALLED_APPS:
            from geonode.catalogue import get_catalogue
            catalogue = get_catalogue()

            # Verify that it no longer exists in GeoNetwork
            shp_layer_gn_info = catalogue.get_record(uuid)
            assert shp_layer_gn_info is None
Ejemplo n.º 10
0
    def test_cascading_delete(self):
        """Verify that the helpers.cascading_delete() method is working properly
        """
        gs_cat = 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)

        shp_layer = geoserver_post_save2(shp_layer.id)

        time.sleep(20)

        # Save the names of the Resource/Store/Styles
        self.assertIsNotNone(shp_layer.name)
        resource_name = shp_layer.name
        self.assertIsNotNone(shp_layer.workspace)
        ws = gs_cat.get_workspace(shp_layer.workspace)
        self.assertIsNotNone(shp_layer.store)
        store = gs_cat.get_store(shp_layer.store, ws)
        store_name = store.name
        self.assertIsNotNone(resource_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 is 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()
Ejemplo n.º 11
0
    def test_layer_thumbnail(self):
        """Test the layer save method generates a thumbnail link
        """

        self.client.login(username='******', password='******')

        # TODO: Would be nice to ensure the name is available before
        # running the test...
        norman = get_user_model().objects.get(username="******")
        saved_layer = file_upload(
            os.path.join(gisdata.VECTOR_DATA,
                         "san_andres_y_providencia_poi.shp"),
            name="san_andres_y_providencia_poi_by_norman",
            user=norman,
            overwrite=True,
        )

        saved_layer = geoserver_post_save2(saved_layer.id)

        thumbnail_url = saved_layer.get_thumbnail_url()

        assert thumbnail_url != staticfiles.static(settings.MISSING_THUMBNAIL)
Ejemplo n.º 12
0
    def test_layer_thumbnail(self):
        """Test the layer save method generates a thumbnail link
        """

        self.client.login(username='******', password='******')

        # TODO: Would be nice to ensure the name is available before
        # running the test...
        norman = get_user_model().objects.get(username="******")
        saved_layer = file_upload(
            os.path.join(
                gisdata.VECTOR_DATA,
                "san_andres_y_providencia_poi.shp"),
            name="san_andres_y_providencia_poi_by_norman",
            user=norman,
            overwrite=True,
        )

        saved_layer = geoserver_post_save2(saved_layer.id)

        thumbnail_url = saved_layer.get_thumbnail_url()

        assert thumbnail_url != staticfiles.static(settings.MISSING_THUMBNAIL)
Ejemplo n.º 13
0
    def test_unpublished(self):
        """Test permissions on an unpublished layer
        """

        thefile = os.path.join(
            gisdata.VECTOR_DATA,
            'san_andres_y_providencia_poi.shp')
        layer = file_upload(thefile, overwrite=True)

        layer = geoserver_post_save2(layer.id)

        layer.set_default_permissions()
        check_layer(layer)

        # we need some time to have the service up and running
        time.sleep(20)

        # request getCapabilities: layer must be there as it is published and
        # advertised: we need to check if in response there is
        # <Name>geonode:san_andres_y_providencia_water</Name>
        url = 'http://localhost:8080/geoserver/ows?' \
            'service=wms&version=1.3.0&request=GetCapabilities'
        str_to_check = '<Name>geonode:san_andres_y_providencia_poi</Name>'
        request = urllib2.Request(url)
        response = urllib2.urlopen(request)
        self.assertTrue(any(str_to_check in s for s in response.readlines()))

        # by default the uploaded layer is
        self.assertTrue(layer.is_published, True)

        # Clean up and completely delete the layer
        layer.delete()

        # with settings disabled
        with self.settings(RESOURCE_PUBLISHING=True):

            thefile = os.path.join(
                gisdata.VECTOR_DATA,
                'san_andres_y_providencia_administrative.shp')
            layer = file_upload(thefile, overwrite=True)

            layer = geoserver_post_save2(layer.id)

            layer.set_default_permissions()
            check_layer(layer)

            # we need some time to have the service up and running
            time.sleep(20)

            str_to_check = '<Name>san_andres_y_providencia_administrative</Name>'

            # by default the uploaded layer must be unpublished
            self.assertEqual(layer.is_published, False)

            # check the layer is not in GetCapabilities
            request = urllib2.Request(url)
            response = urllib2.urlopen(request)
            self.assertFalse(any(str_to_check in s for s in response.readlines()))

            # now test with published layer
            resource = layer.get_self_resource()
            resource.is_published = True
            resource.save()

            layer = geoserver_post_save2(layer.id)

            request = urllib2.Request(url)
            response = urllib2.urlopen(request)
            self.assertTrue(any(str_to_check in s for s in response.readlines()))

            # Clean up and completely delete the layer
            layer.delete()
Ejemplo n.º 14
0
    def test_unpublished(self):
        """Test permissions on an unpublished layer
        """

        thefile = os.path.join(gisdata.VECTOR_DATA,
                               'san_andres_y_providencia_poi.shp')
        layer = file_upload(thefile, overwrite=True)

        layer = geoserver_post_save2(layer.id)

        layer.set_default_permissions()
        check_layer(layer)

        # we need some time to have the service up and running
        time.sleep(20)

        # request getCapabilities: layer must be there as it is published and
        # advertised: we need to check if in response there is
        # <Name>geonode:san_andres_y_providencia_water</Name>
        url = 'http://localhost:8080/geoserver/ows?' \
            'service=wms&version=1.3.0&request=GetCapabilities'
        str_to_check = '<Name>geonode:san_andres_y_providencia_poi</Name>'
        request = urllib2.Request(url)
        response = urllib2.urlopen(request)
        self.assertTrue(any(str_to_check in s for s in response.readlines()))

        # by default the uploaded layer is
        self.assertTrue(layer.is_published, True)

        # Clean up and completely delete the layer
        layer.delete()

        # with settings disabled
        with self.settings(RESOURCE_PUBLISHING=True):

            thefile = os.path.join(
                gisdata.VECTOR_DATA,
                'san_andres_y_providencia_administrative.shp')
            layer = file_upload(thefile, overwrite=True)

            layer = geoserver_post_save2(layer.id)

            layer.set_default_permissions()
            check_layer(layer)

            # we need some time to have the service up and running
            time.sleep(20)

            str_to_check = '<Name>san_andres_y_providencia_administrative</Name>'

            # by default the uploaded layer must be unpublished
            self.assertEqual(layer.is_published, False)

            # check the layer is not in GetCapabilities
            request = urllib2.Request(url)
            response = urllib2.urlopen(request)
            self.assertFalse(
                any(str_to_check in s for s in response.readlines()))

            # now test with published layer
            resource = layer.get_self_resource()
            resource.is_published = True
            resource.save()

            layer = geoserver_post_save2(layer.id)

            request = urllib2.Request(url)
            response = urllib2.urlopen(request)
            self.assertTrue(
                any(str_to_check in s for s in response.readlines()))

            # Clean up and completely delete the layer
            layer.delete()