Commit 9c007a61 by Mjumbe Wawatu Poe

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.
parent f729d0eb
...@@ -4,7 +4,6 @@ Tests for content parsing, and form-overloaded content parsing. ...@@ -4,7 +4,6 @@ Tests for content parsing, and form-overloaded content parsing.
from django.conf.urls.defaults import patterns from django.conf.urls.defaults import patterns
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.test import TestCase, Client from django.test import TestCase, Client
from django.test.client import MULTIPART_CONTENT, BOUNDARY, encode_multipart
from djangorestframework import status from djangorestframework import status
from djangorestframework.authentication import SessionAuthentication from djangorestframework.authentication import SessionAuthentication
...@@ -95,8 +94,16 @@ class TestContentParsing(TestCase): ...@@ -95,8 +94,16 @@ class TestContentParsing(TestCase):
""" """
data = {'qwerty': 'uiop'} data = {'qwerty': 'uiop'}
parsers = (FormParser, MultiPartParser) 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()) self.assertEqual(request.DATA.items(), data.items())
def test_standard_behaviour_determines_non_form_content_PUT(self): def test_standard_behaviour_determines_non_form_content_PUT(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment