[Answered ]-How can i test django rest framework class based views

2๐Ÿ‘

โœ…

You will find this function useful(found here):

def setup_view(view, request, *args, **kwargs):
    """Mimic as_view() returned callable, but returns view instance.
    args and kwargs are the same you would pass to ``reverse()``
    """
    view.request = request
    view.args = args
    view.kwargs = kwargs
    return view

You can use it like this:

view = setup_view(
    views.DynamicStorageDownloadView(),
    django.test.RequestFactory().get('/fake-url'),
    path='dummy path')
path = view.get_path()
self.assertEqual(path, 'DUMMY PATH')
๐Ÿ‘คSebastian Wozny

0๐Ÿ‘

Looks like as_view() return function, but not an object.
Could you please try this code?

view = SnippetList.as_view()(request)
๐Ÿ‘คPaul

Leave a comment