summaryrefslogtreecommitdiff
path: root/tests/regressiontests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-04-29 19:58:00 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-04-29 19:58:00 +0200
commitcec6bd5a59547dc97fe98975c570fc27a1e970be (patch)
treed084ff2008e4bba125c4b28297d6469992f2ec95 /tests/regressiontests
parentee0a7c741e98214bac7eeb60b848cf099ff28836 (diff)
Fixed #18023 -- Removed bundled simplejson.
And started the deprecation path for django.utils.simplejson. Thanks Alex Ogier, Clueless, and other contributors for their work on the patch.
Diffstat (limited to 'tests/regressiontests')
-rw-r--r--tests/regressiontests/file_uploads/tests.py19
-rw-r--r--tests/regressiontests/file_uploads/views.py8
-rw-r--r--tests/regressiontests/test_client_regress/views.py6
-rw-r--r--tests/regressiontests/test_utils/tests.py4
4 files changed, 19 insertions, 18 deletions
diff --git a/tests/regressiontests/file_uploads/tests.py b/tests/regressiontests/file_uploads/tests.py
index ffa2017a5e..b6191ba033 100644
--- a/tests/regressiontests/file_uploads/tests.py
+++ b/tests/regressiontests/file_uploads/tests.py
@@ -5,6 +5,7 @@ from __future__ import absolute_import
import base64
import errno
import hashlib
+import json
import os
import shutil
from StringIO import StringIO
@@ -13,7 +14,7 @@ from django.core.files import temp as tempfile
from django.core.files.uploadedfile import SimpleUploadedFile
from django.http.multipartparser import MultiPartParser
from django.test import TestCase, client
-from django.utils import simplejson, unittest
+from django.utils import unittest
from . import uploadhandler
from .models import FileModel, temp_storage, UPLOAD_TO
@@ -78,7 +79,7 @@ class FileUploadTests(TestCase):
'wsgi.input': client.FakePayload(payload),
}
response = self.client.request(**r)
- received = simplejson.loads(response.content)
+ received = json.loads(response.content)
self.assertEqual(received['file'], test_string)
@@ -150,7 +151,7 @@ class FileUploadTests(TestCase):
response = self.client.request(**r)
# The filenames should have been sanitized by the time it got to the view.
- recieved = simplejson.loads(response.content)
+ recieved = json.loads(response.content)
for i, name in enumerate(scary_file_names):
got = recieved["file%s" % i]
self.assertEqual(got, "hax0rd.txt")
@@ -174,7 +175,7 @@ class FileUploadTests(TestCase):
'REQUEST_METHOD': 'POST',
'wsgi.input': client.FakePayload(payload),
}
- got = simplejson.loads(self.client.request(**r).content)
+ got = json.loads(self.client.request(**r).content)
self.assertTrue(len(got['file']) < 256, "Got a long file name (%s characters)." % len(got['file']))
def test_truncated_multipart_handled_gracefully(self):
@@ -200,7 +201,7 @@ class FileUploadTests(TestCase):
'REQUEST_METHOD': 'POST',
'wsgi.input': client.FakePayload(payload),
}
- got = simplejson.loads(self.client.request(**r).content)
+ got = json.loads(self.client.request(**r).content)
self.assertEquals(got, {})
def test_empty_multipart_handled_gracefully(self):
@@ -215,7 +216,7 @@ class FileUploadTests(TestCase):
'REQUEST_METHOD': 'POST',
'wsgi.input': client.FakePayload(''),
}
- got = simplejson.loads(self.client.request(**r).content)
+ got = json.loads(self.client.request(**r).content)
self.assertEquals(got, {})
def test_custom_upload_handler(self):
@@ -231,12 +232,12 @@ class FileUploadTests(TestCase):
# Small file posting should work.
response = self.client.post('/file_uploads/quota/', {'f': smallfile})
- got = simplejson.loads(response.content)
+ got = json.loads(response.content)
self.assertTrue('f' in got)
# Large files don't go through.
response = self.client.post("/file_uploads/quota/", {'f': bigfile})
- got = simplejson.loads(response.content)
+ got = json.loads(response.content)
self.assertTrue('f' not in got)
def test_broken_custom_upload_handler(self):
@@ -274,7 +275,7 @@ class FileUploadTests(TestCase):
'field5': u'test7',
'file2': (file2, file2a)
})
- got = simplejson.loads(response.content)
+ got = json.loads(response.content)
self.assertEqual(got.get('file1'), 1)
self.assertEqual(got.get('file2'), 2)
diff --git a/tests/regressiontests/file_uploads/views.py b/tests/regressiontests/file_uploads/views.py
index 9fd1a8d544..ae6842d0a7 100644
--- a/tests/regressiontests/file_uploads/views.py
+++ b/tests/regressiontests/file_uploads/views.py
@@ -1,11 +1,11 @@
from __future__ import absolute_import
import hashlib
+import json
import os
from django.core.files.uploadedfile import UploadedFile
from django.http import HttpResponse, HttpResponseServerError
-from django.utils import simplejson
from .models import FileModel, UPLOAD_TO
from .tests import UNICODE_FILENAME
@@ -88,14 +88,14 @@ def file_upload_echo(request):
Simple view to echo back info about uploaded files for tests.
"""
r = dict([(k, f.name) for k, f in request.FILES.items()])
- return HttpResponse(simplejson.dumps(r))
+ return HttpResponse(json.dumps(r))
def file_upload_echo_content(request):
"""
Simple view to echo back the content of uploaded files for tests.
"""
r = dict([(k, f.read()) for k, f in request.FILES.items()])
- return HttpResponse(simplejson.dumps(r))
+ return HttpResponse(json.dumps(r))
def file_upload_quota(request):
"""
@@ -120,7 +120,7 @@ def file_upload_getlist_count(request):
for key in request.FILES.keys():
file_counts[key] = len(request.FILES.getlist(key))
- return HttpResponse(simplejson.dumps(file_counts))
+ return HttpResponse(json.dumps(file_counts))
def file_upload_errors(request):
request.upload_handlers.insert(0, ErroringUploadHandler())
diff --git a/tests/regressiontests/test_client_regress/views.py b/tests/regressiontests/test_client_regress/views.py
index ebb68c4c82..ffd416655e 100644
--- a/tests/regressiontests/test_client_regress/views.py
+++ b/tests/regressiontests/test_client_regress/views.py
@@ -1,3 +1,4 @@
+import json
import warnings
from django.conf import settings
@@ -5,7 +6,6 @@ from django.contrib.auth.decorators import login_required
from django.http import HttpResponse, HttpResponseRedirect
from django.core.exceptions import SuspiciousOperation
from django.shortcuts import render_to_response
-from django.utils import simplejson
from django.utils.encoding import smart_str
from django.core.serializers.json import DjangoJSONEncoder
from django.test.client import CONTENT_TYPE_RE
@@ -81,8 +81,8 @@ def return_json_file(request):
charset = settings.DEFAULT_CHARSET
# This just checks that the uploaded data is JSON
- obj_dict = simplejson.loads(request.body.decode(charset))
- obj_json = simplejson.dumps(obj_dict, encoding=charset,
+ obj_dict = json.loads(request.body.decode(charset))
+ obj_json = json.dumps(obj_dict, encoding=charset,
cls=DjangoJSONEncoder,
ensure_ascii=False)
response = HttpResponse(smart_str(obj_json, encoding=charset), status=200,
diff --git a/tests/regressiontests/test_utils/tests.py b/tests/regressiontests/test_utils/tests.py
index 2192404b93..a277bc999b 100644
--- a/tests/regressiontests/test_utils/tests.py
+++ b/tests/regressiontests/test_utils/tests.py
@@ -491,7 +491,7 @@ class AssertFieldOutputTests(SimpleTestCase):
__test__ = {"API_TEST": r"""
# Some checks of the doctest output normalizer.
# Standard doctests do fairly
->>> from django.utils import simplejson
+>>> import json
>>> from django.utils.xmlutils import SimplerXMLGenerator
>>> from StringIO import StringIO
@@ -502,7 +502,7 @@ __test__ = {"API_TEST": r"""
... return 42
>>> def produce_json():
-... return simplejson.dumps(['foo', {'bar': ('baz', None, 1.0, 2), 'whiz': 42}])
+... return json.dumps(['foo', {'bar': ('baz', None, 1.0, 2), 'whiz': 42}])
>>> def produce_xml():
... stream = StringIO()