Python rest_framework.permissions.IsAuthenticatedOrReadOnly() Examples

The following are 1 code examples of rest_framework.permissions.IsAuthenticatedOrReadOnly(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module rest_framework.permissions , or try the search function .
Example #1
Source File: test_viewsets.py    From drf-haystack with MIT License 6 votes vote down vote up
def test_viewset_get_queryset_with_IsAuthenticatedOrReadOnly_permission(self):
        from rest_framework.permissions import IsAuthenticatedOrReadOnly
        setattr(self.view, "permission_classes", (IsAuthenticatedOrReadOnly,))

        # Unauthenticated GET requests should pass
        request = factory.get(path="/", data="", content_type="application/json")
        response = self.view.as_view(actions={"get": "list"})(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Authenticated GET requests should pass
        request = factory.get(path="/", data="", content_type="application/json")
        force_authenticate(request, user=self.user)
        response = self.view.as_view(actions={"get": "list"})(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # POST, PUT, PATCH and DELETE requests are not supported, so they will
        # raise an error. No need to test the permission.