Skip to content
Prev Previous commit
Next Next commit
Py3 compat
  • Loading branch information
lovelydinosaur committed Aug 17, 2016
commit da47c345c09eaf4fffca9cfcd18bba7acd844e8b
26 changes: 15 additions & 11 deletions rest_framework/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ def force_authenticate(request, user=None, token=None):


if requests is not None:
class HeaderDict(requests.packages.urllib3._collections.HTTPHeaderDict):
def get_all(self, key):
return self.getheaders(self, key)

class MockOriginalResponse(object):
def __init__(self, headers):
self.msg = HeaderDict(headers)
self.closed = False

def isclosed(self):
return self.closed

def close(self):
self.closed = True

class DjangoTestAdapter(requests.adapters.HTTPAdapter):
"""
A transport adapter for `requests`, that makes requests via the
Expand Down Expand Up @@ -65,17 +80,6 @@ def send(self, request, *args, **kwargs):
raw_kwargs = {}

def start_response(wsgi_status, wsgi_headers):
class MockOriginalResponse(object):
def __init__(self, headers):
self.msg = requests.packages.urllib3._collections.HTTPHeaderDict(headers)
self.closed = False

def isclosed(self):
return self.closed

def close(self):
self.closed = True

status, _, reason = wsgi_status.partition(' ')
raw_kwargs['status'] = int(status)
raw_kwargs['reason'] = reason
Expand Down