Fix all python3 test failures
There are still problems with keystoneclient but this corrects all of the tuskarclient issues. Change-Id: I7ea8ba4bab9dd6efe27370b18b6c85d2ed717833 Fixes-bug: #1213882
This commit is contained in:
@@ -6,3 +6,4 @@ prettytable>=0.6,<0.8
|
|||||||
python-keystoneclient>=0.2,<0.4
|
python-keystoneclient>=0.2,<0.4
|
||||||
requests>=0.8
|
requests>=0.8
|
||||||
simplejson
|
simplejson
|
||||||
|
six>=1.4.1
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ def print_list(objs, fields, formatters={}, custom_labels={}, sortby=0):
|
|||||||
else:
|
else:
|
||||||
row.append(getattr(o, field, ''))
|
row.append(getattr(o, field, ''))
|
||||||
pt.add_row(row)
|
pt.add_row(row)
|
||||||
print pt.get_string(sortby=field_labels[sortby])
|
print(pt.get_string(sortby=field_labels[sortby]))
|
||||||
|
|
||||||
|
|
||||||
def print_dict(d, formatters={}, custom_labels={}):
|
def print_dict(d, formatters={}, custom_labels={}):
|
||||||
@@ -77,7 +77,7 @@ def print_dict(d, formatters={}, custom_labels={}):
|
|||||||
pt.add_row([label, formatters[field](d[field])])
|
pt.add_row([label, formatters[field](d[field])])
|
||||||
else:
|
else:
|
||||||
pt.add_row([label, d[field]])
|
pt.add_row([label, d[field]])
|
||||||
print pt.get_string(sortby='Property')
|
print(pt.get_string(sortby='Property'))
|
||||||
|
|
||||||
|
|
||||||
def attr_proxy(attr, formatter=lambda a: a, allow_undefined=True):
|
def attr_proxy(attr, formatter=lambda a: a, allow_undefined=True):
|
||||||
@@ -109,7 +109,7 @@ def capacities_formatter(capacities):
|
|||||||
containing 'name', 'value' and 'unit' keys.
|
containing 'name', 'value' and 'unit' keys.
|
||||||
'''
|
'''
|
||||||
sorted_capacities = sorted(capacities,
|
sorted_capacities = sorted(capacities,
|
||||||
lambda c1, c2: cmp(c1['name'], c2['name']))
|
key=lambda c: c['name'])
|
||||||
return '\n'.join(['{0}: {1} {2}'.format(c['name'], c['value'], c['unit'])
|
return '\n'.join(['{0}: {1} {2}'.format(c['name'], c['value'], c['unit'])
|
||||||
for c in sorted_capacities])
|
for c in sorted_capacities])
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ def links_formatter(links):
|
|||||||
'''Formats a list of links. Link is a dict that has 'href' and
|
'''Formats a list of links. Link is a dict that has 'href' and
|
||||||
'rel' keys.
|
'rel' keys.
|
||||||
'''
|
'''
|
||||||
sorted_links = sorted(links, lambda l1, l2: cmp(l1['rel'], l2['rel']))
|
sorted_links = sorted(links, key=lambda l: l['rel'])
|
||||||
return '\n'.join(['{0}: {1}'.format(l['rel'], l['href'])
|
return '\n'.join(['{0}: {1}'.format(l['rel'], l['href'])
|
||||||
for l in sorted_links])
|
for l in sorted_links])
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ def resource_links_formatter(links):
|
|||||||
one. (We cannot fetch by 'rel', values in 'rel' are not used
|
one. (We cannot fetch by 'rel', values in 'rel' are not used
|
||||||
consistently.)
|
consistently.)
|
||||||
'''
|
'''
|
||||||
sorted_links = sorted(links, lambda l1, l2: cmp(l1['id'], l2['id']))
|
sorted_links = sorted(links, key=lambda l: l['id'])
|
||||||
return '\n'.join(['{0}: {1}'.format(l['id'], l['links'][0]['href'])
|
return '\n'.join(['{0}: {1}'.format(l['id'], l['links'][0]['href'])
|
||||||
for l in sorted_links])
|
for l in sorted_links])
|
||||||
|
|
||||||
|
|||||||
@@ -14,12 +14,13 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import httplib
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import StringIO
|
|
||||||
import urlparse
|
from six.moves import http_client as httplib
|
||||||
|
from six.moves.urllib import parse as urlparse
|
||||||
|
from six import StringIO
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import ssl
|
import ssl
|
||||||
@@ -127,8 +128,8 @@ class HTTPClient(object):
|
|||||||
def _http_request(self, url, method, **kwargs):
|
def _http_request(self, url, method, **kwargs):
|
||||||
"""Send an http request with the specified characteristics.
|
"""Send an http request with the specified characteristics.
|
||||||
|
|
||||||
Wrapper around httplib.HTTP(S)Connection.request to handle tasks such
|
Wrapper around http_client.HTTP(S)Connection.request to handle tasks
|
||||||
as setting headers and error handling.
|
such as setting headers and error handling.
|
||||||
"""
|
"""
|
||||||
# Copy the kwargs so we can reuse the original in case of redirects
|
# Copy the kwargs so we can reuse the original in case of redirects
|
||||||
kwargs['headers'] = copy.deepcopy(kwargs.get('headers', {}))
|
kwargs['headers'] = copy.deepcopy(kwargs.get('headers', {}))
|
||||||
@@ -205,7 +206,7 @@ class HTTPClient(object):
|
|||||||
|
|
||||||
|
|
||||||
class VerifiedHTTPSConnection(httplib.HTTPSConnection):
|
class VerifiedHTTPSConnection(httplib.HTTPSConnection):
|
||||||
"""httplib-compatibile connection using client-side SSL authentication
|
"""http_client-compatibile connection using client-side SSL authentication
|
||||||
|
|
||||||
:see http://code.activestate.com/recipes/
|
:see http://code.activestate.com/recipes/
|
||||||
577548-https-httplib-client-connection-with-certificate-v/
|
577548-https-httplib-client-connection-with-certificate-v/
|
||||||
@@ -213,7 +214,8 @@ class VerifiedHTTPSConnection(httplib.HTTPSConnection):
|
|||||||
|
|
||||||
def __init__(self, host, port, key_file=None, cert_file=None,
|
def __init__(self, host, port, key_file=None, cert_file=None,
|
||||||
ca_file=None, timeout=None, insecure=False):
|
ca_file=None, timeout=None, insecure=False):
|
||||||
httplib.HTTPSConnection.__init__(self, host, port, key_file=key_file,
|
httplib.HTTPSConnection.__init__(self, host, port,
|
||||||
|
key_file=key_file,
|
||||||
cert_file=cert_file)
|
cert_file=cert_file)
|
||||||
self.key_file = key_file
|
self.key_file = key_file
|
||||||
self.cert_file = cert_file
|
self.cert_file = cert_file
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import cStringIO
|
|
||||||
import mock
|
import mock
|
||||||
|
from six import StringIO
|
||||||
|
|
||||||
import tuskarclient.common.formatting as fmt
|
import tuskarclient.common.formatting as fmt
|
||||||
import tuskarclient.tests.utils as tutils
|
import tuskarclient.tests.utils as tutils
|
||||||
@@ -19,7 +19,7 @@ import tuskarclient.tests.utils as tutils
|
|||||||
|
|
||||||
class PrintTest(tutils.TestCase):
|
class PrintTest(tutils.TestCase):
|
||||||
|
|
||||||
@mock.patch('sys.stdout', new_callable=cStringIO.StringIO)
|
@mock.patch('sys.stdout', new_callable=StringIO)
|
||||||
def test_print_dict(self, mock_out):
|
def test_print_dict(self, mock_out):
|
||||||
dict_ = {'k': 'v', 'key': 'value'}
|
dict_ = {'k': 'v', 'key': 'value'}
|
||||||
formatters = {'key': lambda v: 'custom ' + v}
|
formatters = {'key': lambda v: 'custom ' + v}
|
||||||
@@ -36,7 +36,7 @@ class PrintTest(tutils.TestCase):
|
|||||||
mock_out.getvalue()
|
mock_out.getvalue()
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch('sys.stdout', new_callable=cStringIO.StringIO)
|
@mock.patch('sys.stdout', new_callable=StringIO)
|
||||||
def test_print_list(self, mock_out):
|
def test_print_list(self, mock_out):
|
||||||
fields = ['thing', 'color', '!artistic_name']
|
fields = ['thing', 'color', '!artistic_name']
|
||||||
formatters = {
|
formatters = {
|
||||||
@@ -57,7 +57,7 @@ class PrintTest(tutils.TestCase):
|
|||||||
mock_out.getvalue()
|
mock_out.getvalue()
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch('sys.stdout', new_callable=cStringIO.StringIO)
|
@mock.patch('sys.stdout', new_callable=StringIO)
|
||||||
def test_print_list_custom_field_without_formatter(self, mock_out):
|
def test_print_list_custom_field_without_formatter(self, mock_out):
|
||||||
fields = ['!artistic_name']
|
fields = ['!artistic_name']
|
||||||
|
|
||||||
|
|||||||
@@ -27,25 +27,25 @@ class HttpClientUrlGenerationTest(tutils.TestCase):
|
|||||||
def test_url_generation_trailing_slash_in_base(self):
|
def test_url_generation_trailing_slash_in_base(self):
|
||||||
client = http.HTTPClient('http://localhost/')
|
client = http.HTTPClient('http://localhost/')
|
||||||
url = client._make_connection_url('/v1/resources')
|
url = client._make_connection_url('/v1/resources')
|
||||||
print client.connection_params
|
print(client.connection_params)
|
||||||
self.assertEqual(url, '/v1/resources')
|
self.assertEqual(url, '/v1/resources')
|
||||||
|
|
||||||
def test_url_generation_without_trailing_slash_in_base(self):
|
def test_url_generation_without_trailing_slash_in_base(self):
|
||||||
client = http.HTTPClient('http://localhost')
|
client = http.HTTPClient('http://localhost')
|
||||||
url = client._make_connection_url('/v1/resources')
|
url = client._make_connection_url('/v1/resources')
|
||||||
print client.connection_params
|
print(client.connection_params)
|
||||||
self.assertEqual(url, '/v1/resources')
|
self.assertEqual(url, '/v1/resources')
|
||||||
|
|
||||||
def test_url_generation_prefix_slash_in_path(self):
|
def test_url_generation_prefix_slash_in_path(self):
|
||||||
client = http.HTTPClient('http://localhost/')
|
client = http.HTTPClient('http://localhost/')
|
||||||
url = client._make_connection_url('/v1/resources')
|
url = client._make_connection_url('/v1/resources')
|
||||||
print client.connection_params
|
print(client.connection_params)
|
||||||
self.assertEqual(url, '/v1/resources')
|
self.assertEqual(url, '/v1/resources')
|
||||||
|
|
||||||
def test_url_generation_without_prefix_slash_in_path(self):
|
def test_url_generation_without_prefix_slash_in_path(self):
|
||||||
client = http.HTTPClient('http://localhost')
|
client = http.HTTPClient('http://localhost')
|
||||||
url = client._make_connection_url('v1/resources')
|
url = client._make_connection_url('v1/resources')
|
||||||
print client.connection_params
|
print(client.connection_params)
|
||||||
self.assertEqual(url, '/v1/resources')
|
self.assertEqual(url, '/v1/resources')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
import copy
|
import copy
|
||||||
import fixtures
|
import fixtures
|
||||||
import os
|
import os
|
||||||
import StringIO
|
|
||||||
|
from six import StringIO
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from tuskarclient.common import http
|
from tuskarclient.common import http
|
||||||
@@ -45,7 +46,8 @@ class FakeAPI(object):
|
|||||||
|
|
||||||
def raw_request(self, *args, **kwargs):
|
def raw_request(self, *args, **kwargs):
|
||||||
fixture = self._request(*args, **kwargs)
|
fixture = self._request(*args, **kwargs)
|
||||||
body_iter = http.ResponseBodyIterator(StringIO.StringIO(fixture[1]))
|
body_iter = http.ResponseBodyIterator(
|
||||||
|
StringIO.StringIO(fixture[1]))
|
||||||
return FakeResponse(fixture[0]), body_iter
|
return FakeResponse(fixture[0]), body_iter
|
||||||
|
|
||||||
def json_request(self, *args, **kwargs):
|
def json_request(self, *args, **kwargs):
|
||||||
|
|||||||
Reference in New Issue
Block a user