Make TestResponse properly inherit Response.

There are a number of problems doing things like .json() if you don't
inherit the correct parameters.

Change-Id: I0dfc8ab6486090fbcd28792c18deae67e4769d53
This commit is contained in:
Jamie Lennox
2013-08-06 17:16:36 +10:00
parent de72de3b80
commit b423c6708a
2 changed files with 11 additions and 28 deletions

View File

@@ -128,12 +128,15 @@ class TestResponse(requests.Response):
def __init__(self, data):
self._text = None
super(TestResponse, self)
super(TestResponse, self).__init__()
if isinstance(data, dict):
self.status_code = data.get('status_code', None)
self.headers = data.get('headers', None)
headers = data.get('headers')
if headers:
self.headers.update(headers)
# Fake the text attribute to streamline Response creation
self._text = data.get('text', None)
# _content is defined by requests.Response
self._content = data.get('text', None)
else:
self.status_code = data
@@ -142,4 +145,4 @@ class TestResponse(requests.Response):
@property
def text(self):
return self._text
return self.content

View File

@@ -9,8 +9,12 @@ import mox
import requests
import testtools
from .. import utils
from keystoneclient.v3 import client
TestResponse = utils.TestResponse
def parameterize(ref):
"""Rewrites attributes to match the kwarg naming convention in client.
@@ -361,27 +365,3 @@ class CrudTests(testtools.TestCase):
self.mox.ReplayAll()
self.manager.delete(ref['id'])
class TestResponse(requests.Response):
"""Class used to wrap requests.Response and provide some
convenience to initialize with a dict.
"""
def __init__(self, data):
self._text = None
super(TestResponse, self)
if isinstance(data, dict):
self.status_code = data.get('status_code', None)
self.headers = data.get('headers', None)
# Fake the text attribute to streamline Response creation
self._text = data.get('text', None)
else:
self.status_code = data
def __eq__(self, other):
return self.__dict__ == other.__dict__
@property
def text(self):
return self._text