MCPcopy Index your code
hub / github.com/encode/django-rest-framework / TestSimpleRouter

Class TestSimpleRouter

tests/test_routers.py:156–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154
155
156class TestSimpleRouter(URLPatternsTestCase, TestCase):
157 router = SimpleRouter()
158 router.register('basics', BasicViewSet, basename='basic')
159
160 urlpatterns = [
161 path('api/', include(router.urls)),
162 ]
163
164 def setUp(self):
165 self.router = SimpleRouter()
166
167 def test_action_routes(self):
168 # Get action routes (first two are list/detail)
169 routes = self.router.get_routes(BasicViewSet)[2:]
170
171 assert routes[0].url == '^{prefix}/{lookup}/action1{trailing_slash}$'
172 assert routes[0].mapping == {
173 'post': 'action1',
174 }
175
176 assert routes[1].url == '^{prefix}/{lookup}/action2{trailing_slash}$'
177 assert routes[1].mapping == {
178 'post': 'action2',
179 'delete': 'action2',
180 }
181
182 assert routes[2].url == '^{prefix}/{lookup}/action3{trailing_slash}$'
183 assert routes[2].mapping == {
184 'post': 'action3',
185 'delete': 'action3_delete',
186 }
187
188 def test_multiple_action_handlers(self):
189 # Standard action
190 response = self.client.post(reverse('basic-action3', args=[1]))
191 assert response.data == {'post': '1'}
192
193 # Additional handler registered with MethodMapper
194 response = self.client.delete(reverse('basic-action3', args=[1]))
195 assert response.data == {'delete': '1'}
196
197 def test_register_after_accessing_urls(self):
198 self.router.register(r'notes', NoteViewSet)
199 assert len(self.router.urls) == 2 # list and detail
200 self.router.register(r'notes_bis', NoteViewSet, basename='notes_bis')
201 assert len(self.router.urls) == 4
202
203
204class TestRootView(URLPatternsTestCase, TestCase):

Callers

nothing calls this directly

Calls 2

SimpleRouterClass · 0.90
registerMethod · 0.80

Tested by

no test coverage detected