Permalink
Browse files

Add a 1.2 compatible HttpRequest for testing.

  • Loading branch information...
joshbohde committed Jul 14, 2012
1 parent d7681de commit ab00b656011e432e722322b5249c58384cdaee55
Showing with 22 additions and 1 deletion.
  1. +21 −0 tests/core/tests/resources.py
  2. +1 −1 tests/related_resource/tests.py
@@ -29,6 +29,27 @@
from core.tests.mocks import MockRequest
from core.utils import SimpleHandler
+
+if not hasattr(HttpRequest, '_load_post_and_files'):
+ from django.utils.datastructures import MultiValueDict
+ from django.http import QueryDict
+
+ # An HttpRequest that implements _load_post_and_files
+ # for Django 1.2 compatibility
+ class HttpRequest(HttpRequest):
+ @property
+ def raw_post_data(self):
+ return self._raw_post_data
+
+ def _load_post_and_files(self):
+ # Populates self._post and self._files
+ if self.method != 'POST':
+ self._post, self._files = QueryDict('', encoding=self._encoding), MultiValueDict()
+ return
+ else:
+ self._post, self._files = QueryDict(self.raw_post_data, encoding=self._encoding), MultiValueDict()
+
+
class CustomSerializer(Serializer):
pass
@@ -1,9 +1,9 @@
from django.conf import settings
from django.contrib.auth.models import User
-from django.http import HttpRequest
from django.test import TestCase
from django.utils import simplejson as json
from core.models import Note, MediaBit
+from core.tests.resources import HttpRequest
from core.tests.mocks import MockRequest
from tastypie import fields
from related_resource.api.resources import FreshNoteResource, CategoryResource

0 comments on commit ab00b65

Please sign in to comment.