aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/tests
diff options
context:
space:
mode:
authorMjumbe Wawatu Poe2012-09-07 19:14:20 -0400
committerMjumbe Wawatu Poe2012-09-07 19:14:20 -0400
commit9c007a6197ca5125bed774cf3089de7759e755d1 (patch)
tree3156c0e1d3589d40c5197e175dc4743137bcb9d5 /djangorestframework/tests
parentf729d0eb0b8901f18799bb714c60d54c73a1ec98 (diff)
downloaddjango-rest-framework-9c007a6197ca5125bed774cf3089de7759e755d1.tar.bz2
Fix the tests on 1.3 and HEAD
In the latest Django master code, RequestFactory.put behaves fundamentally differently than it did pre-1.5. By default, it expects an octet string as opposed to a dictionary that it will encode like a multipart form. So, for 1.5 and on, we have to be explicit about the multipart type and pre-encode the data. However, pre-1.5 Django expects a dictionary if the content type is multipart. So, the cleanest thing to do is explicitly handle the versions independently.
Diffstat (limited to 'djangorestframework/tests')
-rw-r--r--djangorestframework/tests/request.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/djangorestframework/tests/request.py b/djangorestframework/tests/request.py
index ede5d5d7..8b2f66ee 100644
--- a/djangorestframework/tests/request.py
+++ b/djangorestframework/tests/request.py
@@ -4,7 +4,6 @@ Tests for content parsing, and form-overloaded content parsing.
from django.conf.urls.defaults import patterns
from django.contrib.auth.models import User
from django.test import TestCase, Client
-from django.test.client import MULTIPART_CONTENT, BOUNDARY, encode_multipart
from djangorestframework import status
from djangorestframework.authentication import SessionAuthentication
@@ -95,8 +94,16 @@ class TestContentParsing(TestCase):
"""
data = {'qwerty': 'uiop'}
parsers = (FormParser, MultiPartParser)
- request = factory.put('/', encode_multipart(BOUNDARY, data), parsers=parsers,
- content_type=MULTIPART_CONTENT)
+
+ from django import VERSION
+
+ if VERSION >= (1, 5):
+ from django.test.client import MULTIPART_CONTENT, BOUNDARY, encode_multipart
+ request = factory.put('/', encode_multipart(BOUNDARY, data), parsers=parsers,
+ content_type=MULTIPART_CONTENT)
+ else:
+ request = factory.put('/', data, parsers=parsers)
+
self.assertEqual(request.DATA.items(), data.items())
def test_standard_behaviour_determines_non_form_content_PUT(self):