From 2b5deefe567d46315e9233fd405328e762e4ce07 Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Thu, 20 Dec 2012 00:27:29 -0500 Subject: Subclass Django's RequestFactory to provide PATCH support --- rest_framework/tests/utils.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 rest_framework/tests/utils.py (limited to 'rest_framework/tests/utils.py') diff --git a/rest_framework/tests/utils.py b/rest_framework/tests/utils.py new file mode 100644 index 00000000..d7f14156 --- /dev/null +++ b/rest_framework/tests/utils.py @@ -0,0 +1,27 @@ +from django.test.client import RequestFactory, FakePayload +from django.test.client import MULTIPART_CONTENT +from urlparse import urlparse + + +class DRFRequestFactory(RequestFactory): + + def __init__(self, **defaults): + super(DRFRequestFactory, self).__init__(**defaults) + + def patch(self, path, data={}, content_type=MULTIPART_CONTENT, + **extra): + "Construct a PATCH request." + + patch_data = self._encode_data(data, content_type) + + parsed = urlparse(path) + r = { + 'CONTENT_LENGTH': len(patch_data), + 'CONTENT_TYPE': content_type, + 'PATH_INFO': self._get_path(parsed), + 'QUERY_STRING': parsed[4], + 'REQUEST_METHOD': 'PATCH', + 'wsgi.input': FakePayload(patch_data), + } + r.update(extra) + return self.request(**r) -- cgit v1.2.3 From df1880185c87733a82a41392898e67fe02c769aa Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Sun, 30 Dec 2012 13:57:43 -0400 Subject: Renaming DRFRequestFactory to RequestFactory Updated tests to reflect the new name. --- rest_framework/tests/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'rest_framework/tests/utils.py') diff --git a/rest_framework/tests/utils.py b/rest_framework/tests/utils.py index d7f14156..3906adb9 100644 --- a/rest_framework/tests/utils.py +++ b/rest_framework/tests/utils.py @@ -3,10 +3,10 @@ from django.test.client import MULTIPART_CONTENT from urlparse import urlparse -class DRFRequestFactory(RequestFactory): +class RequestFactory(RequestFactory): def __init__(self, **defaults): - super(DRFRequestFactory, self).__init__(**defaults) + super(RequestFactory, self).__init__(**defaults) def patch(self, path, data={}, content_type=MULTIPART_CONTENT, **extra): -- cgit v1.2.3