Skip to content

Commit

Permalink
fix httpretty based test cases if http_proxy is set.
Browse files Browse the repository at this point in the history
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.

gabrielfalcao/HTTPretty#122
  • Loading branch information
smoser committed Jul 23, 2014
1 parent 77d0be9 commit b8f81c7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
15 changes: 15 additions & 0 deletions tests/unittests/helpers.py
Expand Up @@ -233,6 +233,21 @@ def patchOS(self, new_root):
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)
Expand Down
3 changes: 2 additions & 1 deletion tests/unittests/test_datasource/test_gce.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/test_datasource/test_openstack.py
Expand Up @@ -121,7 +121,7 @@ def get_request_callback(method, uri, headers):
body=get_request_callback)


class TestOpenStackDataSource(test_helpers.TestCase):
class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
VERSION = 'latest'

@hp.activate
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/test_ec2_util.py
Expand Up @@ -6,7 +6,7 @@
import httpretty as hp


class TestEc2Util(helpers.TestCase):
class TestEc2Util(helpers.HttprettyTestCase):
VERSION = 'latest'

@hp.activate
Expand Down

0 comments on commit b8f81c7

Please sign in to comment.