Python rest_framework.permissions 模块,DjangoObjectPermissions() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用rest_framework.permissions.DjangoObjectPermissions()

项目:django-chemtrails    作者:inonit    | 项目源码 | 文件源码
def setUp(self):
        Group.objects.bulk_create([Group(name=name) for name in ['group1', 'group2', 'group3']])

        class GroupSerializer(ModelSerializer):
            class Meta:
                model = Group
                fields = '__all__'

        class GroupViewSet(ModelViewSet):
            queryset = Group.objects.all()
            serializer_class = GroupSerializer
            permission_classes = [DjangoObjectPermissions]
            filter_backends = [ChemoPermissionsFilter]

        self.user = User.objects.create_user(username='testuser', password='test123.')
        self.perm = Permission.objects.create(content_type=get_content_type(Group),
                                              name='Can view group', codename='view_group')
        self.access_rule = AccessRule.objects.create(ctype_source=get_content_type(User),
                                                     ctype_target=get_content_type(Group),
                                                     is_active=True,
                                                     relation_types=[{'GROUPS': None}])
        self.view = GroupViewSet

        self.patched_settings = modify_settings(
            AUTHENTICATION_BACKENDS={'append': self.backend}
        )
        self.patched_settings.enable()