From 9c007a6197ca5125bed774cf3089de7759e755d1 Mon Sep 17 00:00:00 2001 From: Mjumbe Wawatu Poe Date: Fri, 7 Sep 2012 19:14:20 -0400 Subject: [PATCH] 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. --- djangorestframework/tests/request.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/djangorestframework/tests/request.py b/djangorestframework/tests/request.py index ede5d5d79..8b2f66ee0 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):