Django Rest Framework - How to test ViewSet?

前端 未结 5 1720
萌比男神i
萌比男神i 2021-01-31 09:24

I\'m having trouble testing a ViewSet:

class ViewSetTest(TestCase):
    def test_view_set(self):
        factory = APIRequestFactory()
        view = CatViewSet.         


        
5条回答
  •  一整个雨季
    2021-01-31 09:57

    I think it's your last line. You need to call the CatViewSet as_view(). I would go with:

    response = view(request)
    

    given that you already defined view = CatViewSet.as_view()

    EDIT:

    Can you show your views.py? Specifically, what kind of ViewSet did you use? I'm digging through the DRF code and it looks like you may not have any actions mapped to your ViewSet, which is triggering the error.

提交回复
热议问题