示例#1
0
    def test_map_thumbnail(self):
        """Test the map save method generates a thumbnail link
        """
        # 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,
        )
        try:
            self.client.login(username='******', password='******')

            saved_layer.set_default_permissions()
            map_obj = Map(owner=norman, zoom=0,
                          center_x=0, center_y=0)
            map_obj.create_from_layer_list(norman, [saved_layer], 'title', '')

            thumbnail_url = map_obj.get_thumbnail_url()

            self.assertNotEqual(thumbnail_url, staticfiles.static(settings.MISSING_THUMBNAIL))
        finally:
            # Cleanup
            saved_layer.delete()
示例#2
0
    def test_map_thumbnail(self):
        """Test the map save method generates a thumbnail link
        """
        # 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,
        )
        try:
            self.client.login(username='******', password='******')

            saved_layer.set_default_permissions()
            map_obj = Map(owner=norman, zoom=0, center_x=0, center_y=0)
            map_obj.create_from_layer_list(norman, [saved_layer], 'title', '')

            thumbnail_url = map_obj.get_thumbnail_url()

            self.assertNotEqual(thumbnail_url,
                                staticfiles.static(settings.MISSING_THUMBNAIL))
        finally:
            # Cleanup
            saved_layer.delete()
示例#3
0
文件: tests.py 项目: jsiochi/geonode
    def test_new_map_config(self):
        """Test that new map config can be properly assigned
        """
        c = Client()
        c.login(username='******', password='******')

        # Test successful new map creation
        m = Map()
        admin_user = User.objects.get(username='******')
        layer_name = Layer.objects.all()[0].typename
        m.create_from_layer_list(admin_user, [layer_name], "title", "abstract")
        map_id = m.id

        c = Client()

        url = reverse('new_map_json')

        # Test GET method with COPY
        response = c.get(url,{'copy': map_id})
        self.assertEquals(response.status_code,200)
        map_obj = Map.objects.get(id=map_id)
        config_map = map_obj.viewer_json()
        response_config_dict = json.loads(response.content)
        self.assertEquals(config_map['map']['layers'],response_config_dict['map']['layers'])

        # Test GET method no COPY and no layer in params
        response = c.get(url)
        self.assertEquals(response.status_code,200)
        config_default = default_map_config()[0]
        response_config_dict = json.loads(response.content)
        self.assertEquals(config_default['about']['abstract'],response_config_dict['about']['abstract'])
        self.assertEquals(config_default['about']['title'],response_config_dict['about']['title'])

        # Test GET method no COPY but with layer in params
        response = c.get(url,{'layer':layer_name})
        self.assertEquals(response.status_code,200)
        response_dict = json.loads(response.content)
        self.assertEquals(response_dict['fromLayer'],True)

        # Test POST method without authentication
        response = c.post(url,{'layer':layer_name})
        self.assertEquals(response.status_code,401)

        # Test POST method with authentication and a layer in params
        c.login(username='******', password='******')

        response = c.post(url,{'layer':layer_name})
        # Should not accept the request
        self.assertEquals(response.status_code,400)

        # Test POST method with map data in json format
        response = c.post(url, data=self.viewer_config,content_type="text/json")
        self.assertEquals(response.status_code,200)
        map_id = int(json.loads(response.content)['id'])

        # Test methods other than GET or POST and no layer in params
        response = c.put(url)
        self.assertEquals(response.status_code,405)
示例#4
0
    def test_map_thumbnail(self):
        """Test the map save method generates a thumbnail link
        """
        client = Client()
        client.login(username='******', password='******')

        #TODO: Would be nice to ensure the name is available before
        #running the test...
        norman = User.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,
        )

        map_obj = Map(owner=norman, zoom=0,
                      center_x=0, center_y=0)
        map_obj.create_from_layer_list(norman, [saved_layer], 'title','')

        thumbnail_url = map_obj.get_thumbnail_url()

        assert thumbnail_url != staticfiles.static(settings.MISSING_THUMBNAIL)
示例#5
0
    def test_map_thumbnail(self):
        """Test the map save method generates a thumbnail link
        """
        client = Client()
        client.login(username='******', password='******')

        #TODO: Would be nice to ensure the name is available before
        #running the test...
        norman = User.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,
        )

        map_obj = Map(owner=norman, zoom=0, center_x=0, center_y=0)
        map_obj.create_from_layer_list(norman, [saved_layer], 'title', '')

        thumbnail_url = map_obj.get_thumbnail_url()

        assert thumbnail_url != staticfiles.static(settings.MISSING_THUMBNAIL)
示例#6
0
文件: tests.py 项目: plisca/geonode
    def test_new_map_config(self):
        """Test that new map config can be properly assigned
        """
        self.client.login(username='******', password='******')

        # Test successful new map creation
        m = Map()
        admin_user = get_user_model().objects.get(username='******')
        layer_name = Layer.objects.all().first().alternate
        m.create_from_layer_list(admin_user, [layer_name], "title", "abstract")
        map_id = m.id

        url = reverse('new_map_json')

        # Test GET method with COPY
        response = self.client.get(url, {'copy': map_id})
        self.assertEqual(response.status_code, 200)
        map_obj = Map.objects.get(id=map_id)
        config_map = map_obj.viewer_json(None)
        content = response.content
        if isinstance(content, bytes):
            content = content.decode('UTF-8')
        response_config_dict = json.loads(content)
        self.assertEqual(config_map['map']['layers'],
                         response_config_dict['map']['layers'])

        # Test GET method no COPY and no layer in params
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        config_default = default_map_config(None)[0]
        content = response.content
        if isinstance(content, bytes):
            content = content.decode('UTF-8')
        response_config_dict = json.loads(content)
        self.assertEqual(config_default['about']['abstract'],
                         response_config_dict['about']['abstract'])
        self.assertEqual(config_default['about']['title'],
                         response_config_dict['about']['title'])

        # Test GET method no COPY but with layer in params
        response = self.client.get(url, {'layer': layer_name})
        self.assertEqual(response.status_code, 200)
        content = response.content
        if isinstance(content, bytes):
            content = content.decode('UTF-8')
        response_dict = json.loads(content)
        self.assertEqual(response_dict['fromLayer'], True)

        # Test POST method without authentication
        self.client.logout()
        response = self.client.post(url, {'layer': layer_name})
        self.assertEqual(response.status_code, 401)

        # Test POST method with authentication and a layer in params
        self.client.login(username='******', password='******')

        try:
            response = self.client.post(url, {'layer': layer_name})
            # Should not accept the request
            self.assertEqual(response.status_code, 400)

            # Test POST method with map data in json format
            response = self.client.post(url,
                                        data=self.viewer_config,
                                        content_type="text/json")
            self.assertEqual(response.status_code, 200)
            content = response.content
            if isinstance(content, bytes):
                content = content.decode('UTF-8')
            map_id = int(json.loads(content)['id'])
            # Check new map saved
            map_obj = Map.objects.get(id=map_id)
            # Check
            # BBox format: [xmin, xmax, ymin, ymax
            bbox_str = [
                '-90.193207913954200', '-79.206792062465500',
                '9.059219904470890', '16.540780092025600', 'EPSG:4326'
            ]

            self.assertEqual(bbox_str, [str(c) for c in map_obj.bbox])
            bbox_long_str = '-90.193207913954200,9.059219904470890,' \
                            '-79.206792062465500,16.540780092025600'
            self.assertEqual(bbox_long_str, map_obj.bbox_string)

            # Test methods other than GET or POST and no layer in params
            response = self.client.put(url)
            self.assertEqual(response.status_code, 405)
        except Exception:
            pass
示例#7
0
    def testPrintProxy(self):
        """ Test the PrintProxyMiddleware if activated.
            It should respect the permissions on private layers.
        """

        if 'geonode.middleware.PrintProxyMiddleware' in settings.MIDDLEWARE_CLASSES:
            # STEP 1: Import a layer
            from geonode.maps.models import Map

            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,
            )
            # Set the layer private
            saved_layer.set_permissions(
                {'users': {
                    'AnonymousUser': ['view_resourcebase']
                }})

            url = reverse('layer_metadata',
                          args=[saved_layer.service_typename])

            # check is accessible while logged in
            resp = self.client.get(url)
            self.assertEquals(resp.status_code, 200)

            # check is inaccessible when not logged in
            self.client.logout()
            resp = self.client.get(url)
            self.assertEquals(resp.status_code, 302)

            # STEP 2: Create a Map with that layer

            map_obj = Map(owner=norman, zoom=0, center_x=0, center_y=0)
            map_obj.create_from_layer_list(norman, [saved_layer], 'title', '')

            # STEP 3: Print the map

            print_url = settings.OGC_SERVER['default'][
                'LOCATION'] + 'pdf/create.json'

            post_payload = {
                'dpi':
                75,
                'layers': [{
                    'baseURL':
                    settings.OGC_SERVER['default']['LOCATION'] +
                    'wms?SERVICE=WMS&',
                    'format':
                    "image/png",
                    'customParams': {
                        'TILED': True,
                        'TRANSPARENT': True
                    },
                    'layers': [saved_layer.service_typename],
                    'opacity':
                    1,
                    'singleTile':
                    False,
                    'type':
                    'WMS'
                }],
                'layout':
                'A4 portrait',
                'mapTitle':
                'test',
                'outputFilename':
                'print',
                'srs':
                getattr(settings, 'DEFAULT_MAP_CRS', 'EPSG:900913'),
                'units':
                'm'
            }

            self.client.post(print_url, post_payload)

            # Test the layer is still inaccessible as non authenticated
            resp = self.client.get(url)
            self.assertEquals(resp.status_code, 302)

        else:
            pass
示例#8
0
    def test_new_map_config(self):
        """Test that new map config can be properly assigned
        """
        self.client.login(username='******', password='******')

        # Test successful new map creation
        m = Map()
        admin_user = get_user_model().objects.get(username='******')
        layer_name = Layer.objects.all()[0].alternate
        m.create_from_layer_list(admin_user, [layer_name], "title", "abstract")
        map_id = m.id

        url = reverse('new_map_json')

        # Test GET method with COPY
        response = self.client.get(url, {'copy': map_id})
        self.assertEquals(response.status_code, 200)
        map_obj = Map.objects.get(id=map_id)
        config_map = map_obj.viewer_json(None, None)
        response_config_dict = json.loads(response.content)
        self.assertEquals(
            config_map['map']['layers'],
            response_config_dict['map']['layers'])

        # Test GET method no COPY and no layer in params
        response = self.client.get(url)
        self.assertEquals(response.status_code, 200)
        config_default = default_map_config(None)[0]
        response_config_dict = json.loads(response.content)
        self.assertEquals(
            config_default['about']['abstract'],
            response_config_dict['about']['abstract'])
        self.assertEquals(
            config_default['about']['title'],
            response_config_dict['about']['title'])

        # Test GET method no COPY but with layer in params
        response = self.client.get(url, {'layer': layer_name})
        self.assertEquals(response.status_code, 200)
        response_dict = json.loads(response.content)
        self.assertEquals(response_dict['fromLayer'], True)

        # Test POST method without authentication
        self.client.logout()
        response = self.client.post(url, {'layer': layer_name})
        self.assertEquals(response.status_code, 401)

        # Test POST method with authentication and a layer in params
        self.client.login(username='******', password='******')

        response = self.client.post(url, {'layer': layer_name})
        # Should not accept the request
        self.assertEquals(response.status_code, 400)

        # Test POST method with map data in json format
        response = self.client.post(
            url,
            data=self.viewer_config,
            content_type="text/json")
        self.assertEquals(response.status_code, 200)
        map_id = int(json.loads(response.content)['id'])
        # Check new map saved
        map_obj = Map.objects.get(id=map_id)
        # Check
        # BBox format: [xmin, xmax, ymin, ymax
        bbox_str = [
            '-90.1932079140', '-79.2067920625',
            '9.0592199045', '16.5407800920', 'EPSG:4326']

        self.assertEqual(
            bbox_str,
            [str(c) for c in map_obj.bbox])
        bbox_long_str = '-90.1932079140,9.0592199045,' \
                        '-79.2067920625,16.5407800920'
        self.assertEqual(bbox_long_str, map_obj.bbox_string)

        # Test methods other than GET or POST and no layer in params
        response = self.client.put(url)
        self.assertEquals(response.status_code, 405)
    def testPrintProxy(self):
        """ Test the PrintProxyMiddleware if activated.
            It should respect the permissions on private layers.
        """

        if 'geonode.middleware.PrintProxyMiddleware' in settings.MIDDLEWARE_CLASSES:
            # STEP 1: Import a layer
            from geonode.maps.models import Map

            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,
            )
            # Set the layer private
            saved_layer.set_permissions(
                {'users': {'AnonymousUser': ['view_resourcebase']}})

            url = reverse(
                'layer_metadata',
                args=[
                    saved_layer.service_typename])

            # check is accessible while logged in
            resp = self.client.get(url)
            self.assertEquals(resp.status_code, 200)

            # check is inaccessible when not logged in
            self.client.logout()
            resp = self.client.get(url)
            self.assertEquals(resp.status_code, 302)

            # STEP 2: Create a Map with that layer

            map_obj = Map(owner=norman, zoom=0,
                          center_x=0, center_y=0)
            map_obj.create_from_layer_list(norman, [saved_layer], 'title', '')

            # STEP 3: Print the map

            print_url = settings.OGC_SERVER['default'][
                'LOCATION'] + 'pdf/create.json'

            post_payload = {
                'dpi': 75,
                'layers': [
                    {
                        'baseURL': settings.OGC_SERVER['default']['LOCATION'] +
                        'wms?SERVICE=WMS&',
                        'format': "image/png",
                        'customParams': {
                            'TILED': True,
                            'TRANSPARENT': True},
                        'layers': [
                            saved_layer.service_typename],
                        'opacity': 1,
                        'singleTile': False,
                        'type': 'WMS'}],
                'layout': 'A4 portrait',
                'mapTitle': 'test',
                'outputFilename': 'print',
                'srs': 'EPSG:900913',
                'units': 'm'}

            self.client.post(print_url, post_payload)

            # Test the layer is still inaccessible as non authenticated
            resp = self.client.get(url)
            self.assertEquals(resp.status_code, 302)

        else:
            pass
示例#10
0
    def testPrintProxy(self):
        """ Test the PrintProxyMiddleware if activated.
            It should respect the permissions on private layers.
        """

        if "geonode.middleware.PrintProxyMiddleware" in settings.MIDDLEWARE_CLASSES:
            # STEP 1: Import a layer
            from geonode.maps.models import Map

            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,
            )
            # Set the layer private
            saved_layer.set_permissions({"users": {"AnonymousUser": ["view_resourcebase"]}})

            url = reverse("layer_metadata", args=[saved_layer.service_typename])

            # check is accessible while logged in
            resp = self.client.get(url)
            self.assertEquals(resp.status_code, 200)

            # check is inaccessible when not logged in
            self.client.logout()
            resp = self.client.get(url)
            self.assertEquals(resp.status_code, 302)

            # STEP 2: Create a Map with that layer

            map_obj = Map(owner=norman, zoom=0, center_x=0, center_y=0)
            map_obj.create_from_layer_list(norman, [saved_layer], "title", "")

            # STEP 3: Print the map

            print_url = settings.OGC_SERVER["default"]["LOCATION"] + "pdf/create.json"

            post_payload = {
                "dpi": 75,
                "layers": [
                    {
                        "baseURL": settings.OGC_SERVER["default"]["LOCATION"] + "wms?SERVICE=WMS&",
                        "format": "image/png",
                        "customParams": {"TILED": True, "TRANSPARENT": True},
                        "layers": [saved_layer.service_typename],
                        "opacity": 1,
                        "singleTile": False,
                        "type": "WMS",
                    }
                ],
                "layout": "A4 portrait",
                "mapTitle": "test",
                "outputFilename": "print",
                "srs": getattr(settings, "DEFAULT_MAP_CRS", "EPSG:900913"),
                "units": "m",
            }

            self.client.post(print_url, post_payload)

            # Test the layer is still inaccessible as non authenticated
            resp = self.client.get(url)
            self.assertEquals(resp.status_code, 302)

        else:
            pass