diff options
| author | Tom Christie | 2012-09-28 16:41:35 +0100 | 
|---|---|---|
| committer | Tom Christie | 2012-09-28 16:41:35 +0100 | 
| commit | 224bc027cd611cf6ec7dcb7958a675bea39eeb97 (patch) | |
| tree | e180d7ad0bfd37cf3eb0e8a611ceda1cd1f1ab4a /rest_framework/tests | |
| parent | 0853316545ad39c314f56ee559ce56596e578d2b (diff) | |
| download | django-rest-framework-224bc027cd611cf6ec7dcb7958a675bea39eeb97.tar.bz2 | |
Add more tests for generic views
Diffstat (limited to 'rest_framework/tests')
| -rw-r--r-- | rest_framework/tests/generics.py | 56 | 
1 files changed, 53 insertions, 3 deletions
diff --git a/rest_framework/tests/generics.py b/rest_framework/tests/generics.py index 0ce297e0..fee6e3a6 100644 --- a/rest_framework/tests/generics.py +++ b/rest_framework/tests/generics.py @@ -9,10 +9,16 @@ factory = RequestFactory()  class RootView(generics.RootAPIView): +    """ +    Example description for OPTIONS. +    """      model = BasicModel  class InstanceView(generics.InstanceAPIView): +    """ +    Example description for OPTIONS. +    """      model = BasicModel @@ -60,7 +66,7 @@ class TestRootView(TestCase):          request = factory.put('/', json.dumps(content), content_type='application/json')          response = self.view(request).render()          self.assertEquals(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) -        self.assertEquals(response.content, '{"detail": "Method \'PUT\' not allowed."}') +        self.assertEquals(response.data, {"detail": "Method 'PUT' not allowed."})      def test_delete_root_view(self):          """ @@ -69,7 +75,29 @@ class TestRootView(TestCase):          request = factory.delete('/')          response = self.view(request).render()          self.assertEquals(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) -        self.assertEquals(response.content, '{"detail": "Method \'DELETE\' not allowed."}') +        self.assertEquals(response.data, {"detail": "Method 'DELETE' not allowed."}) + +    def test_options_root_view(self): +        """ +        OPTIONS requests to RootAPIView should return metadata +        """ +        request = factory.options('/') +        response = self.view(request).render() +        expected = { +            'parses': [ +                'application/json', +                'application/x-www-form-urlencoded', +                'multipart/form-data' +            ], +            'renders': [ +                'application/json', +                'text/html' +            ], +            'name': 'Root', +            'description': 'Example description for OPTIONS.' +        } +        self.assertEquals(response.status_code, status.HTTP_200_OK) +        self.assertEquals(response.data, expected)  class TestInstanceView(TestCase): @@ -104,7 +132,7 @@ class TestInstanceView(TestCase):          request = factory.post('/', json.dumps(content), content_type='application/json')          response = self.view(request).render()          self.assertEquals(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) -        self.assertEquals(response.content, '{"detail": "Method \'POST\' not allowed."}') +        self.assertEquals(response.data, {"detail": "Method 'POST' not allowed."})      def test_put_instance_view(self):          """ @@ -128,3 +156,25 @@ class TestInstanceView(TestCase):          self.assertEquals(response.content, '')          ids = [obj.id for obj in self.objects.all()]          self.assertEquals(ids, [2, 3]) + +    def test_options_instance_view(self): +        """ +        OPTIONS requests to InstanceAPIView should return metadata +        """ +        request = factory.options('/') +        response = self.view(request).render() +        expected = { +            'parses': [ +                'application/json', +                'application/x-www-form-urlencoded', +                'multipart/form-data' +            ], +            'renders': [ +                'application/json', +                'text/html' +            ], +            'name': 'Instance', +            'description': 'Example description for OPTIONS.' +        } +        self.assertEquals(response.status_code, status.HTTP_200_OK) +        self.assertEquals(response.data, expected)  | 
