def get_proxy_url(self): scheme = urlutils.urlparse(self.endpoint).scheme if scheme == 'https': return os.environ.get('https_proxy') elif scheme == 'http': return os.environ.get('http_proxy') msg = 'Unsupported scheme: %s' % scheme raise exc.InvalidEndpoint(msg)
def get_proxy_url(self): scheme = urlutils.urlparse(self.endpoint).scheme if scheme == 'https': return os.environ.get('https_proxy') elif scheme == 'http': return os.environ.get('http_proxy') msg = 'Unsupported scheme: %s' % scheme raise exc.InvalidEndpoint(msg)
def get_connection(self): _class = self.connection_params[0] try: if self.proxy_url: proxy_parts = urlutils.urlparse(self.proxy_url) return _class(proxy_parts.hostname, proxy_parts.port, **self.connection_params[2]) else: return _class(*self.connection_params[1][0:2], **self.connection_params[2]) except httplib.InvalidURL: raise exc.InvalidEndpoint()
def get_connection(self): _class = self.connection_params[0] try: if self.proxy_url: proxy_parts = urlutils.urlparse(self.proxy_url) return _class(proxy_parts.hostname, proxy_parts.port, **self.connection_params[2]) else: return _class(*self.connection_params[1][0:2], **self.connection_params[2]) except httplib.InvalidURL: raise exc.InvalidEndpoint()
def get_connection_params(endpoint, **kwargs): parts = urlutils.urlparse(endpoint) _args = (parts.hostname, parts.port, parts.path) _kwargs = {'timeout': (float(kwargs.get('timeout')) if kwargs.get('timeout') else 600)} if parts.scheme == 'https': _class = VerifiedHTTPSConnection _kwargs['cacert'] = kwargs.get('cacert', None) _kwargs['cert_file'] = kwargs.get('cert_file', None) _kwargs['key_file'] = kwargs.get('key_file', None) _kwargs['insecure'] = kwargs.get('insecure', False) elif parts.scheme == 'http': _class = httplib.HTTPConnection else: msg = 'Unsupported scheme: %s' % parts.scheme raise exc.InvalidEndpoint(msg) return (_class, _args, _kwargs)
def client_request(self, client, method, url, **kwargs): # Check that certain things are called correctly if method in ["GET", "DELETE"]: assert "json" not in kwargs # Note the call self.callstack.append( (method, url, kwargs.get("headers") or {}, kwargs.get("json") or kwargs.get("data"))) try: fixture = self.fixtures[url][method] except KeyError: pass else: return TestResponse({"headers": fixture[0], "text": fixture[1]}) # Call the method args = urlutils.parse_qsl(urlutils.urlparse(url)[4]) kwargs.update(args) munged_url = url.rsplit('?', 1)[0] munged_url = munged_url.strip('/').replace('/', '_').replace('.', '_') munged_url = munged_url.replace('-', '_') callback = "%s_%s" % (method.lower(), munged_url) if not hasattr(self, callback): raise AssertionError('Called unknown API method: %s %s, ' 'expected fakes method name: %s' % (method, url, callback)) resp = getattr(self, callback)(**kwargs) if len(resp) == 3: status, headers, body = resp else: status, body = resp headers = {} return TestResponse({ "status_code": status, "text": body, "headers": headers, })
def get_connection_params(endpoint, **kwargs): parts = urlutils.urlparse(endpoint) _args = (parts.hostname, parts.port, parts.path) _kwargs = { 'timeout': (float(kwargs.get('timeout')) if kwargs.get('timeout') else 600) } if parts.scheme == 'https': _class = VerifiedHTTPSConnection _kwargs['cacert'] = kwargs.get('cacert', None) _kwargs['cert_file'] = kwargs.get('cert_file', None) _kwargs['key_file'] = kwargs.get('key_file', None) _kwargs['insecure'] = kwargs.get('insecure', False) elif parts.scheme == 'http': _class = httplib.HTTPConnection else: msg = 'Unsupported scheme: %s' % parts.scheme raise exc.InvalidEndpoint(msg) return (_class, _args, _kwargs)