Beispiel #1
0
    def test_themev2_noauth_edit_permission(self):
        from c2cgeoportal_geoportal.views.entry import Entry

        request = self._create_request_obj()
        request.params = {"interface": "main", "version": "2"}
        entry = Entry(request)
        themes = entry.themes()
        self.assertEqual(set(themes["errors"]), set())
        self.assertEqual([t["name"] for t in themes["themes"]], [])
Beispiel #2
0
    def test_error(self):
        from c2cgeoportal_geoportal.views.entry import Entry

        entry = Entry(self._create_request_obj(params={
            "version": "2",
        }))
        themes = entry.themes()
        self.assertEqual(
            set(themes["errors"]),
            set(["The theme has an unsupported name '__test/theme'."]))
    def test_error(self):
        from c2cgeoportal_geoportal.views.entry import Entry

        entry = Entry(self._create_request_obj(params={
            "version": "2",
        }))
        themes = entry.themes()
        self.assertEqual(set(themes["errors"]), set([
            "The theme has an unsupported name '__test/theme'."
        ]))
Beispiel #4
0
    def test_themev2_auth_no_edit_permission(self):
        from c2cgeoportal_geoportal.views.entry import Entry

        request = self._create_request_obj(username="******")
        request.params = {
            "interface": "main",
        }
        entry = Entry(request)
        themes = entry.themes()
        self.assertEqual(set(themes["errors"]), set())
        self.assertEqual([t["name"] for t in themes["themes"]], ["__test_theme"])
        self.assertEqual([c["name"] for c in themes["themes"][0]["children"]], ["__test_layer_group"])

        layers = themes["themes"][0]["children"][0]["children"]
        self.assertEqual([l["name"] for l in layers], ["__test_private_layer"])
        self.assertEqual("editable" in layers[0], False)
    def test_metadata(self):
        from c2cgeoportal_geoportal.views.entry import Entry

        types = [
            {"name": "string", "type": "string"},
            {"name": "list", "type": "list"},
            {"name": "boolean", "type": "boolean"},
            {"name": "boolean2", "type": "boolean"},
            {"name": "boolean3", "type": "boolean"},
            {"name": "integer", "type": "integer"},
            {"name": "float", "type": "float"},
            {"name": "json", "type": "json"},
            {"name": "json_wrong", "type": "json"},
            {"name": "date", "type": "date"},
            {"name": "time", "type": "time"},
            {"name": "datetime", "type": "datetime"},
            {"name": "date2", "type": "date"},
            {"name": "time2", "type": "time"},
            {"name": "datetime2", "type": "datetime"},
            {"name": "unknown", "type": "unknown"},
        ]
        types += [{"name": "url{}".format(n), "type": "url"} for n in range(1, 21)]

        request = create_dummy_request(additional_settings={
            "package": "tests",
            "servers": {
                "server": "http://example.com/test"
            },
            "admin_interface": {"available_metadata": types}
        })

        def route_url(url, **kargs):
            return "http://mapserver.org/"
        request.route_url = route_url

        def static_url(url, **kargs):
            return "http://dummy.org/{}".format(url)
        request.static_url = static_url
        request.params = {
            "version": "2",
            "interface": "desktop",
        }
        entry = Entry(request)

        themes = entry.themes()
        self.assertEqual(self._get_filtered_errors(themes), set([
            "The boolean attribute 'boolean3'='hello' is not in [yes, y, on, 1, true, no, n, off, 0, false].",
            "Unable to parse the attribute 'json_wrong'='{\"test\": 123' with the type 'json', error:\n'set' object has no attribute 'append'",
            "The date attribute 'date2'='Sep 25 10:36:28 BRST 2003' should not have any time",
            "The time attribute 'time2'='Sep 25 10:36:28 BRST 2003' should not have any date",
            "Unable to parse the attribute 'datetime2'='Hello' with the type 'datetime', error:\nUnknown string format",
            "The attribute 'url11'='https:///static/icon.png' is not a valid URL.",
            "The attribute 'url12'='static://test' cannot have an empty path.",
            "The attribute 'url13'='static://test/' cannot have an empty path.",
            "The attribute 'url14'='config:///static/icon.png' cannot have an empty netloc.",
            "The server 'unknown_server' is not found in the config",
            "The attribute 'url16'='https://' is not a valid URL.",
            "The attribute 'url17'='https:///' is not a valid URL.",
            "The attribute 'url18'='https:///static' is not a valid URL.",
            "The attribute 'url19'='' is not an URL.",
            "The attribute 'url20'='/' is not an URL.",
            "Unknown type 'unknown'.",
        ]))
        self.assertEqual(
            [self._only_name(t, "metadata") for t in themes["themes"]],
            [{
                "metadata": {},
                "children": [{
                    "metadata": {},
                    "children": [{
                        "metadata": {
                            "string": "string",
                            "list": ["1", "2", "a"],
                            "boolean": True,
                            "boolean2": False,
                            "integer": 1,
                            "float": 5.5,
                            "json": {"test": 123},
                            "date": "2003-09-25",
                            "time": "10:36:28",
                            "datetime": "2003-09-25T10:36:28",
                            "url1": "http://example.com/hi?a=b#c",
                            "url2": "http://dummy.org/tests_geoportal:static/path/icon.png",
                            "url3": "http://dummy.org/tests:static/path/icon.png",
                            "url4": "http://dummy.org/tests:cgxp/path/icon.png",
                            "url5": "http://dummy.org/project:static/path/icon.png",
                            "url6": "http://dummy.org/project:cgxp/path/icon.png",
                            "url7": "http://example.com/test",
                            "url8": "http://example.com/test/index.html",
                            "url9": "/dummy/static/icon.png",
                            "url10": "dummy/static/icon.png",
                        }
                    }]
                }]
            }]
        )
Beispiel #6
0
    def test_themes_edit_columns_extras(self):
        from c2cgeoportal_geoportal.views.entry import Entry
        from c2cgeoportal_commons.models.main import Metadata

        metadatas = [
            Metadata("lastUpdateDateColumn", "last_update_date"),
            Metadata("lastUpdateUserColumn", "last_update_user"),
        ]
        layer_id = self._create_layer(geom_type=False,
                                      exclude_properties=True,
                                      metadatas=metadatas)
        entry = Entry(
            self._get_request(layer_id,
                              username="******",
                              params={"interface": "main"}))

        themes = entry.themes()
        layers = themes["themes"][0]["children"][0]["children"]

        self.assertEqual(
            [layer["edit_columns"] for layer in layers],
            [[
                {
                    "nillable": True,
                    "type": "xsd:integer",
                    "name": "child_id"
                },
                {
                    "nillable": True,
                    "type": "xsd:boolean",
                    "name": "deleted"
                },
                {
                    "nillable": True,
                    "type": "xsd:date",
                    "name": "date"
                },
                {
                    "nillable": True,
                    "type": "xsd:time",
                    "name": "start_time"
                    # }, {
                    #     "nillable": True,
                    #     "type": "xsd:duration",
                    #     "name": "interval"
                },
                {
                    "nillable": True,
                    "type": "xsd:string",
                    "name": "short_name1"
                },
                {
                    "nillable": True,
                    "type": "xsd:string",
                    "name": "short_name2",
                    "maxLength": 50
                },
                {
                    "nillable": True,
                    "type": "xsd:integer",
                    "name": "short_number"
                },
                {
                    "nillable": True,
                    "type": "xsd:double",
                    "name": "double_number"
                },
                {
                    "nillable": True,
                    "type": "xsd:base64Binary",
                    "name": "large_binary"
                },
                {
                    "enumeration": [
                        "one",
                        "two",
                        "three",
                    ],
                    "type": "xsd:string",
                    "name": "value",
                    "nillable": True,
                    "restriction": "enumeration"
                },
                {
                    "fractionDigits": 2,
                    "nillable": True,
                    "type": "xsd:decimal",
                    "name": "numeric",
                    "totalDigits": 5,
                },
                {
                    "name": "numeric2",
                    "type": "xsd:decimal",
                    "nillable": True
                },
                {
                    "srid": 21781,
                    "nillable": True,
                    "type": "gml:GeometryPropertyType",
                    "name": "geom"
                },
                {
                    "restriction": "enumeration",
                    "nillable": True,
                    "type": "xsd:string",
                    "name": "child",
                    "enumeration": ["c1\xe9", "c2\xe9"]
                }
            ]])
Beispiel #7
0
    def test_themes_edit_columns(self):
        from c2cgeoportal_geoportal.views.entry import Entry

        layer_id = self._create_layer(geom_type=True)
        entry = Entry(
            self._get_request(layer_id,
                              username="******",
                              params={
                                  "version": "2",
                                  "interface": "main"
                              }))

        themes = entry.themes()
        layers = themes["themes"][0]["children"][0]["children"]

        self.assertEqual(
            [layer["edit_columns"] for layer in layers],
            [[
                {
                    "nillable": True,
                    "type": "xsd:integer",
                    "name": "child_id"
                },
                {
                    "type": "xsd:string",
                    "name": "name"
                },
                {
                    "nillable": True,
                    "type": "xsd:boolean",
                    "name": "deleted"
                },
                {
                    "nillable": True,
                    "type": "xsd:string",
                    "name": "last_update_user"
                },
                {
                    "nillable": True,
                    "type": "xsd:dateTime",
                    "name": "last_update_date"
                },
                {
                    "nillable": True,
                    "type": "xsd:date",
                    "name": "date"
                },
                {
                    "nillable": True,
                    "type": "xsd:time",
                    "name": "start_time"
                    # }, {
                    #     "nillable": True,
                    #     "type": "xsd:duration",
                    #     "name": "interval"
                },
                {
                    "nillable": True,
                    "type": "xsd:string",
                    "name": "short_name1"
                },
                {
                    "nillable": True,
                    "type": "xsd:string",
                    "name": "short_name2",
                    "maxLength": 50
                },
                {
                    "nillable": True,
                    "type": "xsd:integer",
                    "name": "short_number"
                },
                {
                    "nillable": True,
                    "type": "xsd:double",
                    "name": "double_number"
                },
                {
                    "nillable": True,
                    "type": "xsd:base64Binary",
                    "name": "large_binary"
                },
                {
                    "enumeration": [
                        "one",
                        "two",
                        "three",
                    ],
                    "type": "xsd:string",
                    "name": "value",
                    "nillable": True,
                    "restriction": "enumeration"
                },
                {
                    "fractionDigits": 2,
                    "nillable": True,
                    "type": "xsd:decimal",
                    "name": "numeric",
                    "totalDigits": 5
                },
                {
                    "nillable": True,
                    "type": "xsd:decimal",
                    "name": "numeric2"
                },
                {
                    "srid": 21781,
                    "nillable": True,
                    "type": "gml:PointPropertyType",
                    "name": "geom"
                },
                {
                    "restriction": "enumeration",
                    "nillable": True,
                    "type": "xsd:string",
                    "name": "child",
                    "enumeration": ["c1\xe9", "c2\xe9"]
                }
            ]])
    def test_metadata(self):
        from c2cgeoportal_geoportal.views.entry import Entry

        types = [
            {"name": "string", "type": "string"},
            {"name": "list", "type": "list"},
            {"name": "boolean", "type": "boolean"},
            {"name": "boolean2", "type": "boolean"},
            {"name": "boolean3", "type": "boolean"},
            {"name": "integer", "type": "integer"},
            {"name": "float", "type": "float"},
            {"name": "json", "type": "json"},
            {"name": "json_wrong", "type": "json"},
            {"name": "date", "type": "date"},
            {"name": "time", "type": "time"},
            {"name": "datetime", "type": "datetime"},
            {"name": "date2", "type": "date"},
            {"name": "time2", "type": "time"},
            {"name": "datetime2", "type": "datetime"},
            {"name": "unknown", "type": "unknown"},
        ]
        types += [{"name": "url{}".format(n), "type": "url"} for n in range(1, 21)]

        request = create_dummy_request(additional_settings={
            "package": "tests",
            "servers": {
                "server": "http://example.com/test"
            },
            "admin_interface": {"available_metadata": types}
        })

        def route_url(url, **kwargs):
            del url
            del kwargs
            return "http://mapserver.org/"
        request.route_url = route_url

        def static_url(url, **kwargs):
            del kwargs
            return "http://dummy.org/{}".format(url)
        request.static_url = static_url
        request.params = {
            "interface": "desktop",
        }
        entry = Entry(request)

        themes = entry.themes()
        self.assertEqual(self._get_filtered_errors(themes), set([
            "The boolean attribute 'boolean3'='hello' is not in [yes, y, on, 1, true, no, n, off, 0, false].",
            "Unable to parse the attribute 'json_wrong'='{\"test\": 123' with the type 'json', error:\n'set' object has no attribute 'append'",
            "The date attribute 'date2'='Sep 25 10:36:28 BRST 2003' should not have any time",
            "The time attribute 'time2'='Sep 25 10:36:28 BRST 2003' should not have any date",
            "Unable to parse the attribute 'datetime2'='Hello' with the type 'datetime', error:\n('Unknown string format:', 'Hello')",
            "The attribute 'url11'='https:///static/icon.png' is not a valid URL.",
            "The attribute 'url12'='static://test' cannot have an empty path.",
            "The attribute 'url13'='static://test/' cannot have an empty path.",
            "The attribute 'url14'='config:///static/icon.png' cannot have an empty netloc.",
            "The attribute 'url15': The server 'unknown_server' (config://unknown_server) is not found in the config: [server]",
            "The attribute 'url16'='https://' is not a valid URL.",
            "The attribute 'url17'='https:///' is not a valid URL.",
            "The attribute 'url18'='https:///static' is not a valid URL.",
            "The attribute 'url19'='' is not an URL.",
            "The attribute 'url20'='/' is not an URL.",
            "Unknown type 'unknown'.",
        ]))
        self.assertEqual(
            [self._only_name(t, "metadata") for t in themes["themes"]],
            [{
                "metadata": {},
                "children": [{
                    "metadata": {},
                    "children": [{
                        "metadata": {
                            "string": "string",
                            "list": ["1", "2", "a"],
                            "boolean": True,
                            "boolean2": False,
                            "integer": 1,
                            "float": 5.5,
                            "json": {"test": 123},
                            "date": "2003-09-25",
                            "time": "10:36:28",
                            "datetime": "2003-09-25T10:36:28",
                            "url1": "http://example.com/hi?a=b#c",
                            "url2": "http://dummy.org//etc/geomapfish/static/path/icon.png",
                            "url3": "http://dummy.org//etc/geomapfish/static/path/icon.png",
                            "url4": "http://dummy.org/tests_geoportal:cgxp/path/icon.png",
                            "url5": "http://dummy.org/project:static/path/icon.png",
                            "url6": "http://dummy.org/project:cgxp/path/icon.png",
                            "url7": "http://example.com/test",
                            "url8": "http://example.com/test/index.html",
                            "url9": "/dummy/static/icon.png",
                            "url10": "dummy/static/icon.png",
                        }
                    }]
                }]
            }]
        )
    def test_themes_edit_columns_extras(self):
        from c2cgeoportal_geoportal.views.entry import Entry
        from c2cgeoportal_commons.models.main import Metadata

        metadatas = [
            Metadata("lastUpdateDateColumn", "last_update_date"),
            Metadata("lastUpdateUserColumn", "last_update_user"),
        ]
        layer_id = self._create_layer(geom_type=False, exclude_properties=True, metadatas=metadatas)
        entry = Entry(self._get_request(layer_id, username="******", params={
            "version": "2",
            "interface": "main"
        }))

        themes = entry.themes()
        layers = themes["themes"][0]["children"][0]["children"]

        self.assertEqual(
            [layer["edit_columns"] for layer in layers],
            [[{
                "nillable": True,
                "type": "xsd:integer",
                "name": "child_id"
            }, {
                "nillable": True,
                "type": "xsd:boolean",
                "name": "deleted"
            }, {
                "nillable": True,
                "type": "xsd:date",
                "name": "date"
            }, {
                "nillable": True,
                "type": "xsd:time",
                "name": "start_time"
                # }, {
                #     "nillable": True,
                #     "type": "xsd:duration",
                #     "name": "interval"
            }, {
                "nillable": True,
                "type": "xsd:string",
                "name": "short_name1"
            }, {
                "nillable": True,
                "type": "xsd:string",
                "name": "short_name2",
                "maxLength": 50
            }, {
                "nillable": True,
                "type": "xsd:integer",
                "name": "short_number"
            }, {
                "nillable": True,
                "type": "xsd:double",
                "name": "double_number"
            }, {
                "nillable": True,
                "type": "xsd:base64Binary",
                "name": "large_binary"
            }, {
                "enumeration": [
                    "one",
                    "two",
                    "three",
                ],
                "type": "xsd:string",
                "name": "value",
                "nillable": True,
                "restriction": "enumeration"
            }, {
                "fractionDigits": 2,
                "nillable": True,
                "type": "xsd:decimal",
                "name": "numeric",
                "totalDigits": 5,
            }, {
                "name": "numeric2",
                "type": "xsd:decimal",
                "nillable": True
            }, {
                "srid": 21781,
                "nillable": True,
                "type": "gml:GeometryPropertyType",
                "name": "geom"
            }, {
                "restriction": "enumeration",
                "nillable": True,
                "type": "xsd:string",
                "name": "child",
                "enumeration": [
                    "c1\xe9",
                    "c2\xe9"
                ]
            }]]
        )