You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2017/04/13 09:33:10 UTC
[04/46] libcloud git commit: converge the 2 base classes
converge the 2 base classes
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/ccd8b107
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/ccd8b107
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/ccd8b107
Branch: refs/heads/trunk
Commit: ccd8b107f1129782b2cad2e5b9ca063a9835f4e9
Parents: f498892
Author: Anthony Shaw <an...@apache.org>
Authored: Tue Apr 11 10:58:10 2017 +1000
Committer: Anthony Shaw <an...@apache.org>
Committed: Tue Apr 11 10:58:10 2017 +1000
----------------------------------------------------------------------
libcloud/test/__init__.py | 40 ++++++++++++++++++----------------------
1 file changed, 18 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/ccd8b107/libcloud/test/__init__.py
----------------------------------------------------------------------
diff --git a/libcloud/test/__init__.py b/libcloud/test/__init__.py
index 5d6a3f9..29ee365 100644
--- a/libcloud/test/__init__.py
+++ b/libcloud/test/__init__.py
@@ -93,25 +93,7 @@ class BodyStream(StringIO):
return StringIO.read(self)
-class BaseMockHttpObject(object):
- def _get_method_name(self, type, use_param, qs, path):
- path = path.split('?')[0]
- meth_name = path.replace('/', '_').replace('.', '_').replace('-', '_')
-
- if type:
- meth_name = '%s_%s' % (meth_name, self.type)
-
- if use_param and use_param in qs:
- param = qs[use_param][0].replace('.', '_').replace('-', '_')
- meth_name = '%s_%s' % (meth_name, param)
-
- if meth_name == '':
- meth_name = 'root'
-
- return meth_name
-
-
-class MockHttp(BaseMockHttpObject, LibcloudConnection):
+class MockHttp(LibcloudConnection):
"""
A mock HTTP client/server suitable for testing purposes. This replaces
`HTTPConnection` by implementing its API and returning a mock response.
@@ -143,16 +125,14 @@ class MockHttp(BaseMockHttpObject, LibcloudConnection):
"""
type = None
use_param = None # will use this param to namespace the request function
-
test = None # TestCase instance which is using this mock
-
proxy_url = None
def request(self, method, url, body=None, headers=None, raw=False, stream=False):
# Find a method we can use for this request
parsed = urlparse.urlparse(url)
- scheme, netloc, path, params, query, fragment = parsed
+ _, _, path, _, query, _ = parsed
qs = parse_qs(query)
if path.endswith('/'):
path = path[:-1]
@@ -186,6 +166,22 @@ class MockHttp(BaseMockHttpObject, LibcloudConnection):
return (httplib.FORBIDDEN, 'Oh Noes!', {'X-Foo': 'fail'},
httplib.responses[httplib.FORBIDDEN])
+ def _get_method_name(self, type, use_param, qs, path):
+ path = path.split('?')[0]
+ meth_name = path.replace('/', '_').replace('.', '_').replace('-', '_')
+
+ if type:
+ meth_name = '%s_%s' % (meth_name, self.type)
+
+ if use_param and use_param in qs:
+ param = qs[use_param][0].replace('.', '_').replace('-', '_')
+ meth_name = '%s_%s' % (meth_name, param)
+
+ if meth_name == '':
+ meth_name = 'root'
+
+ return meth_name
+
class MockHttpTestCase(MockHttp, unittest.TestCase):
# Same as the MockHttp class, but you can also use assertions in the