Skip to content

Using ViewSet.as_view() in test results in AttributeError #2171

Closed
@tdavis

Description

@tdavis

I feel like I must be doing something stupid since this is all over the documentation, but it has never worked for me:

view = MyViewSet.as_view()
uri = reverse(...)
request = my_APIFactory.get(uri)
response = view(request)

This test (with zero-argument call to as_view()) always fails with the TB:

   def view(request, *args, **kwargs):
       self = cls(**initkwargs)
       # We also store the mapping of request methods to actions,
       # so that we can later set the action attribute.
       # eg. `self.action = 'list'` on an incoming GET request.
       self.action_map = actions

       # Bind methods to actions
       # This is the bit that's different to a standard view
>     for method, action in actions.items():
           handler = getattr(self, action)
E     AttributeError: 'NoneType' object has no attribute 'items'

eggs/djangorestframework-3.0.0-py3.4.egg/rest_framework/viewsets.py:70: AttributeError

I mean, this makes sense looking at the code: the actions argument defaults to None but gets no other value, and items() is eventually called on it. What am I missing? How can actions be optional?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions