def test_error(self):
        from c2cgeoportal_geoportal.views.theme import Theme

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

        request = self._create_request_obj()
        request.params = {"interface": "main"}
        theme_view = Theme(request)
        themes = theme_view.themes()
        self.assertEqual(set(themes["errors"]), set())
        self.assertEqual([t["name"] for t in themes["themes"]], [])
Ejemplo n.º 3
0
    def test_themev2_auth_no_edit_permission(self):
        from c2cgeoportal_geoportal.views.theme import Theme

        request = self._create_request_obj(username="******")
        request.params = {"interface": "main"}
        theme_view = Theme(request)
        themes = theme_view.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_themes_edit_columns_extras(self):
        from c2cgeoportal_geoportal.views.theme import Theme
        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)
        theme_view = Theme(
            self._get_request(layer_id,
                              username="******",
                              params={"interface": "main"}))

        themes = theme_view.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"],
                },
            ]],
        )
Ejemplo n.º 5
0
    def test_metadata(self):
        from c2cgeoportal_geoportal.views.theme import Theme

        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": "regex",
                "type": "regex",
                "regex": "^valid$"
            },
            {
                "name": "unknown",
                "type": "unknown"
            },
        ]
        types += [{"name": f"url{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 f"http://dummy.org/{url}"

        request.static_url = static_url
        request.params = {"interface": "desktop"}
        theme_view = Theme(request)

        themes = theme_view.themes()
        self.assertEqual(
            set(themes["errors"]),
            {
                "The boolean attribute 'boolean3'='hello' is not in [yes, y, on, 1, true, no, n, off, 0, false].",
                "The attribute 'json_wrong'='{\"test\": 123' has an error: Expecting ',' delimiter: line 1 column 13 (char 12)",
                "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: Hello",
                "The regex attribute 'regex'='invalid' does not match expected pattern '^valid$'.",
                "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",
                            "regex": "valid",
                            "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",
                        }
                    }],
                }],
            }],
        )