fix httpretty based test cases if http_proxy is set.
previously this would fail: http_proxy=http://foo.bar make test now it will pass. This works around a bug where httpretty is not able to patch http operations if http_proxy is set. https://github.com/gabrielfalcao/HTTPretty/issues/122
This commit is contained in:
parent
aeca294990
commit
d436f218f7
@ -233,6 +233,21 @@ class FilesystemMockingTestCase(ResourceUsingTestCase):
|
||||
self.patched_funcs.append((mod, f, func))
|
||||
|
||||
|
||||
class HttprettyTestCase(TestCase):
|
||||
# necessary as http_proxy gets in the way of httpretty
|
||||
# https://github.com/gabrielfalcao/HTTPretty/issues/122
|
||||
def setUp(self):
|
||||
self.restore_proxy = os.environ.get('http_proxy')
|
||||
if self.restore_proxy is not None:
|
||||
del os.environ['http_proxy']
|
||||
super(HttprettyTestCase, self).setUp()
|
||||
|
||||
def tearDown(self):
|
||||
if self.restore_proxy:
|
||||
os.environ['http_proxy'] = self.restore_proxy
|
||||
super(HttprettyTestCase, self).tearDown()
|
||||
|
||||
|
||||
def populate_dir(path, files):
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
|
@ -55,12 +55,13 @@ def _request_callback(method, uri, headers):
|
||||
return (404, headers, '')
|
||||
|
||||
|
||||
class TestDataSourceGCE(test_helpers.TestCase):
|
||||
class TestDataSourceGCE(test_helpers.HttprettyTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.ds = DataSourceGCE.DataSourceGCE(
|
||||
settings.CFG_BUILTIN, None,
|
||||
helpers.Paths({}))
|
||||
super(TestDataSourceGCE, self).setUp()
|
||||
|
||||
@httpretty.activate
|
||||
def test_connection(self):
|
||||
|
@ -121,7 +121,7 @@ def _register_uris(version, ec2_files, ec2_meta, os_files):
|
||||
body=get_request_callback)
|
||||
|
||||
|
||||
class TestOpenStackDataSource(test_helpers.TestCase):
|
||||
class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
|
||||
VERSION = 'latest'
|
||||
|
||||
@hp.activate
|
||||
|
@ -6,7 +6,7 @@ from cloudinit import url_helper as uh
|
||||
import httpretty as hp
|
||||
|
||||
|
||||
class TestEc2Util(helpers.TestCase):
|
||||
class TestEc2Util(helpers.HttprettyTestCase):
|
||||
VERSION = 'latest'
|
||||
|
||||
@hp.activate
|
||||
|
Loading…
x
Reference in New Issue
Block a user