From 9b648184359b12c3a5f531593df9906fbf05dd5c Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Wed, 16 May 2018 08:50:58 -0400 Subject: [PATCH] Update simple router tests Removed old test logic around link/action decorators from `v2.3`. Also simplified the test by making the results explicit instead of computed. --- tests/test_routers.py | 45 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/tests/test_routers.py b/tests/test_routers.py index 36255f48f..2189d1c2b 100644 --- a/tests/test_routers.py +++ b/tests/test_routers.py @@ -103,44 +103,29 @@ class BasicViewSet(viewsets.ViewSet): def action1(self, request, *args, **kwargs): return Response({'method': 'action1'}) - @action(methods=['post'], detail=True) + @action(methods=['post', 'delete'], detail=True) def action2(self, request, *args, **kwargs): return Response({'method': 'action2'}) - @action(methods=['post', 'delete'], detail=True) - def action3(self, request, *args, **kwargs): - return Response({'method': 'action2'}) - - @action(detail=True) - def link1(self, request, *args, **kwargs): - return Response({'method': 'link1'}) - - @action(detail=True) - def link2(self, request, *args, **kwargs): - return Response({'method': 'link2'}) - class TestSimpleRouter(TestCase): def setUp(self): self.router = SimpleRouter() - def test_link_and_action_decorator(self): - routes = self.router.get_routes(BasicViewSet) - decorator_routes = routes[2:] - # Make sure all these endpoints exist and none have been clobbered - for i, endpoint in enumerate(['action1', 'action2', 'action3', 'link1', 'link2']): - route = decorator_routes[i] - # check url listing - assert route.url == '^{{prefix}}/{{lookup}}/{0}{{trailing_slash}}$'.format(endpoint) - # check method to function mapping - if endpoint == 'action3': - methods_map = ['post', 'delete'] - elif endpoint.startswith('action'): - methods_map = ['post'] - else: - methods_map = ['get'] - for method in methods_map: - assert route.mapping[method] == endpoint + def test_action_routes(self): + # Get action routes (first two are list/detail) + routes = self.router.get_routes(BasicViewSet)[2:] + + assert routes[0].url == '^{prefix}/{lookup}/action1{trailing_slash}$' + assert routes[0].mapping == { + 'post': 'action1', + } + + assert routes[1].url == '^{prefix}/{lookup}/action2{trailing_slash}$' + assert routes[1].mapping == { + 'post': 'action2', + 'delete': 'action2', + } class TestRootView(URLPatternsTestCase, TestCase):