diff options
| author | Andrew Hankinson | 2012-12-20 00:27:29 -0500 |
|---|---|---|
| committer | Andrew Hankinson | 2012-12-20 00:27:29 -0500 |
| commit | 2b5deefe567d46315e9233fd405328e762e4ce07 (patch) | |
| tree | 9802cd3cd03e184b1e7a437abbe445545688713c | |
| parent | 18338a37d356faebb0f59bd57b2ba876d66e6b73 (diff) | |
| download | django-rest-framework-2b5deefe567d46315e9233fd405328e762e4ce07.tar.bz2 | |
Subclass Django's RequestFactory to provide PATCH support
| -rw-r--r-- | rest_framework/tests/utils.py | 27 |
1 files changed, 27 insertions, 0 deletions
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) |
