mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-05-10 02:43:41 +03:00
Subclass Django's RequestFactory to provide PATCH support
This commit is contained in:
parent
18338a37d3
commit
2b5deefe56
27
rest_framework/tests/utils.py
Normal file
27
rest_framework/tests/utils.py
Normal file
|
@ -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)
|
Loading…
Reference in New Issue
Block a user