def setup_method(self, _):
        import transaction

        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.main import Functionality, Role
        from c2cgeoportal_commons.models.static import User

        create_default_ogcserver()
        role1 = Role(name="__test_role1")
        user1 = User(username="******", password="******", settings_role=role1, roles=[role1])
        role2 = Role(name="__test_role2")
        user2 = User(username="******", password="******", settings_role=role2, roles=[role2])
        role3 = Role(name="__test_role3")
        role4 = Role(name="__test_role4")
        user3 = User(
            username="******", password="******", roles=[role3, role4], settings_role=role3
        )

        functionality1 = Functionality("__test_s", "db")
        functionality2 = Functionality("__test_a", "db1")
        functionality3 = Functionality("__test_a", "db2")
        functionality4 = Functionality("__test_b", "db")
        role2.functionalities = [functionality1, functionality2, functionality3]
        role3.functionalities = [functionality1, functionality2]
        role4.functionalities = [functionality2, functionality3, functionality4]

        DBSession.add_all([user1, user2, user3, role1, role2])
        transaction.commit()
Ejemplo n.º 2
0
    def setup_method(self, _):
        import transaction
        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.main import Role, Functionality
        from c2cgeoportal_commons.models.static import User

        create_default_ogcserver()
        role1 = Role(name="__test_role1")
        user1 = User(username="******",
                     password="******",
                     role=role1)
        role2 = Role(name="__test_role2")
        user2 = User(username="******",
                     password="******",
                     role=role2)

        functionality1 = Functionality("__test_s", "db")
        functionality2 = Functionality("__test_a", "db1")
        functionality3 = Functionality("__test_a", "db2")
        role2.functionalities = [
            functionality1, functionality2, functionality3
        ]

        DBSession.add_all([user1, user2, role1, role2])
        transaction.commit()
Ejemplo n.º 3
0
    def setup_method(self, _):
        # Always see the diff
        # https://docs.python.org/2/library/unittest.html#unittest.TestCase.maxDiff
        self.maxDiff = None  # pylint: disable=invalid-name
        self._tables = []

        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.static import OAuth2Client, User

        user1 = User(username="******", password="******")
        user1.is_password_changed = True
        user1.email = "*****@*****.**"

        user2 = User(username="******", password="******")
        user2.email = "*****@*****.**"

        client = OAuth2Client()
        client.client_id = "qgis"
        client.secret = "1234"
        client.redirect_uri = "http://127.0.0.1:7070/"

        session = DBSession()

        session.add_all([user1, user2, client])
        session.flush()
        transaction.commit()
Ejemplo n.º 4
0
    def setup_method(self, _):
        self.maxDiff = None

        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.static import User

        user = User(username="******", password="******")
        DBSession.add(user)

        user2 = User(username="******",
                     password="******",
                     deactivated=True)
        DBSession.add(user2)

        now = datetime.datetime.utcnow()
        user3 = User(username="******",
                     password="******",
                     expire_on=now)
        DBSession.add(user3)

        tomorrow = now + datetime.timedelta(days=1)
        user4 = User(username="******",
                     password="******",
                     expire_on=tomorrow)
        DBSession.add(user4)

        DBSession.flush()
Ejemplo n.º 5
0
    def setup_method(self, _):
        # Always see the diff
        # https://docs.python.org/2/library/unittest.html#unittest.TestCase.maxDiff
        self.maxDiff = None  # pylint: disable=invalid-name
        self._tables = []

        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.main import Role
        from c2cgeoportal_commons.models.static import User

        setup_db()

        role1 = Role(name="__test_role1")
        user1 = User(username="******",
                     password="******",
                     settings_role=role1,
                     roles=[role1])
        user1.email = "*****@*****.**"

        role2 = Role(name="__test_role2",
                     extent=WKTElement("POLYGON((1 2, 1 4, 3 4, 3 2, 1 2))",
                                       srid=21781))
        user2 = User(username="******",
                     password="******",
                     settings_role=role2,
                     roles=[role2])

        DBSession.add_all([user1, user2])
        DBSession.flush()

        self.role1_id = role1.id

        transaction.commit()
Ejemplo n.º 6
0
    def setup_method(self, _):
        # Always see the diff
        # https://docs.python.org/2/library/unittest.html#unittest.TestCase.maxDiff
        self.maxDiff = None

        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.main import Interface, LayerWMS, RestrictionArea, Role
        from c2cgeoportal_commons.models.static import User

        setup_db()

        user1 = User(username="******", password="******")
        role1 = Role(name="__test_role1", description="__test_role1")
        user1.roles = [role1]
        user1.email = "Tarenpion"

        user2 = User(username="******", password="******")
        role2 = Role(name="__test_role2", description="__test_role2")
        user2.roles = [role2]
        user2.email = "Tarenpion"

        ogc_server_internal = create_default_ogcserver()

        main = Interface(name="main")

        layer1 = LayerWMS("layer_1", public=False)
        layer1.layer = "layer_1"
        layer1.ogc_server = ogc_server_internal
        layer1.interfaces = [main]

        layer2 = LayerWMS("layer_2", public=False)
        layer2.layer = "layer_2"
        layer2.ogc_server = ogc_server_internal
        layer2.interfaces = [main]

        layer3 = LayerWMS("layer_3", public=False)
        layer3.layer = "layer_3"
        layer3.ogc_server = ogc_server_internal
        layer3.interfaces = [main]

        area = "POLYGON((-100 30, -100 50, 100 50, 100 30, -100 30))"
        area = WKTElement(area, srid=21781)
        restricted_area1 = RestrictionArea("__test_ra1",
                                           "", [layer1, layer2], [role1],
                                           area,
                                           readwrite=True)

        area = "POLYGON((-100 0, -100 20, 100 20, 100 0, -100 0))"
        area = WKTElement(area, srid=21781)
        restricted_area2 = RestrictionArea("__test_ra2", "",
                                           [layer1, layer2, layer3], [role2],
                                           area)

        DBSession.add_all(
            [user1, user2, role1, role2, restricted_area1, restricted_area2])

        transaction.commit()
Ejemplo n.º 7
0
def setup_test_data(dbsession: Session) -> None:
    from c2cgeoportal_commons.models.main import Role
    from c2cgeoportal_commons.models.static import User
    role_admin = dbsession.merge(Role(name='role_admin'))
    role_user = dbsession.merge(Role(name='role_user'))

    dbsession.merge(
        User(username='******', email='*****@*****.**', role=role_admin))
    dbsession.merge(
        User(username='******', email='*****@*****.**', role=role_user))
Ejemplo n.º 8
0
def setup_test_data(dbsession: Session) -> None:
    """Initialize the testing data."""
    from c2cgeoportal_commons.models.main import Role  # pylint: disable=import-outside-toplevel
    from c2cgeoportal_commons.models.static import User  # pylint: disable=import-outside-toplevel

    role_admin = dbsession.merge(Role(name="role_admin"))
    role_user = dbsession.merge(Role(name="role_user"))

    dbsession.merge(
        User(username="******", email="*****@*****.**", settings_role=role_admin, roles=[role_admin])
    )
    dbsession.merge(
        User(username="******", email="*****@*****.**", settings_role=role_user, roles=[role_user])
    )
Ejemplo n.º 9
0
    def setup_method(self, _):
        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.main import Role, LayerWMS, RestrictionArea, Interface
        from c2cgeoportal_commons.models.static import User

        ogc_server_internal = create_default_ogcserver()

        role1 = Role(name="__test_role1", description="__test_role1")
        user1 = User(username="******",
                     password="******",
                     settings_role=role1,
                     roles=[role1])
        user1.email = "Tarenpion"

        main = Interface(name="main")

        layer1 = LayerWMS("testpoint_group_name", public=False)
        layer1.layer = "testpoint_group"
        layer1.ogc_server = ogc_server_internal
        layer1.interfaces = [main]

        layer2 = LayerWMS("testpoint_protected_2_name", public=False)
        layer2.layer = "testpoint_protected_2"
        layer2.ogc_server = ogc_server_internal
        layer2.interfaces = [main]

        area = "POLYGON((-100 30, -100 50, 100 50, 100 30, -100 30))"
        area = WKTElement(area, srid=21781)
        restricted_area1 = RestrictionArea("__test_ra1", "", [layer1, layer2],
                                           [role1], area)

        DBSession.add_all([user1, role1, layer1, layer2, restricted_area1])
        DBSession.flush()

        transaction.commit()
Ejemplo n.º 10
0
    def setup_method(self, _):
        setup_module()

        import transaction
        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.main import Role, Interface
        from c2cgeoportal_commons.models.static import User

        cleanup_db()

        self.metadata = None
        self.layer_ids = []

        DBSession.query(User).delete()
        DBSession.query(User).filter(User.username == "__test_user").delete()

        self.role = Role(name="__test_role")
        self.user = User(username="******",
                         password="******",
                         settings_role=self.role,
                         roles=[self.role])
        self.main = Interface(name="main")

        DBSession.add(self.user)
        DBSession.add(self.role)
        DBSession.add(self.main)
        transaction.commit()
Ejemplo n.º 11
0
def users_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.static import User
    from c2cgeoportal_commons.models.main import Role

    roles = []
    for i in range(0, 4):
        roles.append(Role('secretary_{}'.format(i)))
        dbsession.add(roles[i])
    users = []
    for i in range(0, 23):
        user = User('babar_{}'.format(i),
                    email='mail{}@valid.net'.format(i),
                    role=roles[i % 4])
        user.password = '******'
        user.is_password_changed = i % 2 == 1
        users.append(user)
        dbsession.add(user)

    dbsession.flush()

    yield {
        'roles': roles,
        'users': users
    }
Ejemplo n.º 12
0
def insert_users_test_data(dbsession):
    from c2cgeoportal_commons.models.static import User
    user = User("babar")
    t = dbsession.begin_nested()
    dbsession.add(user)
    yield
    t.rollback()
Ejemplo n.º 13
0
def users_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import Role
    from c2cgeoportal_commons.models.static import User

    roles = []
    for i in range(0, 4):
        roles.append(Role("secretary_{}".format(i)))
        dbsession.add(roles[i])
    users = []
    for i in range(0, 23):
        user = User(
            "babar_{}".format(i),
            email="mail{}@valid.net".format(i),
            settings_role=roles[i % 4],
            roles=[roles[i % 4]],
        )
        user.password = "******"
        user.is_password_changed = i % 2 == 1
        users.append(user)
        dbsession.add(user)

    dbsession.flush()

    yield {"roles": roles, "users": users}
Ejemplo n.º 14
0
    def setup_method(self, _):
        setup_module()

        import transaction

        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.main import Interface, Role
        from c2cgeoportal_commons.models.static import User

        setup_db()

        self.metadata = None
        self.layer_ids = []

        for o in DBSession.query(User).all():
            DBSession.delete(o)

        self.role = Role(name="__test_role")
        self.user = User(username="******",
                         password="******",
                         settings_role=self.role,
                         roles=[self.role])
        self.main = Interface(name="main")

        DBSession.add(self.user)
        DBSession.add(self.role)
        DBSession.add(self.main)

        create_default_ogcserver()

        transaction.commit()
Ejemplo n.º 15
0
def view_committing_user(request):
    from c2cgeoportal_commons.models.static import User
    user = User("momo")
    t = request.dbsession.begin_nested()
    request.dbsession.add(user)
    t.commit()
    return {}
Ejemplo n.º 16
0
    def test_grid_settings_role_none(self, dbsession, test_app):
        """
        Grid view must work even if a user's settings_role is None.
        """
        from c2cgeoportal_commons.models.static import User

        dbsession.add(User("test", email="*****@*****.**"))
        self.check_search(test_app, "test", total=1)
Ejemplo n.º 17
0
def roles_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import Role, Functionality, RestrictionArea
    from c2cgeoportal_commons.models.static import User

    functionalities = {}
    for name in ('default_basemap', 'location'):
        functionalities[name] = []
        for v in range(0, 4):
            functionality = Functionality(
                name=name,
                value='value_{}'.format(v))
            dbsession.add(functionality)
            functionalities[name].append(functionality)

    restrictionareas = []
    for i in range(0, 5):
        restrictionarea = RestrictionArea(
            name='restrictionarea_{}'.format(i))
        dbsession.add(restrictionarea)
        restrictionareas.append(restrictionarea)

    roles = []
    for i in range(0, 23):
        role = Role('secretary_' + str(i))
        role.functionalities = [
            functionalities['default_basemap'][0],
            functionalities['location'][0],
            functionalities['location'][1]]
        role.restrictionareas = [
            restrictionareas[0],
            restrictionareas[1]]
        role.extent = from_shape(box(485869.5728, 76443.1884, 837076.5648, 299941.7864),
                                 srid=21781)
        dbsession.add(role)
        roles.append(role)

    # Users roles must not be broken with role name changes
    users = []
    for i in range(0, 23):
        user = User("babar_" + str(i),
                    email='mail' + str(i),
                    settings_role=roles[i],
                    roles=[roles[i]])
        user.password = '******'
        user.is_password_changed = i % 2 == 1
        users.append(user)
        dbsession.add(user)

    dbsession.flush()

    yield {
        'functionalities': functionalities,
        'restrictionareas': restrictionareas,
        'users': users,
        'roles': roles
    }
Ejemplo n.º 18
0
def roles_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import Functionality, RestrictionArea, Role
    from c2cgeoportal_commons.models.static import User

    # Note that "default_basemap" is not relevant for roles
    functionalities = {}
    for name in ("default_basemap", "default_theme", "print_template"):
        functionalities[name] = []
        for v in range(0, 4):
            functionality = Functionality(name=name, value=f"value_{v}")
            dbsession.add(functionality)
            functionalities[name].append(functionality)

    restrictionareas = []
    for i in range(0, 5):
        restrictionarea = RestrictionArea(name=f"restrictionarea_{i}")
        dbsession.add(restrictionarea)
        restrictionareas.append(restrictionarea)

    roles = []
    for i in range(0, 23):
        role = Role("secretary_" + str(i))
        role.functionalities = [
            functionalities["default_theme"][0],
            functionalities["print_template"][0],
            functionalities["print_template"][1],
        ]
        role.restrictionareas = [restrictionareas[0], restrictionareas[1]]
        role.extent = from_shape(box(485869.5728, 76443.1884, 837076.5648,
                                     299941.7864),
                                 srid=21781)
        dbsession.add(role)
        roles.append(role)

    # Users roles must not be broken with role name changes
    users = []
    for i in range(0, 23):
        user = User("babar_" + str(i),
                    email="mail" + str(i),
                    settings_role=roles[i],
                    roles=[roles[i]])
        user.password = "******"
        user.is_password_changed = i % 2 == 1
        users.append(user)
        dbsession.add(user)

    dbsession.flush()

    yield {
        "functionalities": functionalities,
        "restrictionareas": restrictionareas,
        "users": users,
        "roles": roles,
    }
Ejemplo n.º 19
0
def insert_users_test_data(dbsession):
    from c2cgeoportal_commons.models.static import User
    from c2cgeoportal_commons.models.main import Role
    user = User("babar")
    user.roles = [Role(name='Role1'), Role(name='Role2')]
    t = dbsession.begin_nested()
    dbsession.add(user)
    dbsession.flush()
    yield
    t.rollback()
Ejemplo n.º 20
0
 def test_add(self, dbsession):
     from c2cgeoportal_commons.models.static import User
     user = User("momo")
     dbsession.begin_nested()
     dbsession.add(user)
     dbsession.commit()
     users = dbsession.query(User).all()
     assert len(users) == 2, "added a user"
     assert users[0].username == 'babar', "user from test data is babar"
     assert users[1].username == 'momo', "added user is momo"
Ejemplo n.º 21
0
def insert_roles_test_data(dbsession):
    from c2cgeoportal_commons.models.main import Role
    from c2cgeoportal_commons.models.static import User
    role = Role("secretary")
    user = User("user1", roles=[role])
    t = dbsession.begin_nested()
    dbsession.add(role)
    dbsession.add(user)
    dbsession.flush()
    yield
    t.rollback()
Ejemplo n.º 22
0
    def setup_method(self, _):
        import transaction
        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.main import Role
        from c2cgeoportal_commons.models.static import User

        r = Role(name="__test_role")
        u = User(username="******", password="******", role=r)

        DBSession.add_all([r, u])
        transaction.commit()
Ejemplo n.º 23
0
        def setter(request):
            class User:
                pass

            class Role:
                pass

            u = User()
            u.username = "******"
            u.role = Role()
            u.role.name = "__bar"
            return u
Ejemplo n.º 24
0
    def setup_method(self, _):
        self.maxDiff = None

        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.static import User

        user = User(username="******", password="******")
        DBSession.add(user)

        user2 = User(username="******",
                     password="******",
                     deactivated=True)
        DBSession.add(user2)

        now = datetime.datetime.utcnow()
        user3 = User(username="******",
                     password="******",
                     expire_on=now)
        DBSession.add(user3)

        tomorrow = now + datetime.timedelta(days=1)
        user4 = User(username="******",
                     password="******",
                     expire_on=tomorrow)
        DBSession.add(user4)

        DBSession.flush()

        self.old_remember = pyramid.security.remember
        self.user = None

        def remember(request, user=None):
            del request  # Unused
            self.user = user

        pyramid.security.remember = remember
Ejemplo n.º 25
0
    def setup_method(self, _):
        # Always see the diff
        # https://docs.python.org/2/library/unittest.html#unittest.TestCase.maxDiff
        self.maxDiff = None

        setup_db()

        self._tables = []

        import transaction

        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.main import (
            OGCSERVER_AUTH_NOAUTH,
            Interface,
            LayerGroup,
            Role,
            Theme,
            TreeItem,
        )
        from c2cgeoportal_commons.models.static import User

        for treeitem in DBSession.query(TreeItem).all():
            DBSession.delete(treeitem)

        self.role = Role(name="__test_role")
        self.user = User(username="******",
                         password="******",
                         settings_role=self.role,
                         roles=[self.role])
        self.main = Interface(name="main")

        self.ogc_server = create_default_ogcserver()
        self.ogc_server.auth = OGCSERVER_AUTH_NOAUTH

        self.metadata = None
        self.layer_ids = []

        self.layer_group_1 = LayerGroup(name="__test_layer_group_1")

        theme = Theme(name="__test_theme")
        theme.interfaces = [self.main]
        theme.children = [self.layer_group_1]

        DBSession.add_all(
            [self.main, self.user, self.role, theme, self.layer_group_1])

        transaction.commit()
Ejemplo n.º 26
0
    def test_add(self, dbsession):
        from c2cgeoportal_commons.models.main import Role
        from c2cgeoportal_commons.models.static import User, user_role

        user = User(username="******")
        user.roles = [Role(name="Role3")]
        dbsession.begin_nested()
        dbsession.add(user)
        dbsession.commit()
        assert dbsession.query(User).count() == 2, "added a user"
        dbsession.expire(user)
        assert user.username == "momo", "added user is momo"
        assert 1 == len(user.roles)
        assert user.roles[0].name == "Role3"
        assert 1 == dbsession.query(user_role).filter(
            user_role.c.user_id == user.id).count()
        def setter(request):
            del request  # Unused

            class User:
                pass

            class Role:
                pass

            user = User()
            user.username = "******"
            role = Role()
            role.name = "__bar"
            user.settings_role = role
            user.roles = [role]
            return user
Ejemplo n.º 28
0
    def setup_method(self, _):
        self.maxDiff = None

        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.static import User

        user = User(username="******", password="******")
        DBSession.add(user)
        DBSession.flush()

        self.old_remember = pyramid.security.remember
        self.user = None

        def remember(request, user=None):
            self.user = user

        pyramid.security.remember = remember
Ejemplo n.º 29
0
    def setup_method(self, _):
        # Always see the diff
        # https://docs.python.org/2/library/unittest.html#unittest.TestCase.maxDiff
        self.maxDiff = None  # pylint: disable=invalid-name
        self._tables = []

        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.static import User

        setup_db()

        user = User(username="******", password="******")
        user.email = "*****@*****.**"
        DBSession.add(user)
        testing.setUp().testing_securitypolicy(remember_result=[("Cookie",
                                                                 "Test")])
        transaction.commit()
Ejemplo n.º 30
0
def test_data(dbsession):
    from c2cgeoportal_commons.models.main import (
        LayerWMS,
        OGCServer,
        OGCSERVER_TYPE_QGISSERVER,
        OGCSERVER_AUTH_STANDARD,
        RestrictionArea,
        Role,
    )
    from c2cgeoportal_commons.models.static import User

    ogc_server1 = OGCServer(name='qgisserver1',
                            type_=OGCSERVER_TYPE_QGISSERVER,
                            image_type='image/png',
                            auth=OGCSERVER_AUTH_STANDARD)
    ogc_server2 = OGCServer(name='qgisserver2',
                            type_=OGCSERVER_TYPE_QGISSERVER,
                            image_type='image/png',
                            auth=OGCSERVER_AUTH_STANDARD)
    ogc_servers = {
        ogc_server.name: ogc_server
        for ogc_server in (ogc_server1, ogc_server2)
    }
    dbsession.add_all(ogc_servers.values())

    role1 = Role('role1')
    role2 = Role('role2')
    roles = {role.name: role for role in (role1, role2)}
    dbsession.add_all(roles.values())

    user1 = User('user1', roles=[role1])
    user2 = User('user12', roles=[role1, role2])
    users = {user.username: user for user in (user1, user2)}
    dbsession.add_all(users.values())

    project = QgsProject.instance()

    def add_node(parent_node, node_def):

        if node_def['type'] == 'layer':
            vlayer = QgsVectorLayer("Point", node_def['name'], 'memory')
            project.addMapLayer(vlayer)
            node = project.layerTreeRoot().findLayer(vlayer)
            clone = node.clone()
            parent_node.addChildNode(clone)
            node.parent().takeChild(node)

        if node_def['type'] == 'group':
            node = parent_node.addGroup(node_def['name'])
            for child_def in node_def['children']:
                add_node(node, child_def)

    for node in [{
            'name':
            'root',
            'type':
            'group',
            'children': [
                {
                    'name': 'public_group',
                    'type': 'group',
                    'children': [{
                        'name': 'public_layer',
                        'type': 'layer'
                    }]
                },
                {
                    'name': 'private_group1',
                    'type': 'group',
                    'children': [{
                        'name': 'private_layer1',
                        'type': 'layer'
                    }]
                },
                {
                    'name': 'private_group2',
                    'type': 'group',
                    'children': [{
                        'name': 'private_layer2',
                        'type': 'layer'
                    }]
                },
            ]
    }]:
        add_node(project.layerTreeRoot(), node)

    public_group = LayerWMS(name='public_group',
                            layer='public_group',
                            public=True)
    public_group.ogc_server = ogc_server1

    public_layer = LayerWMS(name='public_layer',
                            layer='public_layer',
                            public=True)
    public_layer.ogc_server = ogc_server1

    private_layer1 = LayerWMS(name='private_layer1',
                              layer='private_layer1',
                              public=False)
    private_layer1.ogc_server = ogc_server1

    private_layer2 = LayerWMS(name='private_layer2',
                              layer='private_layer2',
                              public=False)
    private_layer2.ogc_server = ogc_server1

    layers = {
        layer.name: layer
        for layer in (public_group, public_layer, private_layer1,
                      private_layer2)
    }
    dbsession.add_all(layers.values())

    ra1 = RestrictionArea('restriction_area1',
                          layers=[private_layer1],
                          roles=[role1],
                          area=from_shape(area1, srid=21781))
    ra2 = RestrictionArea('restriction_area2',
                          layers=[private_layer2],
                          roles=[role2],
                          readwrite=True)
    restriction_areas = {ra.name: ra for ra in (ra1, ra2)}
    dbsession.add_all(restriction_areas.values())

    t = dbsession.begin_nested()

    dbsession.flush()

    yield {
        'ogc_servers': ogc_servers,
        'roles': roles,
        'users': users,
        'layers': layers,
        'restriction_areas': restriction_areas,
    }

    t.rollback()