【发布时间】:2021-04-01 13:00:03
【问题描述】:
所以本质上我想向 ViewSet 发出请求而不需要进行身份验证,Django APIRequestFactory 是否使这成为可能?这有效:
from django.test import TestCase
from .views.SomeViewSet
from rest_framework.test import APIRequestFactory
class ViewSetsTest(TestCase):
...
...
...
def test_db_instance_viewset(self):
api_request = APIRequestFactory.patch("", HTTP_AUTHORIZATION="Bearer xyz123ppouu")
detail_view = SomeViewSet.as_view({'patch': 'update'})
response = detail_view(api_request)
self.assertEqual(response.status_code, 200)
但问题是,不记名令牌是每 24 小时在“某处”生成的东西。因此,我想跳过身份验证。
提前谢谢你。
【问题讨论】:
标签: django authentication django-rest-framework django-unittest django-rest-viewsets