Skip to content

Commit

Permalink
fix tests/test_dynamic_routers.py (deprecation of list_route/detail_r…
Browse files Browse the repository at this point in the history
…oute)
  • Loading branch information
buko106 committed Sep 11, 2019
1 parent a3107da commit ad97833
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions tests/test_dynamic_routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,25 @@ class Meta:
app_label = 'testapp'


# DRF 3.8+
try:
from rest_framework.decorators import detail_route, list_route
from rest_framework.decorators import action

def detail_route_decorator(**kwargs):
return action(detail=True, **kwargs)

def list_route_decorator(**kwargs):
return action(detail=False, **kwargs)
except ImportError:
pass
else:

# for DRF < 3.8
try:
from rest_framework.decorators import detail_route as detail_route_decorator, list_route as list_route_decorator
except ImportError:
pass

if 'detail_route_decorator' in globals() and 'list_route_decorator' in globals():
def map_by_name(iterable):
ret = {}
for item in iterable:
Expand All @@ -37,15 +51,15 @@ class DetailRouteViewSet(ModelViewSet):
model = BasicModel
queryset = QS(BasicModel)

@detail_route(methods=["post"])
@detail_route_decorator(methods=["post"])
def set_password(self, request, pk=None):
return Response({'hello': 'ok'})

class ListRouteViewSet(ModelViewSet):
model = BasicModel
queryset = QS(BasicModel)

@list_route()
@list_route_decorator()
def recent_users(self, request, pk=None):
return Response([{'hello': 'ok'}])

Expand Down

0 comments on commit ad97833

Please sign in to comment.