当前位置: 首页>>代码示例>>Python>>正文


Python status.HTTP_403_FORBIDDEN属性代码示例

本文整理汇总了Python中rest_framework.status.HTTP_403_FORBIDDEN属性的典型用法代码示例。如果您正苦于以下问题:Python status.HTTP_403_FORBIDDEN属性的具体用法?Python status.HTTP_403_FORBIDDEN怎么用?Python status.HTTP_403_FORBIDDEN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在rest_framework.status的用法示例。


在下文中一共展示了status.HTTP_403_FORBIDDEN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_user

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_403_FORBIDDEN [as 别名]
def add_user(self, request, pk=None):
        group = self.get_object()

        if not request.data.get("user_id"):
            return Response(
                {"user_id": "This field is required."}, status=status.HTTP_400_BAD_REQUEST
            )

        try:
            user = User.objects.get(pk=request.data.get("user_id"))
        except User.DoesNotExist:
            return Response({"user_id": "Invalid user ID."}, status=status.HTTP_400_BAD_REQUEST)

        if request.user == user:
            return Response(status=status.HTTP_403_FORBIDDEN)

        user.groups.add(group)

        return Response(status=status.HTTP_204_NO_CONTENT) 
开发者ID:mozilla,项目名称:normandy,代码行数:21,代码来源:views.py

示例2: approve

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_403_FORBIDDEN [as 别名]
def approve(self, request, pk=None):
        approval_request = self.get_object()

        if not request.data.get("comment"):
            return Response(
                {"comment": "This field is required."}, status=status.HTTP_400_BAD_REQUEST
            )

        try:
            approval_request.approve(approver=request.user, comment=request.data.get("comment"))
        except ApprovalRequest.NotActionable:
            return Response(
                {"error": "This approval request has already been approved or rejected."},
                status=status.HTTP_400_BAD_REQUEST,
            )
        except ApprovalRequest.CannotActOnOwnRequest:
            return Response(
                {"error": "You cannot approve your own approval request."},
                status=status.HTTP_403_FORBIDDEN,
            )

        return Response(ApprovalRequestSerializer(approval_request).data) 
开发者ID:mozilla,项目名称:normandy,代码行数:24,代码来源:views.py

示例3: reject

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_403_FORBIDDEN [as 别名]
def reject(self, request, pk=None):
        approval_request = self.get_object()

        if not request.data.get("comment"):
            return Response(
                {"comment": "This field is required."}, status=status.HTTP_400_BAD_REQUEST
            )

        try:
            approval_request.reject(approver=request.user, comment=request.data.get("comment"))
        except ApprovalRequest.NotActionable:
            return Response(
                {"error": "This approval request has already been approved or rejected."},
                status=status.HTTP_400_BAD_REQUEST,
            )
        except ApprovalRequest.CannotActOnOwnRequest:
            return Response(
                {"error": "You cannot reject your own approval request."},
                status=status.HTTP_403_FORBIDDEN,
            )

        return Response(ApprovalRequestSerializer(approval_request).data) 
开发者ID:mozilla,项目名称:normandy,代码行数:24,代码来源:views.py

示例4: test_public_user

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_403_FORBIDDEN [as 别名]
def test_public_user(self):
        """Public user cannot create/edit anything"""
        assign_perm("view_collection", self.user1, self.collection)
        assign_perm("share_collection", self.user1, self.collection)

        data = {"public": {"add": ["view"]}}
        resp = self._detail_permissions(self.collection.pk, data, self.user1)
        self.assertEqual(resp.status_code, status.HTTP_200_OK)

        data = {"public": {"add": ["edit"]}}
        resp = self._detail_permissions(self.collection.pk, data, self.user1)
        self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)

        data = {"public": {"remove": ["edit"]}}
        resp = self._detail_permissions(self.collection.pk, data, self.user1)
        self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN) 
开发者ID:genialis,项目名称:resolwe,代码行数:18,代码来源:test_permissions.py

示例5: test_token_register_api

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_403_FORBIDDEN [as 别名]
def test_token_register_api(self):
        url = api_reverse('api-auth:login')
        data = {
            'username': 'cfe',
            'password': 'yeahhhcfe',
        }
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK) # 400
        token = response.data.get("token", None)
        self.client.credentials(HTTP_AUTHORIZATION='JWT ' + token)

        url2 = api_reverse('api-auth:register')
        data2 = {
            'username': 'cfe.doe',
            'email': 'cfe.doe@gmail.com',
            'password': 'learncode',
            'password2': 'learncode'
        }
        response = self.client.post(url2, data2, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) # 403 
开发者ID:codingforentrepreneurs,项目名称:REST-API,代码行数:22,代码来源:tests.py

示例6: test_other_user_permissions_api

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_403_FORBIDDEN [as 别名]
def test_other_user_permissions_api(self):
        data            = self.create_item()
        data_id         = data.get("id")
        user            = User.objects.create(username='testjmitch')
        payload         = jwt_payload_handler(user)
        token           = jwt_encode_handler(payload)
        self.client.credentials(HTTP_AUTHORIZATION='JWT ' + token)
        rud_url         = api_reverse('api-status:detail', kwargs={"id": data_id})
        rud_data        = {
                            'content': "smashing"
                        }
        get_            = self.client.get(rud_url, format='json')
        put_            = self.client.put(rud_url, rud_data, format='json')
        delete_         = self.client.delete(rud_url, format='json')
        self.assertEqual(get_.status_code, status.HTTP_200_OK)
        self.assertEqual(put_.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(delete_.status_code, status.HTTP_403_FORBIDDEN) 
开发者ID:codingforentrepreneurs,项目名称:REST-API,代码行数:19,代码来源:tests.py

示例7: test_regular_user_bulk_create

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_403_FORBIDDEN [as 别名]
def test_regular_user_bulk_create(self):
        self.org_1.regular_users.add(self.user)
        url = reverse('event-list')
        location_id = reverse('place-detail', kwargs={'pk': self.place.id})
        data_1 = self.make_complex_event_dict(self.system_data_source, self.org_1, location_id, self.languages)
        data_1['name']['fi'] = 'event-data-1'
        data_1['publication_status'] = 'public'
        data_2 = deepcopy(data_1)
        data_2['name']['fi'] = 'event-data-2'
        data_2['publication_status'] = 'draft'

        self.client.force_authenticate(self.user)
        response = self.client.post(url, [data_1, data_2], format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # test creating multiple draft events
        data_1['publication_status'] = 'draft'
        self.client.force_authenticate(self.user)
        response = self.client.post(url, [data_1, data_2], format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        qs = Event.objects.filter(name_fi__in=['event-data-1', 'event-data-2'])
        self.assertEqual(qs.count(), 2) 
开发者ID:City-of-Helsinki,项目名称:linkedevents,代码行数:24,代码来源:test_event_auth_api.py

示例8: test_cannot_get_conversation_as_nonmember

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_403_FORBIDDEN [as 别名]
def test_cannot_get_conversation_as_nonmember(self):
        self.client.force_login(user=self.user)

        # cannot get via activity
        response = self.client.get(self.conversation_url)
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

        # cannot get via conversation info
        conversation_id = self.activity.conversation.id
        response = self.client.get('/api/conversations/{}/'.format(conversation_id))
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

        # cannot write a message
        conversation_id = self.activity.conversation.id
        response = self.client.post('/api/messages/', {
            'conversation': conversation_id,
            'content': 'hey',
        })
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN, response.data)
        self.assertEqual(response.data['detail'], 'You are not in this conversation') 
开发者ID:yunity,项目名称:karrot-backend,代码行数:22,代码来源:test_activities_api.py

示例9: destroy

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_403_FORBIDDEN [as 别名]
def destroy(self, request, *args, **kwargs):
        instance = self.get_object()

        # Should not be able to delete self
        if request.user == instance:
            return Response(status=status.HTTP_403_FORBIDDEN)

        return super().destroy(request, *args, **kwargs) 
开发者ID:mozilla,项目名称:normandy,代码行数:10,代码来源:views.py

示例10: test_not_logged_in

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_403_FORBIDDEN [as 别名]
def test_not_logged_in(self):
        request = self.create_post_request()
        self.add_session_to_request(request)
        response = self.view_func(request)
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) 
开发者ID:apragacz,项目名称:django-rest-registration,代码行数:7,代码来源:test_logout.py

示例11: test_forbidden

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_403_FORBIDDEN [as 别名]
def test_forbidden(self):
        request = self.create_post_request({})
        response = self.view_func(request)
        self.assert_invalid_response(response, status.HTTP_403_FORBIDDEN) 
开发者ID:apragacz,项目名称:django-rest-registration,代码行数:6,代码来源:test_change_password.py

示例12: test_patch_public_user

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_403_FORBIDDEN [as 别名]
def test_patch_public_user(self):
        data = {"name": "New collection"}
        resp = self._patch(3, data)
        self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
        p = Collection.objects.get(pk=3)
        self.assertEqual(p.name, "Test collection 3") 
开发者ID:genialis,项目名称:resolwe,代码行数:8,代码来源:test_collection.py

示例13: test_delete_public_user

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_403_FORBIDDEN [as 别名]
def test_delete_public_user(self):
        resp = self._delete(3)
        self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
        collection_exists = Collection.objects.filter(pk=3).exists()
        self.assertTrue(collection_exists) 
开发者ID:genialis,项目名称:resolwe,代码行数:7,代码来源:test_collection.py

示例14: test_post_no_perms

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_403_FORBIDDEN [as 别名]
def test_post_no_perms(self):
        collection = Collection.objects.get(pk=1)
        remove_perm("edit_collection", self.user2, collection)

        data_count = Data.objects.count()
        resp = self._post(self.data, self.user2)
        self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(Data.objects.count(), data_count) 
开发者ID:genialis,项目名称:resolwe,代码行数:10,代码来源:test_data.py

示例15: test_post_public_user

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_403_FORBIDDEN [as 别名]
def test_post_public_user(self):
        data_count = Data.objects.count()
        resp = self._post(self.data)
        # User has no permission to add Data object to the collection.
        self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(Data.objects.count(), data_count) 
开发者ID:genialis,项目名称:resolwe,代码行数:8,代码来源:test_data.py


注:本文中的rest_framework.status.HTTP_403_FORBIDDEN属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。