Skip to content

Commit 21a2035

Browse files
author
Ryan P Kilby
committed
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.
1 parent 1afd568 commit 21a2035

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

tests/test_routers.py

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -103,44 +103,29 @@ def list(self, request, *args, **kwargs):
103103
def action1(self, request, *args, **kwargs):
104104
return Response({'method': 'action1'})
105105

106-
@action(methods=['post'], detail=True)
107-
def action2(self, request, *args, **kwargs):
108-
return Response({'method': 'action2'})
109-
110106
@action(methods=['post', 'delete'], detail=True)
111-
def action3(self, request, *args, **kwargs):
107+
def action2(self, request, *args, **kwargs):
112108
return Response({'method': 'action2'})
113109

114-
@action(detail=True)
115-
def link1(self, request, *args, **kwargs):
116-
return Response({'method': 'link1'})
117-
118-
@action(detail=True)
119-
def link2(self, request, *args, **kwargs):
120-
return Response({'method': 'link2'})
121-
122110

123111
class TestSimpleRouter(TestCase):
124112
def setUp(self):
125113
self.router = SimpleRouter()
126114

127-
def test_link_and_action_decorator(self):
128-
routes = self.router.get_routes(BasicViewSet)
129-
decorator_routes = routes[2:]
130-
# Make sure all these endpoints exist and none have been clobbered
131-
for i, endpoint in enumerate(['action1', 'action2', 'action3', 'link1', 'link2']):
132-
route = decorator_routes[i]
133-
# check url listing
134-
assert route.url == '^{{prefix}}/{{lookup}}/{0}{{trailing_slash}}$'.format(endpoint)
135-
# check method to function mapping
136-
if endpoint == 'action3':
137-
methods_map = ['post', 'delete']
138-
elif endpoint.startswith('action'):
139-
methods_map = ['post']
140-
else:
141-
methods_map = ['get']
142-
for method in methods_map:
143-
assert route.mapping[method] == endpoint
115+
def test_action_routes(self):
116+
# Get action routes (first two are list/detail)
117+
routes = self.router.get_routes(BasicViewSet)[2:]
118+
119+
assert routes[0].url == '^{prefix}/{lookup}/action1{trailing_slash}$'
120+
assert routes[0].mapping == {
121+
'post': 'action1',
122+
}
123+
124+
assert routes[1].url == '^{prefix}/{lookup}/action2{trailing_slash}$'
125+
assert routes[1].mapping == {
126+
'post': 'action2',
127+
'delete': 'action2',
128+
}
144129

145130

146131
class TestRootView(URLPatternsTestCase, TestCase):

0 commit comments

Comments
 (0)