我正在为一个安静的服务(使用DRF)编写测试,我想要在权限视图更改时不需要修改的测试。
例子:
view.py
class List(generics.ListAPIView): permission_classes = (IsAuthenticated, ) queryset = List.objects.all() serializer_class = ListSerializer
test.py
def test_liste(self): url = reverse('degree-list') response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
如果运行测试
OK
但如果permission_classes = (AllowAny, )
运行测试
FAILED (failures=1)
那么,当权限更改时,我如何将测试编码为无需重新编码?
谢谢