Fix the parameter order of assertEqual in glanceclient test

On assertEqual, the order of parameters should be (expected, observed).
But, some part of glanceclient test were written with invalid order.
This patch fixes this problem.

Change-Id: I7722fdce766ce3cc5bc9944dc72d7d0af0b09f69
Partially-bug: #1277104
This commit is contained in:
Eiichi Aikawa 2014-02-24 18:47:59 +09:00
parent fe006e0671
commit 3576b1bdcb
5 changed files with 49 additions and 47 deletions

View File

@ -23,14 +23,14 @@ class TestBase(testtools.TestCase):
def test_resource_repr(self):
r = base.Resource(None, dict(foo="bar", baz="spam"))
self.assertEqual(repr(r), "<Resource baz=spam, foo=bar>")
self.assertEqual("<Resource baz=spam, foo=bar>", repr(r))
def test_getid(self):
self.assertEqual(base.getid(4), 4)
self.assertEqual(4, base.getid(4))
class TmpObject(object):
id = 4
self.assertEqual(base.getid(TmpObject), 4)
self.assertEqual(4, base.getid(TmpObject))
def test_two_resources_with_same_id_are_equal(self):
# Two resources of the same type with the same id: equal

View File

@ -59,7 +59,7 @@ class TestClient(testtools.TestCase):
kwargs = {'token': u'fake-token',
'identity_headers': identity_headers}
http_client_object = http.HTTPClient(self.endpoint, **kwargs)
self.assertEqual(http_client_object.auth_token, 'auth_token')
self.assertEqual('auth_token', http_client_object.auth_token)
self.assertTrue(http_client_object.identity_headers.
get('X-Auth-Token') is None)
@ -75,7 +75,7 @@ class TestClient(testtools.TestCase):
kwargs = {'token': u'fake-token',
'identity_headers': identity_headers}
http_client_object = http.HTTPClient(self.endpoint, **kwargs)
self.assertEqual(http_client_object.auth_token, u'fake-token')
self.assertEqual(u'fake-token', http_client_object.auth_token)
self.assertTrue(http_client_object.identity_headers.
get('X-Auth-Token') is None)
@ -143,20 +143,20 @@ class TestClient(testtools.TestCase):
headers = {"test": u'ni\xf1o'}
resp, body = self.client.raw_request('GET', '/v1/images/detail',
headers=headers)
self.assertEqual(resp, fake)
self.assertEqual(fake, resp)
def test_headers_encoding(self):
headers = {"test": u'ni\xf1o'}
encoded = self.client.encode_headers(headers)
self.assertEqual(encoded["test"], "ni\xc3\xb1o")
self.assertEqual("ni\xc3\xb1o", encoded["test"])
def test_raw_request(self):
" Verify the path being used for HTTP requests reflects accurately. "
def check_request(method, path, **kwargs):
self.assertEqual(method, 'GET')
self.assertEqual('GET', method)
# NOTE(kmcdonald): See bug #1179984 for more details.
self.assertEqual(path, '/v1/images/detail')
self.assertEqual('/v1/images/detail', path)
http_client.HTTPConnection.request(
mox.IgnoreArg(),
@ -169,7 +169,7 @@ class TestClient(testtools.TestCase):
self.mock.ReplayAll()
resp, body = self.client.raw_request('GET', '/v1/images/detail')
self.assertEqual(resp, fake)
self.assertEqual(fake, resp)
def test_customized_path_raw_request(self):
"""
@ -178,13 +178,13 @@ class TestClient(testtools.TestCase):
"""
def check_request(method, path, **kwargs):
self.assertEqual(method, 'GET')
self.assertEqual(path, '/customized-path/v1/images/detail')
self.assertEqual('GET', method)
self.assertEqual('/customized-path/v1/images/detail', path)
# NOTE(yuyangbj): see bug 1230032 to get more info
endpoint = 'http://example.com:9292/customized-path'
client = http.HTTPClient(endpoint, token=u'abc123')
self.assertEqual(client.endpoint_path, '/customized-path')
self.assertEqual('/customized-path', client.endpoint_path)
http_client.HTTPConnection.request(
mox.IgnoreArg(),
@ -197,15 +197,15 @@ class TestClient(testtools.TestCase):
self.mock.ReplayAll()
resp, body = client.raw_request('GET', '/v1/images/detail')
self.assertEqual(resp, fake)
self.assertEqual(fake, resp)
def test_raw_request_no_content_length(self):
with tempfile.NamedTemporaryFile() as test_file:
test_file.write(b'abcd')
test_file.seek(0)
data_length = 4
self.assertEqual(client_utils.get_file_size(test_file),
data_length)
self.assertEqual(data_length,
client_utils.get_file_size(test_file))
exp_resp = {'body': test_file}
exp_resp['headers'] = {'Content-Length': str(data_length),
@ -236,8 +236,8 @@ class TestClient(testtools.TestCase):
test_file.write(b'abcd')
test_file.seek(0)
data_length = 4
self.assertEqual(client_utils.get_file_size(test_file),
data_length)
self.assertEqual(data_length,
client_utils.get_file_size(test_file))
exp_resp = {'body': test_file}
# NOTE: we expect the actual file size to be overridden by the
@ -269,7 +269,7 @@ class TestClient(testtools.TestCase):
with tempfile.NamedTemporaryFile() as test_file:
test_file.write(b'abcd')
test_file.seek(0)
self.assertEqual(client_utils.get_file_size(test_file), 4)
self.assertEqual(4, client_utils.get_file_size(test_file))
def mock_request(url, method, **kwargs):
return kwargs
@ -313,7 +313,7 @@ class TestClient(testtools.TestCase):
endpoint = 'http://example.com:9292'
test_client = http.HTTPClient(endpoint, token=u'adc123')
actual = (test_client.get_connection_class('https'))
self.assertEqual(actual, http.VerifiedHTTPSConnection)
self.assertEqual(http.VerifiedHTTPSConnection, actual)
def test_get_connections_kwargs_http(self):
endpoint = 'http://example.com:9292'
@ -399,7 +399,7 @@ class TestResponseBodyIterator(testtools.TestCase):
resp = utils.FakeResponse({}, six.StringIO('X' * 98304))
iterator = http.ResponseBodyIterator(resp)
chunks = list(iterator)
self.assertEqual(chunks, ['X' * 65536, 'X' * 32768])
self.assertEqual(['X' * 65536, 'X' * 32768], chunks)
def test_integrity_check_with_correct_checksum(self):
resp = utils.FakeResponse({}, six.StringIO('CCC'))
@ -432,4 +432,4 @@ class TestResponseBodyIterator(testtools.TestCase):
resp = utils.FakeResponse(
{'content-length': str(size)}, six.StringIO('BB'))
body = http.ResponseBodyIterator(resp)
self.assertEqual(len(body), size)
self.assertEqual(size, len(body))

View File

@ -32,10 +32,10 @@ class TestProgressBarWrapper(testtools.TestCase):
sys.stdout = output = test_utils.FakeTTYStdout()
# Consume iterator.
data = list(progressbar.VerboseIteratorWrapper(iterator, size))
self.assertEqual(data, ['X'] * 100)
self.assertEqual(['X'] * 100, data)
self.assertEqual(
output.getvalue(),
'[%s>] 100%%\n' % ('=' * 29)
'[%s>] 100%%\n' % ('=' * 29),
output.getvalue()
)
finally:
sys.stdout = saved_stdout
@ -52,8 +52,8 @@ class TestProgressBarWrapper(testtools.TestCase):
while chunk:
chunk = file_obj.read(chunksize)
self.assertEqual(
output.getvalue(),
'[%s>] 100%%\n' % ('=' * 29)
'[%s>] 100%%\n' % ('=' * 29),
output.getvalue()
)
finally:
sys.stdout = saved_stdout
@ -70,6 +70,6 @@ class TestProgressBarWrapper(testtools.TestCase):
while chunk:
chunk = file_obj.read(chunksize)
# If stdout is not a tty progress bar should do nothing.
self.assertEqual(output.getvalue(), '')
self.assertEqual('', output.getvalue())
finally:
sys.stdout = saved_stdout

View File

@ -122,7 +122,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
file(cert_file).read())
# The expected cert should have CN=0.0.0.0
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
self.assertEqual('0.0.0.0', cert.get_subject().commonName)
try:
conn = http.VerifiedHTTPSConnection('0.0.0.0', 0)
conn.verify_callback(None, cert, 0, 0, 1)
@ -137,7 +137,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
file(cert_file).read())
# The expected cert should have CN=*.pong.example.com
self.assertEqual(cert.get_subject().commonName, '*.pong.example.com')
self.assertEqual('*.pong.example.com', cert.get_subject().commonName)
try:
conn = http.VerifiedHTTPSConnection('ping.pong.example.com', 0)
conn.verify_callback(None, cert, 0, 0, 1)
@ -152,7 +152,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
file(cert_file).read())
# The expected cert should have CN=0.0.0.0
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
self.assertEqual('0.0.0.0', cert.get_subject().commonName)
try:
conn = http.VerifiedHTTPSConnection('alt1.example.com', 0)
conn.verify_callback(None, cert, 0, 0, 1)
@ -173,7 +173,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
file(cert_file).read())
# The expected cert should have CN=0.0.0.0
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
self.assertEqual('0.0.0.0', cert.get_subject().commonName)
try:
conn = http.VerifiedHTTPSConnection('alt1.example.com', 0)
conn.verify_callback(None, cert, 0, 0, 1)
@ -201,7 +201,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
file(cert_file).read())
# The expected cert should have CN=0.0.0.0
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
self.assertEqual('0.0.0.0', cert.get_subject().commonName)
try:
conn = http.VerifiedHTTPSConnection('mismatch.example.com', 0)
except Exception:
@ -218,8 +218,8 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
cert = crypto.load_certificate(crypto.FILETYPE_PEM,
file(cert_file).read())
# The expected expired cert has CN=openstack.example.com
self.assertEqual(cert.get_subject().commonName,
'openstack.example.com')
self.assertEqual('openstack.example.com',
cert.get_subject().commonName)
try:
conn = http.VerifiedHTTPSConnection('openstack.example.com', 0)
except Exception:

View File

@ -34,9 +34,9 @@ class TestUtils(testtools.TestCase):
size = 98304
file_obj = six.StringIO('X' * size)
try:
self.assertEqual(utils.get_file_size(file_obj), size)
self.assertEqual(size, utils.get_file_size(file_obj))
# Check that get_file_size didn't change original file position.
self.assertEqual(file_obj.tell(), 0)
self.assertEqual(0, file_obj.tell())
finally:
file_obj.close()
@ -45,9 +45,9 @@ class TestUtils(testtools.TestCase):
file_obj = six.StringIO('X' * size)
file_obj.seek(consumed)
try:
self.assertEqual(utils.get_file_size(file_obj), size)
self.assertEqual(size, utils.get_file_size(file_obj))
# Check that get_file_size didn't change original file position.
self.assertEqual(file_obj.tell(), consumed)
self.assertEqual(consumed, file_obj.tell())
finally:
file_obj.close()
@ -77,7 +77,7 @@ class TestUtils(testtools.TestCase):
finally:
sys.stdout = saved_stdout
self.assertEqual(output_list.getvalue(), '''\
self.assertEqual('''\
+-------+--------------+
| ID | Name |
+-------+--------------+
@ -85,9 +85,10 @@ class TestUtils(testtools.TestCase):
| 1 | another |
| 65536 | veeeery long |
+-------+--------------+
''')
''',
output_list.getvalue())
self.assertEqual(output_dict.getvalue(), '''\
self.assertEqual('''\
+----------+--------------------------------------------------------------+
| Property | Value |
+----------+--------------------------------------------------------------+
@ -96,7 +97,8 @@ class TestUtils(testtools.TestCase):
| | eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee |
| | ery long value |
+----------+--------------------------------------------------------------+
''')
''',
output_dict.getvalue())
def test_exception_to_str(self):
class FakeException(Exception):
@ -104,11 +106,11 @@ class TestUtils(testtools.TestCase):
raise UnicodeError()
ret = utils.exception_to_str(Exception('error message'))
self.assertEqual(ret, 'error message')
self.assertEqual('error message', ret)
ret = utils.exception_to_str(Exception('\xa5 error message'))
self.assertEqual(ret, ' error message')
self.assertEqual(' error message', ret)
ret = utils.exception_to_str(FakeException('\xa5 error message'))
self.assertEqual(ret, "Caught '%(exception)s' exception." %
{'exception': 'FakeException'})
self.assertEqual("Caught '%(exception)s' exception." %
{'exception': 'FakeException'}, ret)