Exemple #1
0
 def test_by_group_and_perm(self, db_session):
     add_group(db_session, )
     queried = GroupPermission.by_group_and_perm(1,
                                                 'manage_apps',
                                                 db_session=db_session)
     assert queried.group_id == 1
     assert queried.perm_name == 'manage_apps'
Exemple #2
0
    def test_by_group_name_wrong_groupname(self, db_session):
        add_group(db_session)
        queried_group = GroupService.by_group_name(
            "not existing group", db_session=db_session
        )

        assert queried_group is None
 def test_by_group_and_perm(self, db_session):
     add_group(db_session)
     queried = GroupPermissionService.by_group_and_perm(
         1, "manage_apps", db_session=db_session
     )
     assert queried.group_id == 1
     assert queried.perm_name == "manage_apps"
Exemple #4
0
    def test_all(self, db_session):
        group1 = add_group(db_session, "group1")
        group2 = add_group(db_session, "group2")

        all_groups = Group.all(db_session=db_session).all()

        assert len(all_groups) == 2
        assert all_groups[0] == group1
        assert all_groups[1] == group2
 def test_users_for_perms(self, db_session):
     user = User(user_name='aaa', email='aaa', status=0)
     user.set_password('password')
     aaa_perm = UserPermission(perm_name='aaa')
     bbb_perm = UserPermission(perm_name='bbb')
     bbb2_perm = UserPermission(perm_name='bbb')
     user.user_permissions.append(aaa_perm)
     user.user_permissions.append(bbb_perm)
     user2 = User(user_name='bbb', email='bbb', status=0)
     user2.set_password('password')
     user2.user_permissions.append(bbb2_perm)
     user3 = User(user_name='ccc', email='ccc', status=0)
     user3.set_password('password')
     group = add_group(db_session, )
     group.users.append(user3)
     db_session.add(user)
     db_session.add(user2)
     db_session.flush()
     users = User.users_for_perms(['aaa'], db_session=db_session)
     assert len(users.all()) == 1
     assert users[0].user_name == 'aaa'
     users = User.users_for_perms(['bbb'], db_session=db_session).all()
     assert len(users) == 2
     assert ['aaa', 'bbb'] == sorted([u.user_name for u in users])
     users = User.users_for_perms(['aaa', 'bbb', 'manage_apps'],
                                  db_session=db_session)
     assert ['aaa', 'bbb', 'ccc'] == sorted([u.user_name for u in users])
Exemple #6
0
    def test_resource_groups_for_any_perm_just_group_perms_limited_empty_group(
            self, db_session):
        self.maxDiff = 99999
        self.set_up_user_group_and_perms(db_session)
        user6 = add_user(db_session, 6, 'user 6')
        user7 = add_user(db_session, 7, 'user 7')
        perm2 = GroupResourcePermission(perm_name='group_perm2',
                                        resource_id=self.resource.resource_id)
        self.group.resource_permissions.append(perm2)
        self.group.users.append(user6)
        self.group.users.append(user7)

        group3 = add_group(db_session, 'Empty group')
        perm3 = GroupResourcePermission(perm_name='group_permx',
                                        resource_id=self.resource.resource_id)
        group3.resource_permissions.append(perm3)
        perms = self.resource.groups_for_perm('__any_permission__',
                                              limit_group_permissions=True,
                                              db_session=db_session)

        second = [
            PermissionTuple(None, 'group_perm', 'group', self.group,
                            self.resource, False, True),
            PermissionTuple(None, 'group_perm2', 'group', self.group,
                            self.resource, False, True),
            PermissionTuple(None, 'group_perm', 'group', self.group2,
                            self.resource, False, True),
            PermissionTuple(None, 'group_permx', 'group', group3,
                            self.resource, False, True)
        ]

        check_one_in_other(perms, second)
Exemple #7
0
 def test_get(self, db_session):
     org_group = add_group(db_session, 'group1')
     group = GroupPermissionService.get(group_id=org_group.id,
                                        perm_name='manage_apps',
                                        db_session=db_session)
     assert group.group_id == 1
     assert group.perm_name == 'manage_apps'
Exemple #8
0
    def test_resource_users_limited_group_ownage(self, db_session):
        self.maxDiff = 9999
        self.set_up_user_group_and_perms(db_session)
        resource = ResourceTestobjB(resource_id=99,
                                    resource_name="other",
                                    owner_user_id=self.user2.id)
        group3 = add_group(db_session, "group 3")
        user2_permission = UserResourcePermission(perm_name="foo_perm",
                                                  user_id=self.user2.id)
        group3_permission = GroupResourcePermission(perm_name="group_perm",
                                                    group_id=group3.id)
        resource.group_permissions.append(group3_permission)
        resource.user_permissions.append(user2_permission)
        group3.users.append(self.user3)
        self.user.resources.append(resource)
        self.group2.resources.append(resource)
        db_session.flush()
        perms = ResourceService.users_for_perm(resource,
                                               "__any_permission__",
                                               db_session=db_session)
        second = [
            PermissionTuple(self.user2, "foo_perm", "user", None, resource,
                            False, True),
            PermissionTuple(self.user, ALL_PERMISSIONS, "user", None, resource,
                            True, True),
            PermissionTuple(self.user4, ALL_PERMISSIONS, "group", self.group2,
                            resource, True, True),
            PermissionTuple(self.user3, "group_perm", "group", group3,
                            resource, False, True),
        ]

        check_one_in_other(perms, second)
 def test_users_for_perms(self, db_session):
     user = User(user_name="aaa", email="aaa", status=0)
     UserService.set_password(user, "password")
     aaa_perm = UserPermission(perm_name="aaa")
     bbb_perm = UserPermission(perm_name="bbb")
     bbb2_perm = UserPermission(perm_name="bbb")
     user.user_permissions.append(aaa_perm)
     user.user_permissions.append(bbb_perm)
     user2 = User(user_name="bbb", email="bbb", status=0)
     UserService.set_password(user2, "password")
     user2.user_permissions.append(bbb2_perm)
     user3 = User(user_name="ccc", email="ccc", status=0)
     UserService.set_password(user3, "password")
     group = add_group(db_session)
     group.users.append(user3)
     db_session.add(user)
     db_session.add(user2)
     db_session.flush()
     users = UserService.users_for_perms(["aaa"], db_session=db_session)
     assert len(users.all()) == 1
     assert users[0].user_name == "aaa"
     users = UserService.users_for_perms(["bbb"], db_session=db_session).all()
     assert len(users) == 2
     assert ["aaa", "bbb"] == sorted([u.user_name for u in users])
     users = UserService.users_for_perms(
         ["aaa", "bbb", "manage_apps"], db_session=db_session
     )
     assert ["aaa", "bbb", "ccc"] == sorted([u.user_name for u in users])
    def test_resource_users_limited_group_ownage(self, db_session):
        self.maxDiff = 9999
        self.set_up_user_group_and_perms(db_session)
        resource = TestResourceB(resource_id=99,
                                 resource_name='other',
                                 owner_user_id=self.user2.id)
        group3 = add_group(db_session, 'group 3')
        user2_permission = UserResourcePermission(
            perm_name='foo_perm',
            user_id=self.user2.id,
        )
        group3_permission = GroupResourcePermission(
            perm_name='group_perm',
            group_id=group3.id
        )
        resource.group_permissions.append(group3_permission)
        resource.user_permissions.append(user2_permission)
        group3.users.append(self.user3)
        self.user.resources.append(resource)
        self.group2.resources.append(resource)
        db_session.flush()
        perms = resource.users_for_perm('__any_permission__',
                                        db_session=db_session)
        second = [
            PermissionTuple(self.user2, 'foo_perm', 'user', None, resource,
                            False, True),
            PermissionTuple(self.user, ALL_PERMISSIONS, 'user', None, resource,
                            True, True),
            PermissionTuple(self.user4, ALL_PERMISSIONS, 'group', self.group2,
                            resource, True, True),
            PermissionTuple(self.user3, 'group_perm', 'group', group3,
                            resource, False, True)
        ]

        check_one_in_other(perms, second)
Exemple #11
0
 def test_users_for_perms(self, db_session):
     user = User(user_name='aaa', email='aaa', status=0)
     user.set_password('password')
     aaa_perm = UserPermission(perm_name='aaa')
     bbb_perm = UserPermission(perm_name='bbb')
     bbb2_perm = UserPermission(perm_name='bbb')
     user.user_permissions.append(aaa_perm)
     user.user_permissions.append(bbb_perm)
     user2 = User(user_name='bbb', email='bbb', status=0)
     user2.set_password('password')
     user2.user_permissions.append(bbb2_perm)
     user3 = User(user_name='ccc', email='ccc', status=0)
     user3.set_password('password')
     group = add_group(db_session, )
     group.users.append(user3)
     db_session.add(user)
     db_session.add(user2)
     db_session.flush()
     users = User.users_for_perms(['aaa'], db_session=db_session)
     assert len(users.all()) == 1
     assert users[0].user_name == 'aaa'
     users = User.users_for_perms(['bbb'], db_session=db_session).all()
     assert len(users) == 2
     assert ['aaa', 'bbb'] == sorted([u.user_name for u in users])
     users = User.users_for_perms(['aaa', 'bbb', 'manage_apps'],
                                  db_session=db_session)
     assert ['aaa', 'bbb', 'ccc'] == sorted([u.user_name for u in users])
 def test_get(self, db_session):
     org_group = add_group(db_session, 'group1')
     group = GroupPermissionService.get(
         group_id=org_group.id, perm_name='manage_apps',
         db_session=db_session)
     assert group.group_id == 1
     assert group.perm_name == 'manage_apps'
Exemple #13
0
 def test_users_for_perms(self, db_session):
     user = User(user_name="aaa", email="aaa", status=0)
     UserService.set_password(user, "password")
     aaa_perm = UserPermission(perm_name="aaa")
     bbb_perm = UserPermission(perm_name="bbb")
     bbb2_perm = UserPermission(perm_name="bbb")
     user.user_permissions.append(aaa_perm)
     user.user_permissions.append(bbb_perm)
     user2 = User(user_name="bbb", email="bbb", status=0)
     UserService.set_password(user2, "password")
     user2.user_permissions.append(bbb2_perm)
     user3 = User(user_name="ccc", email="ccc", status=0)
     UserService.set_password(user3, "password")
     group = add_group(db_session)
     group.users.append(user3)
     db_session.add(user)
     db_session.add(user2)
     db_session.flush()
     users = UserService.users_for_perms(["aaa"], db_session=db_session)
     assert len(users.all()) == 1
     assert users[0].user_name == "aaa"
     users = UserService.users_for_perms(["bbb"],
                                         db_session=db_session).all()
     assert len(users) == 2
     assert ["aaa", "bbb"] == sorted([u.user_name for u in users])
     users = UserService.users_for_perms(["aaa", "bbb", "manage_apps"],
                                         db_session=db_session)
     assert ["aaa", "bbb", "ccc"] == sorted([u.user_name for u in users])
Exemple #14
0
    def test_resource_groups_for_any_perm_just_group_perms_limited_empty_group(
            self, db_session):
        self.maxDiff = 99999
        self.set_up_user_group_and_perms(db_session)
        user6 = add_user(db_session, 6, "user 6")
        user7 = add_user(db_session, 7, "user 7")
        perm2 = GroupResourcePermission(perm_name="group_perm2",
                                        resource_id=self.resource.resource_id)
        self.group.resource_permissions.append(perm2)
        self.group.users.append(user6)
        self.group.users.append(user7)

        group3 = add_group(db_session, "Empty group")
        perm3 = GroupResourcePermission(perm_name="group_permx",
                                        resource_id=self.resource.resource_id)
        group3.resource_permissions.append(perm3)
        perms = ResourceService.groups_for_perm(
            self.resource,
            "__any_permission__",
            limit_group_permissions=True,
            db_session=db_session,
        )

        second = [
            PermissionTuple(None, "group_perm", "group", self.group,
                            self.resource, False, True),
            PermissionTuple(None, "group_perm2", "group", self.group,
                            self.resource, False, True),
            PermissionTuple(None, "group_perm", "group", self.group2,
                            self.resource, False, True),
            PermissionTuple(None, "group_permx", "group", group3,
                            self.resource, False, True),
        ]

        check_one_in_other(perms, second)
Exemple #15
0
    def test_resource_users_limited_group_ownage(self, db_session):
        self.maxDiff = 9999
        self.set_up_user_group_and_perms(db_session)
        resource = TestResourceB(resource_id=99,
                                 resource_name='other',
                                 owner_user_id=self.user2.id)
        group3 = add_group(db_session, 'group 3')
        user2_permission = UserResourcePermission(
            perm_name='foo_perm',
            user_id=self.user2.id,
        )
        group3_permission = GroupResourcePermission(perm_name='group_perm',
                                                    group_id=group3.id)
        resource.group_permissions.append(group3_permission)
        resource.user_permissions.append(user2_permission)
        group3.users.append(self.user3)
        self.user.resources.append(resource)
        self.group2.resources.append(resource)
        db_session.flush()
        perms = resource.users_for_perm('__any_permission__',
                                        db_session=db_session)
        second = [
            PermissionTuple(self.user2, 'foo_perm', 'user', None, resource,
                            False, True),
            PermissionTuple(self.user, ALL_PERMISSIONS, 'user', None, resource,
                            True, True),
            PermissionTuple(self.user4, ALL_PERMISSIONS, 'group', self.group2,
                            resource, True, True),
            PermissionTuple(self.user3, 'group_perm', 'group', group3,
                            resource, False, True)
        ]

        check_one_in_other(perms, second)
    def test_users(self, db_session):
        user1 = add_user(db_session, 'user1', 'email1')
        user2 = add_user(db_session, 'user2', 'email2')

        group = add_group(db_session, )
        group.users.append(user1)
        group.users.append(user2)

        assert group.users[0] == user1
        assert group.users[1] == user2
    def test_users(self, db_session):
        user1 = add_user(db_session, 'user1', 'email1')
        user2 = add_user(db_session, 'user2', 'email2')

        group = add_group(db_session, )
        group.users.append(user1)
        group.users.append(user2)

        assert group.users[0] == user1
        assert group.users[1] == user2
Exemple #18
0
    def test_users(self, db_session):
        user1 = add_user(db_session, "user1", "email1")
        user2 = add_user(db_session, "user2", "email2")

        group = add_group(db_session)
        group.users.append(user1)
        group.users.append(user2)

        assert group.users[0] == user1
        assert group.users[1] == user2
Exemple #19
0
 def test_resources_with_wrong_group_permission(self, db_session):
     created_user = add_user(db_session)
     resource = add_resource(db_session, 1, 'test_resource')
     group = add_group(db_session, )
     group.users.append(created_user)
     group_permission = GroupResourcePermission(
         perm_name='test_perm_bad',
         group_id=group.id,
         resource_id=resource.resource_id)
     with pytest.raises(AssertionError):
         resource.group_permissions.append(group_permission)
 def test_resources_with_wrong_group_permission(self, db_session):
     created_user = add_user(db_session)
     resource = add_resource(db_session, 1, 'test_resource')
     group = add_group(db_session, )
     group.users.append(created_user)
     group_permission = GroupResourcePermission(
         perm_name='test_perm_bad',
         group_id=group.id,
         resource_id=resource.resource_id
     )
     with pytest.raises(AssertionError):
         resource.group_permissions.append(group_permission)
    def test_resource_users_for_any_perm_limited_group_perms_empty_group(
        self, db_session
    ):
        self.maxDiff = 99999
        self.set_up_user_group_and_perms(db_session)
        user6 = add_user(db_session, 6, "user 6")
        user7 = add_user(db_session, 7, "user 7")
        perm2 = GroupResourcePermission(
            perm_name="group_perm2", resource_id=self.resource.resource_id
        )
        self.group.resource_permissions.append(perm2)
        self.group.users.append(user6)
        self.group.users.append(user7)
        group3 = add_group(db_session, "Empty group")
        perm3 = GroupResourcePermission(
            perm_name="group_permx", resource_id=self.resource.resource_id
        )
        group3.resource_permissions.append(perm3)

        perms = ResourceService.users_for_perm(
            self.resource,
            "__any_permission__",
            limit_group_permissions=True,
            db_session=db_session,
        )

        second = [
            PermissionTuple(
                None, "group_perm", "group", self.group, self.resource, False, True
            ),
            PermissionTuple(
                None, "group_perm2", "group", self.group, self.resource, False, True
            ),
            PermissionTuple(
                self.user, "test_perm2", "user", None, self.resource, False, True
            ),
            PermissionTuple(
                self.user, "foo_perm", "user", None, self.resource, False, True
            ),
            PermissionTuple(
                None, "group_perm", "group", self.group2, self.resource, False, True
            ),
            PermissionTuple(
                None, "group_permx", "group", group3, self.resource, False, True
            ),
        ]

        check_one_in_other(perms, second)
Exemple #22
0
    def test_user_paginator_usernames(self, db_session):
        user1 = add_user(db_session, "user1", "email1")
        user2 = add_user(db_session, "user2", "email2")
        user3 = add_user(db_session, "user3", "email3")

        group = add_group(db_session)
        group.users.append(user1)
        group.users.append(user2)
        group.users.append(user3)

        # TODO: users count when filtering on names?
        paginator = GroupService.get_user_paginator(group, 1, user_ids=[1, 3])

        assert paginator.page == 1
        assert paginator.first_item == 1
        assert paginator.last_item == 2
        assert paginator.items == [user1, user3]
        assert paginator.item_count == 2
        assert paginator.page_count == 1
Exemple #23
0
    def test_user_paginator_usernames(self, db_session):
        user1 = add_user(db_session, 'user1', 'email1')
        user2 = add_user(db_session, 'user2', 'email2')
        user3 = add_user(db_session, 'user3', 'email3')

        group = add_group(db_session, )
        group.users.append(user1)
        group.users.append(user2)
        group.users.append(user3)

        # TODO: users count when filtering on names?
        paginator = group.get_user_paginator(1, user_ids=[1, 3])

        assert paginator.page == 1
        assert paginator.first_item == 1
        assert paginator.last_item == 2
        assert paginator.items == [user1, user3]
        assert paginator.item_count == 2
        assert paginator.page_count == 1
 def test_resources_with_group_permission(self, db_session):
     created_user = add_user(db_session)
     resource = add_resource(db_session, 1, "test_resource")
     resource2 = add_resource(db_session, 2, "test_resource2")
     add_resource(db_session, 3, "test_resource3")
     group = add_group(db_session)
     group.users.append(created_user)
     group_permission = GroupResourcePermission(
         perm_name="test_perm", group_id=1, resource_id=resource.resource_id
     )
     group_permission2 = GroupResourcePermission(
         perm_name="foo_perm", group_id=1, resource_id=resource2.resource_id
     )
     resource.group_permissions.append(group_permission)
     resource2.group_permissions.append(group_permission2)
     db_session.flush()
     resources = UserService.resources_with_perms(
         created_user, ["foo_perm"], db_session=db_session
     ).all()
     assert resources[0] == resource2
    def test_user_paginator(self, db_session):
        user1 = add_user(db_session, 'user1', 'email1')
        user2 = add_user(db_session, 'user2', 'email2')

        group = add_group(db_session, )
        group.users.append(user1)
        group.users.append(user2)
        users_count = len(group.users)
        get_params = {'foo': 'bar', 'baz': 'xxx'}

        paginator = group.get_user_paginator(1, users_count,
                                             GET_params=get_params)

        assert paginator.page == 1
        assert paginator.first_item == 1
        assert paginator.last_item == 2
        assert paginator.items == [user1, user2]
        assert paginator.items == [user1, user2]
        assert paginator.items == [user1, user2]
        assert paginator.items == [user1, user2]
    def test_user_paginator_usernames(self, db_session):
        user1 = add_user(db_session, 'user1', 'email1')
        user2 = add_user(db_session, 'user2', 'email2')
        user3 = add_user(db_session, 'user3', 'email3')

        group = add_group(db_session, )
        group.users.append(user1)
        group.users.append(user2)
        group.users.append(user3)

        # TODO: users count when filtering on names?
        paginator = group.get_user_paginator(1,
                                             user_ids=[1, 3])

        assert paginator.page == 1
        assert paginator.first_item == 1
        assert paginator.last_item == 2
        assert paginator.items == [user1, user3]
        assert paginator.item_count == 2
        assert paginator.page_count == 1
    def test_user_paginator(self, db_session):
        user1 = add_user(db_session, 'user1', 'email1')
        user2 = add_user(db_session, 'user2', 'email2')

        group = add_group(db_session, )
        group.users.append(user1)
        group.users.append(user2)
        users_count = len(group.users)
        get_params = {'foo': 'bar', 'baz': 'xxx'}

        paginator = group.get_user_paginator(1, users_count,
                                             GET_params=get_params)

        assert paginator.page == 1
        assert paginator.first_item == 1
        assert paginator.last_item == 2
        assert paginator.items == [user1, user2]
        assert paginator.items == [user1, user2]
        assert paginator.items == [user1, user2]
        assert paginator.items == [user1, user2]
Exemple #28
0
    def test_user_paginator(self, db_session):
        user1 = add_user(db_session, "user1", "email1")
        user2 = add_user(db_session, "user2", "email2")

        group = add_group(db_session)
        group.users.append(user1)
        group.users.append(user2)
        users_count = len(group.users)
        get_params = {"foo": "bar", "baz": "xxx"}

        paginator = GroupService.get_user_paginator(
            group, 1, users_count, GET_params=get_params
        )

        assert paginator.page == 1
        assert paginator.first_item == 1
        assert paginator.last_item == 2
        assert paginator.items == [user1, user2]
        assert paginator.items == [user1, user2]
        assert paginator.items == [user1, user2]
        assert paginator.items == [user1, user2]
Exemple #29
0
 def test_resources_with_group_permission(self, db_session):
     created_user = add_user(db_session)
     resource = add_resource(db_session, 1, "test_resource")
     resource2 = add_resource(db_session, 2, "test_resource2")
     add_resource(db_session, 3, "test_resource3")
     group = add_group(db_session)
     group.users.append(created_user)
     group_permission = GroupResourcePermission(
         perm_name="test_perm",
         group_id=1,
         resource_id=resource.resource_id)
     group_permission2 = GroupResourcePermission(
         perm_name="foo_perm",
         group_id=1,
         resource_id=resource2.resource_id)
     resource.group_permissions.append(group_permission)
     resource2.group_permissions.append(group_permission2)
     db_session.flush()
     resources = UserService.resources_with_perms(
         created_user, ["foo_perm"], db_session=db_session).all()
     assert resources[0] == resource2
Exemple #30
0
 def test_resources_with_group_permission(self, db_session):
     created_user = add_user(db_session)
     resource = add_resource(db_session, 1, 'test_resource')
     resource2 = add_resource(db_session, 2, 'test_resource2')
     add_resource(db_session, 3, 'test_resource3')
     group = add_group(db_session, )
     group.users.append(created_user)
     group_permission = GroupResourcePermission(
         perm_name='test_perm',
         group_id=1,
         resource_id=resource.resource_id)
     group_permission2 = GroupResourcePermission(
         perm_name='foo_perm',
         group_id=1,
         resource_id=resource2.resource_id)
     resource.group_permissions.append(group_permission)
     resource2.group_permissions.append(group_permission2)
     db_session.flush()
     resources = created_user.resources_with_perms(
         ['foo_perm'], db_session=db_session).all()
     assert resources[0] == resource2
    def test_resource_users_for_any_perm_limited_group_perms_empty_group(
            self, db_session):
        self.maxDiff = 99999
        self.set_up_user_group_and_perms(db_session)
        user6 = add_user(db_session, 6, 'user 6')
        user7 = add_user(db_session, 7, 'user 7')
        perm2 = GroupResourcePermission(
            perm_name='group_perm2',
            resource_id=self.resource.resource_id
        )
        self.group.resource_permissions.append(perm2)
        self.group.users.append(user6)
        self.group.users.append(user7)
        group3 = add_group(db_session, 'Empty group')
        perm3 = GroupResourcePermission(
            perm_name='group_permx',
            resource_id=self.resource.resource_id
        )
        group3.resource_permissions.append(perm3)

        perms = self.resource.users_for_perm(
            '__any_permission__', limit_group_permissions=True,
            db_session=db_session)

        second = [
            PermissionTuple(None, 'group_perm', 'group', self.group,
                            self.resource, False, True),
            PermissionTuple(None, 'group_perm2', 'group', self.group,
                            self.resource, False, True),
            PermissionTuple(self.user, 'test_perm2', 'user', None,
                            self.resource, False, True),
            PermissionTuple(self.user, 'foo_perm', 'user', None,
                            self.resource, False, True),
            PermissionTuple(None, 'group_perm', 'group', self.group2,
                            self.resource, False, True),
            PermissionTuple(None, 'group_permx', 'group', group3,
                            self.resource, False, True),
        ]

        check_one_in_other(perms, second)
    def test_resource_users_limited_group_ownage(self, db_session):
        self.maxDiff = 9999
        self.set_up_user_group_and_perms(db_session)
        resource = TestResourceB(
            resource_id=99, resource_name="other", owner_user_id=self.user2.id
        )
        group3 = add_group(db_session, "group 3")
        user2_permission = UserResourcePermission(
            perm_name="foo_perm", user_id=self.user2.id
        )
        group3_permission = GroupResourcePermission(
            perm_name="group_perm", group_id=group3.id
        )
        resource.group_permissions.append(group3_permission)
        resource.user_permissions.append(user2_permission)
        group3.users.append(self.user3)
        self.user.resources.append(resource)
        self.group2.resources.append(resource)
        db_session.flush()
        perms = ResourceService.users_for_perm(
            resource, "__any_permission__", db_session=db_session
        )
        second = [
            PermissionTuple(
                self.user2, "foo_perm", "user", None, resource, False, True
            ),
            PermissionTuple(
                self.user, ALL_PERMISSIONS, "user", None, resource, True, True
            ),
            PermissionTuple(
                self.user4, ALL_PERMISSIONS, "group", self.group2, resource, True, True
            ),
            PermissionTuple(
                self.user3, "group_perm", "group", group3, resource, False, True
            ),
        ]

        check_one_in_other(perms, second)
 def test_resources_with_group_permission(self, db_session):
     created_user = add_user(db_session)
     resource = add_resource(db_session, 1, 'test_resource')
     resource2 = add_resource(db_session, 2, 'test_resource2')
     add_resource(db_session, 3, 'test_resource3')
     group = add_group(db_session, )
     group.users.append(created_user)
     group_permission = GroupResourcePermission(
         perm_name='test_perm',
         group_id=1,
         resource_id=resource.resource_id
     )
     group_permission2 = GroupResourcePermission(
         perm_name='foo_perm',
         group_id=1,
         resource_id=resource2.resource_id
     )
     resource.group_permissions.append(group_permission)
     resource2.group_permissions.append(group_permission2)
     db_session.flush()
     resources = created_user.resources_with_perms(['foo_perm'],
                                                   db_session=db_session).all()
     assert resources[0] == resource2
    def test_by_group_name(self, db_session):
        added_group = add_group(db_session, )
        queried_group = Group.by_group_name('group',
                                            db_session=db_session)

        assert added_group == queried_group
    def test_by_group_name_wrong_groupname(self, db_session):
        add_group(db_session, )
        queried_group = Group.by_group_name('not existing group',
                                            db_session=db_session)

        assert queried_group is None
 def test_by_group_and_perm_wrong_perm(self, db_session):
     add_group(db_session, )
     queried = GroupPermission.by_group_and_perm(1, 'wrong_perm',
                                                 db_session=db_session)
     assert queried is None
Exemple #37
0
 def test_by_group_and_perm_wrong_group(self, db_session):
     add_group(db_session)
     queried = GroupPermissionService.by_group_and_perm(
         2, "manage_apps", db_session=db_session)
     assert queried is None
Exemple #38
0
 def test_by_group_and_perm_wrong_group(self, db_session):
     add_group(db_session, )
     queried = GroupPermission.by_group_and_perm(2,
                                                 'manage_apps',
                                                 db_session=db_session)
     assert queried is None
 def test_by_group_and_perm_wrong_perm(self, db_session):
     add_group(db_session)
     queried = GroupPermissionService.by_group_and_perm(
         1, "wrong_perm", db_session=db_session
     )
     assert queried is None
Exemple #40
0
    def test_by_group_name(self, db_session):
        added_group = add_group(db_session)
        queried_group = GroupService.by_group_name("group", db_session=db_session)

        assert added_group == queried_group
Exemple #41
0
 def test_get(self, db_session):
     group1 = add_group(db_session, "group1")
     group = GroupService.get(group_id=group1.id, db_session=db_session)
     assert group.id == group1.id
Exemple #42
0
 def test_by_group_and_perm_wrong_perm(self, db_session):
     add_group(db_session)
     queried = GroupPermissionService.by_group_and_perm(
         1, "wrong_perm", db_session=db_session)
     assert queried is None
    def test_by_group_name_wrong_groupname(self, db_session):
        add_group(db_session, )
        queried_group = Group.by_group_name('not existing group',
                                            db_session=db_session)

        assert queried_group is None
Exemple #44
0
 def test_group_repr(self, db_session):
     group = add_group(db_session)
     assert repr(group) == "<Group: group, 1>"
    def test_by_group_name(self, db_session):
        added_group = add_group(db_session, )
        queried_group = Group.by_group_name('group',
                                            db_session=db_session)

        assert added_group == queried_group
 def test_by_group_and_perm(self, db_session):
     add_group(db_session, )
     queried = GroupPermission.by_group_and_perm(1, 'manage_apps',
                                                 db_session=db_session)
     assert queried.group_id == 1
     assert queried.perm_name == 'manage_apps'
 def test_by_group_and_perm_wrong_group(self, db_session):
     add_group(db_session)
     queried = GroupPermissionService.by_group_and_perm(
         2, "manage_apps", db_session=db_session
     )
     assert queried is None
 def test_by_group_and_perm_wrong_group(self, db_session):
     add_group(db_session, )
     queried = GroupPermission.by_group_and_perm(2,
                                                 'manage_apps',
                                                 db_session=db_session)
     assert queried is None
Exemple #49
0
 def test_by_group_and_perm_wrong_perm(self, db_session):
     add_group(db_session, )
     queried = GroupPermission.by_group_and_perm(1,
                                                 'wrong_perm',
                                                 db_session=db_session)
     assert queried is None
Exemple #50
0
 def test_by_group_and_perm(self, db_session):
     add_group(db_session)
     queried = GroupPermissionService.by_group_and_perm(
         1, "manage_apps", db_session=db_session)
     assert queried.group_id == 1
     assert queried.perm_name == "manage_apps"