diff options
| author | Xavier Ordoquy | 2014-05-16 01:20:40 +0200 | 
|---|---|---|
| committer | Xavier Ordoquy | 2014-05-16 01:20:40 +0200 | 
| commit | a704d5a206238c65765c1f02eb053e461675dda2 (patch) | |
| tree | 39c468b4678a2a41543779a7ff8eb7c9629f2fc2 /rest_framework | |
| parent | b370fb40b6bc0fd3f597fb8c2db59f0ca57a7ccd (diff) | |
| download | django-rest-framework-a704d5a206238c65765c1f02eb053e461675dda2.tar.bz2 | |
Fixed tests for python 3.4
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/tests/test_views.py | 16 | 
1 files changed, 11 insertions, 5 deletions
diff --git a/rest_framework/tests/test_views.py b/rest_framework/tests/test_views.py index 65c7e50e..77b113ee 100644 --- a/rest_framework/tests/test_views.py +++ b/rest_framework/tests/test_views.py @@ -1,5 +1,6 @@  from __future__ import unicode_literals +import sys  import copy  from django.test import TestCase  from rest_framework import status @@ -11,6 +12,11 @@ from rest_framework.views import APIView  factory = APIRequestFactory() +if sys.version_info[:2] >= (3, 4): +    JSON_ERROR = 'JSON parse error - Expecting value:' +else: +    JSON_ERROR = 'JSON parse error - No JSON object could be decoded' +  class BasicView(APIView):      def get(self, request, *args, **kwargs): @@ -48,7 +54,7 @@ def sanitise_json_error(error_dict):      of json.      """      ret = copy.copy(error_dict) -    chop = len('JSON parse error - No JSON object could be decoded') +    chop = len(JSON_ERROR)      ret['detail'] = ret['detail'][:chop]      return ret @@ -61,7 +67,7 @@ class ClassBasedViewIntegrationTests(TestCase):          request = factory.post('/', 'f00bar', content_type='application/json')          response = self.view(request)          expected = { -            'detail': 'JSON parse error - No JSON object could be decoded' +            'detail': JSON_ERROR          }          self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)          self.assertEqual(sanitise_json_error(response.data), expected) @@ -76,7 +82,7 @@ class ClassBasedViewIntegrationTests(TestCase):          request = factory.post('/', form_data)          response = self.view(request)          expected = { -            'detail': 'JSON parse error - No JSON object could be decoded' +            'detail': JSON_ERROR          }          self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)          self.assertEqual(sanitise_json_error(response.data), expected) @@ -90,7 +96,7 @@ class FunctionBasedViewIntegrationTests(TestCase):          request = factory.post('/', 'f00bar', content_type='application/json')          response = self.view(request)          expected = { -            'detail': 'JSON parse error - No JSON object could be decoded' +            'detail': JSON_ERROR          }          self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)          self.assertEqual(sanitise_json_error(response.data), expected) @@ -105,7 +111,7 @@ class FunctionBasedViewIntegrationTests(TestCase):          request = factory.post('/', form_data)          response = self.view(request)          expected = { -            'detail': 'JSON parse error - No JSON object could be decoded' +            'detail': JSON_ERROR          }          self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)          self.assertEqual(sanitise_json_error(response.data), expected)  | 
