← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~smoser/cloud-init:httpretty-cleanup into cloud-init:master

 

Scott Moser has proposed merging ~smoser/cloud-init:httpretty-cleanup into cloud-init:master.

Requested reviews:
  Dan Watkins (daniel-thewatkins)
  cloud init development team (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/315489
-- 
Your team cloud init development team is requested to review the proposed merge of ~smoser/cloud-init:httpretty-cleanup into cloud-init:master.
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py
index 64e56d9..f62d73c 100644
--- a/tests/unittests/helpers.py
+++ b/tests/unittests/helpers.py
@@ -9,6 +9,7 @@ import sys
 import tempfile
 import unittest
 
+import httpretty
 import mock
 import six
 import unittest2
@@ -29,7 +30,6 @@ PY2 = False
 PY26 = False
 PY27 = False
 PY3 = False
-FIX_HTTPRETTY = False
 
 _PY_VER = sys.version_info
 _PY_MAJOR, _PY_MINOR, _PY_MICRO = _PY_VER[0:3]
@@ -44,8 +44,6 @@ else:
         PY2 = True
     if (_PY_MAJOR, _PY_MINOR) >= (3, 0):
         PY3 = True
-        if _PY_MINOR == 4 and _PY_MICRO < 3:
-            FIX_HTTPRETTY = True
 
 
 # Makes the old path start
@@ -216,37 +214,6 @@ class FilesystemMockingTestCase(ResourceUsingTestCase):
         return root
 
 
-def import_httpretty():
-    """Import HTTPretty and monkey patch Python 3.4 issue.
-    See https://github.com/gabrielfalcao/HTTPretty/pull/193 and
-    as well as https://github.com/gabrielfalcao/HTTPretty/issues/221.
-
-    Lifted from
-    https://github.com/inveniosoftware/datacite/blob/master/tests/helpers.py
-    """
-    if not FIX_HTTPRETTY:
-        import httpretty
-    else:
-        import socket
-        old_SocketType = socket.SocketType
-
-        import httpretty
-        from httpretty import core
-
-        def sockettype_patch(f):
-            @functools.wraps(f)
-            def inner(*args, **kwargs):
-                f(*args, **kwargs)
-                socket.SocketType = old_SocketType
-                socket.__dict__['SocketType'] = old_SocketType
-            return inner
-
-        core.httpretty.disable = sockettype_patch(
-            httpretty.httpretty.disable
-        )
-    return httpretty
-
-
 class HttprettyTestCase(TestCase):
     # necessary as http_proxy gets in the way of httpretty
     # https://github.com/gabrielfalcao/HTTPretty/issues/122
diff --git a/tests/unittests/test_datasource/test_gce.py b/tests/unittests/test_datasource/test_gce.py
index a5cced0..8757cb8 100644
--- a/tests/unittests/test_datasource/test_gce.py
+++ b/tests/unittests/test_datasource/test_gce.py
@@ -14,8 +14,8 @@ from cloudinit import settings
 from cloudinit.sources import DataSourceGCE
 
 from .. import helpers as test_helpers
+from ..helpers import httpretty
 
-httpretty = test_helpers.import_httpretty()
 
 GCE_META = {
     'instance/id': '123',
diff --git a/tests/unittests/test_datasource/test_openstack.py b/tests/unittests/test_datasource/test_openstack.py
index 28e1833..6eeed73 100644
--- a/tests/unittests/test_datasource/test_openstack.py
+++ b/tests/unittests/test_datasource/test_openstack.py
@@ -20,7 +20,7 @@ from cloudinit.sources import DataSourceOpenStack as ds
 from cloudinit.sources.helpers import openstack
 from cloudinit import util
 
-hp = test_helpers.import_httpretty()
+hp = helpers.httpretty
 
 BASE_URL = "http://169.254.169.254";
 PUBKEY = u'ssh-rsa AAAAB3NzaC1....sIkJhq8wdX+4I3A4cYbYP ubuntu@server-460\n'
diff --git a/tests/unittests/test_ec2_util.py b/tests/unittests/test_ec2_util.py
index 71c2009..61723d9 100644
--- a/tests/unittests/test_ec2_util.py
+++ b/tests/unittests/test_ec2_util.py
@@ -5,7 +5,7 @@ from . import helpers
 from cloudinit import ec2_utils as eu
 from cloudinit import url_helper as uh
 
-hp = helpers.import_httpretty()
+hp = helpers.httpretty
 
 
 class TestEc2Util(helpers.HttprettyTestCase):