2013-02-05 00:55:35 +04:00
|
|
|
from __future__ import unicode_literals
|
2012-12-20 09:27:29 +04:00
|
|
|
from django.test.client import RequestFactory, FakePayload
|
|
|
|
from django.test.client import MULTIPART_CONTENT
|
2013-02-01 18:03:28 +04:00
|
|
|
from rest_framework.compat import urlparse
|
2012-12-20 09:27:29 +04:00
|
|
|
|
|
|
|
|
2012-12-30 21:57:43 +04:00
|
|
|
class RequestFactory(RequestFactory):
|
2012-12-20 09:27:29 +04:00
|
|
|
|
|
|
|
def __init__(self, **defaults):
|
2012-12-30 21:57:43 +04:00
|
|
|
super(RequestFactory, self).__init__(**defaults)
|
2012-12-20 09:27:29 +04:00
|
|
|
|
|
|
|
def patch(self, path, data={}, content_type=MULTIPART_CONTENT,
|
|
|
|
**extra):
|
|
|
|
"Construct a PATCH request."
|
|
|
|
|
|
|
|
patch_data = self._encode_data(data, content_type)
|
|
|
|
|
2013-02-01 18:03:28 +04:00
|
|
|
parsed = urlparse.urlparse(path)
|
2012-12-20 09:27:29 +04:00
|
|
|
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)
|