def test_resources_with_perm_type_other_found(self, db_session): created_user = add_user(db_session) resource = add_resource(db_session, 1, 'test_resource') resource2 = add_resource_b(db_session, 2, 'test_resource') resource3 = add_resource(db_session, 3, 'test_resource') resource4 = add_resource_b(db_session, 4, 'test_resource') db_session.flush() permission = UserResourcePermission(perm_name='test_perm', user_id=created_user.id, resource_id=resource.resource_id) resource.user_permissions.append(permission) permission2 = UserResourcePermission(perm_name='test_perm', user_id=created_user.id, resource_id=resource2.resource_id) resource2.user_permissions.append(permission2) permission3 = UserResourcePermission(perm_name='test_perm', user_id=created_user.id, resource_id=resource3.resource_id) resource3.user_permissions.append(permission3) permission4 = UserResourcePermission(perm_name='test_perm', user_id=created_user.id, resource_id=resource4.resource_id) resource4.user_permissions.append(permission4) db_session.flush() resources = created_user.resources_with_perms( ['test_perm'], resource_types=['test_resource_b'], db_session=db_session).all() assert len(resources) == 2
def test_resources_with_perm_type_other_found(self, db_session): created_user = add_user(db_session) resource = add_resource(db_session, 1, 'test_resource') resource2 = add_resource_b(db_session, 2, 'test_resource') resource3 = add_resource(db_session, 3, 'test_resource') resource4 = add_resource_b(db_session, 4, 'test_resource') db_session.flush() permission = UserResourcePermission(perm_name='test_perm', user_id=created_user.id, resource_id=resource.resource_id) resource.user_permissions.append(permission) permission2 = UserResourcePermission(perm_name='test_perm', user_id=created_user.id, resource_id=resource2.resource_id) resource2.user_permissions.append(permission2) permission3 = UserResourcePermission(perm_name='test_perm', user_id=created_user.id, resource_id=resource3.resource_id) resource3.user_permissions.append(permission3) permission4 = UserResourcePermission(perm_name='test_perm', user_id=created_user.id, resource_id=resource4.resource_id) resource4.user_permissions.append(permission4) db_session.flush() resources = created_user.resources_with_perms(['test_perm'], resource_types=[ 'test_resource_b'], db_session=db_session).all() assert len(resources) == 2
def test_mixed_perms(self, db_session): created_user = add_user(db_session) resource = add_resource(db_session, 1, "test_resource") permission = UserResourcePermission( perm_name="test_perm", user_id=created_user.id, resource_id=resource.resource_id, ) resource.user_permissions.append(permission) resource2 = add_resource(db_session, 2, "test_resource") created_user.resources.append(resource2) add_resource(db_session, 3, "test_resource") add_resource_b(db_session, 4, "test_resource") db_session.flush() resources = UserService.resources_with_perms( created_user, ["test_perm"], db_session=db_session).all() found_ids = [r.resource_id for r in resources] assert sorted(found_ids) == [1, 2]
def test_mixed_perms(self, db_session): created_user = add_user(db_session) resource = add_resource(db_session, 1, "test_resource") permission = UserResourcePermission( perm_name="test_perm", user_id=created_user.id, resource_id=resource.resource_id, ) resource.user_permissions.append(permission) resource2 = add_resource(db_session, 2, "test_resource") created_user.resources.append(resource2) add_resource(db_session, 3, "test_resource") add_resource_b(db_session, 4, "test_resource") db_session.flush() resources = UserService.resources_with_perms( created_user, ["test_perm"], db_session=db_session ).all() found_ids = [r.resource_id for r in resources] assert sorted(found_ids) == [1, 2]
def test_group_resource_permission(self, db_session): self.set_up_user_group_and_perms(db_session) add_resource_b(db_session, 3, "other resource") db_session.flush() group_permission2 = GroupResourcePermission(perm_name="group_perm2", group_id=self.group2.id) row = GroupResourcePermissionService.get( group_id=self.group2.id, resource_id=self.resource2.resource_id, perm_name="group_perm2", db_session=db_session, ) assert row is None self.resource2.group_permissions.append(group_permission2) row = GroupResourcePermissionService.get( group_id=self.group2.id, resource_id=self.resource2.resource_id, perm_name="group_perm2", db_session=db_session, ) assert row is not None
def test_resources_with_perm_type_other_found(self, db_session): created_user = add_user(db_session) resource = add_resource(db_session, 1, "test_resource") resource2 = add_resource_b(db_session, 2, "test_resource") resource3 = add_resource(db_session, 3, "test_resource") resource4 = add_resource_b(db_session, 4, "test_resource") db_session.flush() permission = UserResourcePermission( perm_name="test_perm", user_id=created_user.id, resource_id=resource.resource_id, ) resource.user_permissions.append(permission) permission2 = UserResourcePermission( perm_name="test_perm", user_id=created_user.id, resource_id=resource2.resource_id, ) resource2.user_permissions.append(permission2) permission3 = UserResourcePermission( perm_name="test_perm", user_id=created_user.id, resource_id=resource3.resource_id, ) resource3.user_permissions.append(permission3) permission4 = UserResourcePermission( perm_name="test_perm", user_id=created_user.id, resource_id=resource4.resource_id, ) resource4.user_permissions.append(permission4) db_session.flush() resources = UserService.resources_with_perms( created_user, ["test_perm"], resource_types=["test_resource_b"], db_session=db_session, ).all() assert len(resources) == 2
def test_group_resource_permission(self, db_session): self.set_up_user_group_and_perms(db_session) add_resource_b(db_session, 3, "other resource") db_session.flush() group_permission2 = GroupResourcePermission( perm_name="group_perm2", group_id=self.group2.id ) row = GroupResourcePermissionService.get( group_id=self.group2.id, resource_id=self.resource2.resource_id, perm_name="group_perm2", db_session=db_session, ) assert row is None self.resource2.group_permissions.append(group_permission2) row = GroupResourcePermissionService.get( group_id=self.group2.id, resource_id=self.resource2.resource_id, perm_name="group_perm2", db_session=db_session, ) assert row is not None
def test_resources_with_perm_type_other_found(self, db_session): created_user = add_user(db_session) resource = add_resource(db_session, 1, "test_resource") resource2 = add_resource_b(db_session, 2, "test_resource") resource3 = add_resource(db_session, 3, "test_resource") resource4 = add_resource_b(db_session, 4, "test_resource") db_session.flush() permission = UserResourcePermission( perm_name="test_perm", user_id=created_user.id, resource_id=resource.resource_id, ) resource.user_permissions.append(permission) permission2 = UserResourcePermission( perm_name="test_perm", user_id=created_user.id, resource_id=resource2.resource_id, ) resource2.user_permissions.append(permission2) permission3 = UserResourcePermission( perm_name="test_perm", user_id=created_user.id, resource_id=resource3.resource_id, ) resource3.user_permissions.append(permission3) permission4 = UserResourcePermission( perm_name="test_perm", user_id=created_user.id, resource_id=resource4.resource_id, ) resource4.user_permissions.append(permission4) db_session.flush() resources = UserService.resources_with_perms( created_user, ["test_perm"], resource_types=["test_resource_b"], db_session=db_session, ).all() assert len(resources) == 2
def test_mixed_perms(self, db_session): created_user = add_user(db_session) resource = add_resource(db_session, 1, 'test_resource') permission = UserResourcePermission(perm_name='test_perm', user_id=created_user.id, resource_id=resource.resource_id) resource.user_permissions.append(permission) resource2 = add_resource(db_session, 2, 'test_resource') created_user.resources.append(resource2) resource3 = add_resource(db_session, 3, 'test_resource') resource4 = add_resource_b(db_session, 4, 'test_resource') db_session.flush() resources = created_user.resources_with_perms( ['test_perm'], db_session=db_session).all() found_ids = [r.resource_id for r in resources] assert sorted(found_ids) == [1, 2]
def test_mixed_perms(self, db_session): created_user = add_user(db_session) resource = add_resource(db_session, 1, 'test_resource') permission = UserResourcePermission( perm_name='test_perm', user_id=created_user.id, resource_id=resource.resource_id) resource.user_permissions.append(permission) resource2 = add_resource(db_session, 2, 'test_resource') created_user.resources.append(resource2) resource3 = add_resource(db_session, 3, 'test_resource') resource4 = add_resource_b(db_session, 4, 'test_resource') db_session.flush() resources = created_user.resources_with_perms(['test_perm'], db_session=db_session).all() found_ids = [r.resource_id for r in resources] assert sorted(found_ids) == [1, 2]
def test_resources_with_possible_perms_group2(self, db_session): self.set_up_user_group_and_perms(db_session) resource3 = add_resource_b(db_session, 3, "other resource") self.group2.resources.append(resource3) group_permission2 = GroupResourcePermission(perm_name="group_perm2", group_id=self.group2.id) self.resource2.group_permissions.append(group_permission2) perms = GroupService.resources_with_possible_perms(self.group2) second = [ PermissionTuple(None, "group_perm", "group", self.group2, self.resource, False, True), PermissionTuple(None, "group_perm2", "group", self.group2, self.resource2, False, True), PermissionTuple(None, ALL_PERMISSIONS, "group", self.group2, resource3, True, True), ] check_one_in_other(perms, second)
def test_resources_with_possible_perms_group2(self, db_session): self.set_up_user_group_and_perms(db_session) resource3 = add_resource_b(db_session, 3, 'other resource') self.group2.resources.append(resource3) group_permission2 = GroupResourcePermission( perm_name='group_perm2', group_id=self.group2.id, ) self.resource2.group_permissions.append(group_permission2) perms = self.group2.resources_with_possible_perms() second = [PermissionTuple(None, 'group_perm', 'group', self.group2, self.resource, False, True), PermissionTuple(None, 'group_perm2', 'group', self.group2, self.resource2, False, True), PermissionTuple(None, ALL_PERMISSIONS, 'group', self.group2, resource3, True, True), ] check_one_in_other(perms, second)
def test_resources_with_possible_perms_group2(self, db_session): self.set_up_user_group_and_perms(db_session) resource3 = add_resource_b(db_session, 3, 'other resource') self.group2.resources.append(resource3) group_permission2 = GroupResourcePermission( perm_name='group_perm2', group_id=self.group2.id, ) self.resource2.group_permissions.append(group_permission2) perms = self.group2.resources_with_possible_perms() second = [ PermissionTuple(None, 'group_perm', 'group', self.group2, self.resource, False, True), PermissionTuple(None, 'group_perm2', 'group', self.group2, self.resource2, False, True), PermissionTuple(None, ALL_PERMISSIONS, 'group', self.group2, resource3, True, True), ] check_one_in_other(perms, second)
def test_resources_with_possible_perms_group2(self, db_session): self.set_up_user_group_and_perms(db_session) resource3 = add_resource_b(db_session, 3, "other resource") self.group2.resources.append(resource3) group_permission2 = GroupResourcePermission( perm_name="group_perm2", group_id=self.group2.id ) self.resource2.group_permissions.append(group_permission2) perms = GroupService.resources_with_possible_perms(self.group2) second = [ PermissionTuple( None, "group_perm", "group", self.group2, self.resource, False, True ), PermissionTuple( None, "group_perm2", "group", self.group2, self.resource2, False, True ), PermissionTuple( None, ALL_PERMISSIONS, "group", self.group2, resource3, True, True ), ] check_one_in_other(perms, second)