def test_get_restriction_areas(self, server_iface, dbsession, test_data):
        ogcserver_accesscontrol = OGCServerAccessControl(
            server_iface,
            'qgisserver1',
            21781,
            dbsession
        )

        test_layers = test_data['layers']
        test_roles = test_data['roles']

        assert (Access.FULL, None) == ogcserver_accesscontrol.get_restriction_areas(
            (test_layers['private_layer1'],),
            rw=True,
            roles='ROOT')

        for layer_names, rw, role_names, expected in (
            (('private_layer1',), False, ('role1',), (Access.AREA, [area1])),
            (('private_layer3',), False, ('role1',), (Access.AREA, [area1])),
        ):
            layers = [test_layers[layer_name] for layer_name in layer_names]
            roles = [test_roles[role_name] for role_name in role_names]
            ras = ogcserver_accesscontrol.get_restriction_areas(layers, rw, roles)
            assert expected == ras, (
                'get_restriction_areas with {} should return {}'.
                format((layer_names, rw, role_names), expected))
    def test_get_restriction_areas(self, server_iface, DBSession,
                                   test_data):  # noqa: ignore=N803
        from c2cgeoportal_commons.models.main import LayerWMS, Role

        dbsession = DBSession()
        ogcserver_accesscontrol = OGCServerAccessControl(
            server_iface, "qgisserver1", "no_project", 21781,
            lambda: dbsession)

        assert (Access.FULL,
                None) == ogcserver_accesscontrol.get_restriction_areas(
                    dbsession.query(LayerWMS).filter(
                        LayerWMS.name == "private_layer1").one(),
                    read_write=True,
                    roles="ROOT",
                )

        for layer_names, rw, role_names, expected in (
            (("private_layer1", ), False, ("role1", ), (Access.AREA, [area1])),
            (("private_layer3", ), False, ("role1", ), (Access.AREA, [area1])),
        ):
            layers = [
                dbsession.query(LayerWMS).filter(
                    LayerWMS.name == layer_name).one()
                for layer_name in layer_names
            ]
            roles = [
                dbsession.query(Role).filter(Role.name == role_name).one()
                for role_name in role_names
            ]
            ras = ogcserver_accesscontrol.get_restriction_areas(
                layers, rw, roles)
            assert expected == ras, "get_restriction_areas with {} should return {}".format(
                (layer_names, rw, role_names), expected)
Пример #3
0
    def test_get_restriction_areas(self, server_iface, dbsession, test_data):
        ogcserver_accesscontrol = OGCServerAccessControl(
            server_iface, "qgisserver1", 21781, dbsession)

        test_layers = test_data["layers"]
        test_roles = test_data["roles"]

        assert (Access.FULL,
                None) == ogcserver_accesscontrol.get_restriction_areas(
                    (test_layers["private_layer1"], ), rw=True, roles="ROOT")

        for layer_names, rw, role_names, expected in (
            (("private_layer1", ), False, ("role1", ), (Access.AREA, [area1])),
            (("private_layer3", ), False, ("role1", ), (Access.AREA, [area1])),
        ):
            layers = [test_layers[layer_name] for layer_name in layer_names]
            roles = [test_roles[role_name] for role_name in role_names]
            ras = ogcserver_accesscontrol.get_restriction_areas(
                layers, rw, roles)
            assert expected == ras, "get_restriction_areas with {} should return {}".format(
                (layer_names, rw, role_names), expected)