diff options
| author | Tom Christie | 2013-05-14 11:34:47 +0100 | 
|---|---|---|
| committer | Tom Christie | 2013-05-14 11:34:47 +0100 | 
| commit | ce1a04a603cac28fc3332151623f3831ec5f4660 (patch) | |
| tree | 64199dfa68067ac5329931f49a0cda9ccfb7f03b /rest_framework/tests | |
| parent | 2cff6e69dbe3828eca56d0ce60ffdfc80fed045c (diff) | |
| parent | 5e2d8052d4bf87c81cc9807c96c933ca975cc483 (diff) | |
| download | django-rest-framework-ce1a04a603cac28fc3332151623f3831ec5f4660.tar.bz2 | |
Merge branch 'master' of https://github.com/avinash240/django-rest-framework
Diffstat (limited to 'rest_framework/tests')
| -rw-r--r-- | rest_framework/tests/routers.py | 55 | 
1 files changed, 55 insertions, 0 deletions
diff --git a/rest_framework/tests/routers.py b/rest_framework/tests/routers.py new file mode 100644 index 00000000..4e4765cb --- /dev/null +++ b/rest_framework/tests/routers.py @@ -0,0 +1,55 @@ +from __future__ import unicode_literals +from django.test import TestCase +from django.test.client import RequestFactory +from rest_framework import status +from rest_framework.response import Response +from rest_framework import viewsets +from rest_framework.decorators import link, action +from rest_framework.routers import SimpleRouter +import copy + +factory = RequestFactory() + + +class BasicViewSet(viewsets.ViewSet): +    def list(self, request, *args, **kwargs): +        return Response({'method': 'list'}) + +    @action() +    def action1(self, request, *args, **kwargs): +        return Response({'method': 'action1'}) + +    @action() +    def action2(self, request, *args, **kwargs): +        return Response({'method': 'action2'}) + +    @link() +    def link1(self, request, *args, **kwargs): +        return Response({'method': 'link1'}) + +    @link() +    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', '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' +            else: +                method_map = 'get' +            self.assertEqual(route.mapping[method_map], endpoint) + +  | 
