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:
Clint Byrum 2013-10-14 11:03:06 -07:00
parent 4a7913d2f1
commit 01fb13c612
6 changed files with 27 additions and 22 deletions

View File

@ -6,3 +6,4 @@ prettytable>=0.6,<0.8
python-keystoneclient>=0.2,<0.4
requests>=0.8
simplejson
six>=1.4.1

View File

@ -53,7 +53,7 @@ def print_list(objs, fields, formatters={}, custom_labels={}, sortby=0):
else:
row.append(getattr(o, field, ''))
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={}):
@ -77,7 +77,7 @@ def print_dict(d, formatters={}, custom_labels={}):
pt.add_row([label, formatters[field](d[field])])
else:
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):
@ -109,7 +109,7 @@ def capacities_formatter(capacities):
containing 'name', 'value' and 'unit' keys.
'''
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'])
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
'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'])
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
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'])
for l in sorted_links])

View File

@ -14,12 +14,13 @@
# under the License.
import copy
import httplib
import logging
import os
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:
import ssl
@ -127,8 +128,8 @@ class HTTPClient(object):
def _http_request(self, url, method, **kwargs):
"""Send an http request with the specified characteristics.
Wrapper around httplib.HTTP(S)Connection.request to handle tasks such
as setting headers and error handling.
Wrapper around http_client.HTTP(S)Connection.request to handle tasks
such as setting headers and error handling.
"""
# Copy the kwargs so we can reuse the original in case of redirects
kwargs['headers'] = copy.deepcopy(kwargs.get('headers', {}))
@ -205,7 +206,7 @@ class HTTPClient(object):
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/
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,
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)
self.key_file = key_file
self.cert_file = cert_file

View File

@ -10,8 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import cStringIO
import mock
from six import StringIO
import tuskarclient.common.formatting as fmt
import tuskarclient.tests.utils as tutils
@ -19,7 +19,7 @@ import tuskarclient.tests.utils as tutils
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):
dict_ = {'k': 'v', 'key': 'value'}
formatters = {'key': lambda v: 'custom ' + v}
@ -36,7 +36,7 @@ class PrintTest(tutils.TestCase):
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):
fields = ['thing', 'color', '!artistic_name']
formatters = {
@ -57,7 +57,7 @@ class PrintTest(tutils.TestCase):
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):
fields = ['!artistic_name']

View File

@ -27,25 +27,25 @@ class HttpClientUrlGenerationTest(tutils.TestCase):
def test_url_generation_trailing_slash_in_base(self):
client = http.HTTPClient('http://localhost/')
url = client._make_connection_url('/v1/resources')
print client.connection_params
print(client.connection_params)
self.assertEqual(url, '/v1/resources')
def test_url_generation_without_trailing_slash_in_base(self):
client = http.HTTPClient('http://localhost')
url = client._make_connection_url('/v1/resources')
print client.connection_params
print(client.connection_params)
self.assertEqual(url, '/v1/resources')
def test_url_generation_prefix_slash_in_path(self):
client = http.HTTPClient('http://localhost/')
url = client._make_connection_url('/v1/resources')
print client.connection_params
print(client.connection_params)
self.assertEqual(url, '/v1/resources')
def test_url_generation_without_prefix_slash_in_path(self):
client = http.HTTPClient('http://localhost')
url = client._make_connection_url('v1/resources')
print client.connection_params
print(client.connection_params)
self.assertEqual(url, '/v1/resources')

View File

@ -13,7 +13,8 @@
import copy
import fixtures
import os
import StringIO
from six import StringIO
import testtools
from tuskarclient.common import http
@ -45,7 +46,8 @@ class FakeAPI(object):
def raw_request(self, *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
def json_request(self, *args, **kwargs):