mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-11 04:07:39 +03:00
b052c92ac3
Mostly adding `from __future__ import unicode_literals` everywhere.
29 lines
915 B
Python
29 lines
915 B
Python
from __future__ import unicode_literals
|
|
from django.test.client import RequestFactory, FakePayload
|
|
from django.test.client import MULTIPART_CONTENT
|
|
from rest_framework.compat 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.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)
|