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.
This commit is contained in:
Mjumbe Wawatu Poe 2012-09-07 19:14:20 -04:00
parent f729d0eb0b
commit 9c007a6197

View File

@ -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)
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):