@@ -103,44 +103,29 @@ def list(self, request, *args, **kwargs):
103
103
def action1 (self , request , * args , ** kwargs ):
104
104
return Response ({'method' : 'action1' })
105
105
106
- @action (methods = ['post' ], detail = True )
107
- def action2 (self , request , * args , ** kwargs ):
108
- return Response ({'method' : 'action2' })
109
-
110
106
@action (methods = ['post' , 'delete' ], detail = True )
111
- def action3 (self , request , * args , ** kwargs ):
107
+ def action2 (self , request , * args , ** kwargs ):
112
108
return Response ({'method' : 'action2' })
113
109
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
-
122
110
123
111
class TestSimpleRouter (TestCase ):
124
112
def setUp (self ):
125
113
self .router = SimpleRouter ()
126
114
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
+ }
144
129
145
130
146
131
class TestRootView (URLPatternsTestCase , TestCase ):
0 commit comments