當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。