Django Rest Framework - How to test ViewSet?

前端 未结 5 1717
萌比男神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:55

    I found a way to do this without needing to manually create the right viewset and give it an action mapping:

    from django.core.urlresolvers import reverse, resolve
    ...
    url = reverse('cat-list')
    req = factory.get(url)
    view = resolve(url).func
    response = view(req)
    response.render()
    

提交回复
热议问题