本文整理汇总了Python中rest_framework.permissions.IsAuthenticatedOrReadOnly方法的典型用法代码示例。如果您正苦于以下问题:Python permissions.IsAuthenticatedOrReadOnly方法的具体用法?Python permissions.IsAuthenticatedOrReadOnly怎么用?Python permissions.IsAuthenticatedOrReadOnly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest_framework.permissions
的用法示例。
在下文中一共展示了permissions.IsAuthenticatedOrReadOnly方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_viewset_get_queryset_with_IsAuthenticatedOrReadOnly_permission
# 需要导入模块: from rest_framework import permissions [as 别名]
# 或者: from rest_framework.permissions import IsAuthenticatedOrReadOnly [as 别名]
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.