diff options
| author | Tom Christie | 2013-01-02 13:27:00 +0000 |
|---|---|---|
| committer | Tom Christie | 2013-01-02 13:27:00 +0000 |
| commit | eff40391fb66f441d2f5a643d5d46f198cf77147 (patch) | |
| tree | ce768dbccfa7194005299762b972874f6b5de156 /rest_framework/tests/utils.py | |
| parent | d379997aba5b1e41309bbed8740ed704c0feb58b (diff) | |
| parent | 389ca3b3b1faa90ea4624f495115d83024fdc151 (diff) | |
| download | django-rest-framework-eff40391fb66f441d2f5a643d5d46f198cf77147.tar.bz2 | |
Merge branch 'patch-support' of https://github.com/ahankinson/django-rest-framework into patch
Diffstat (limited to 'rest_framework/tests/utils.py')
| -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..3906adb9 --- /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 RequestFactory(RequestFactory): + + def __init__(self, **defaults): + super(RequestFactory, 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) |
