diff options
| author | Tom Christie | 2013-06-02 20:40:56 +0100 |
|---|---|---|
| committer | Tom Christie | 2013-06-02 20:40:56 +0100 |
| commit | 27d8b848bc474467fbfca29be6a9f8e22250fba0 (patch) | |
| tree | fe5f18c02be6ea4a18b5f697621fc1dab0fe68d2 /rest_framework/tests/test_routers.py | |
| parent | b15a6ccef2e13ab3310dbe856a945bba56e21c63 (diff) | |
| parent | 112b52f57e8f5a4a54e2b0c40f442ee63daf9709 (diff) | |
| download | django-rest-framework-27d8b848bc474467fbfca29be6a9f8e22250fba0.tar.bz2 | |
Add notes on 'method' argument to '@action' decorator
Diffstat (limited to 'rest_framework/tests/test_routers.py')
| -rw-r--r-- | rest_framework/tests/test_routers.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/rest_framework/tests/test_routers.py b/rest_framework/tests/test_routers.py index fc3a87e9..10d3cc25 100644 --- a/rest_framework/tests/test_routers.py +++ b/rest_framework/tests/test_routers.py @@ -25,6 +25,10 @@ class BasicViewSet(viewsets.ViewSet): def action2(self, request, *args, **kwargs): return Response({'method': 'action2'}) + @action(methods=['post', 'delete']) + def action3(self, request, *args, **kwargs): + return Response({'method': 'action2'}) + @link() def link1(self, request, *args, **kwargs): return Response({'method': 'link1'}) @@ -42,17 +46,20 @@ class TestSimpleRouter(TestCase): 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', 'link1', 'link2']): + for i, endpoint in enumerate(['action1', 'action2', 'action3', 'link1', 'link2']): route = decorator_routes[i] # check url listing self.assertEqual(route.url, '^{{prefix}}/{{lookup}}/{0}/$'.format(endpoint)) # check method to function mapping - if endpoint.startswith('action'): - method_map = 'post' + if endpoint == 'action3': + methods_map = ['post', 'delete'] + elif endpoint.startswith('action'): + methods_map = ['post'] else: - method_map = 'get' - self.assertEqual(route.mapping[method_map], endpoint) + methods_map = ['get'] + for method in methods_map: + self.assertEqual(route.mapping[method], endpoint) class RouterTestModel(models.Model): |
