c73afa9fd1
The requests module dropped all configuration with the 1.0.0 release. There's no danger_mode and no 'verbose'' mode. The former shouldn't be necessary anymore and the latter can be done by setting a different log handler for the request.logging root logger. Change-Id: Iec169ef6e39097814cdbf1b777bc0590236692ba
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
import os
|
|
|
|
import fixtures
|
|
import requests
|
|
import testtools
|
|
|
|
|
|
class TestCase(testtools.TestCase):
|
|
TEST_REQUEST_BASE = {
|
|
'verify': True,
|
|
}
|
|
|
|
def setUp(self):
|
|
super(TestCase, self).setUp()
|
|
if (os.environ.get('OS_STDOUT_NOCAPTURE') == 'True' and
|
|
os.environ.get('OS_STDOUT_NOCAPTURE') == '1'):
|
|
stdout = self.useFixture(fixtures.StringStream('stdout')).stream
|
|
self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
|
|
if (os.environ.get('OS_STDERR_NOCAPTURE') == 'True' and
|
|
os.environ.get('OS_STDERR_NOCAPTURE') == '1'):
|
|
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
|
|
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
|
|
|
|
|
|
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
|