Merge "Fix the parameter order of assertEqual in glanceclient test"

This commit is contained in:
Jenkins
2014-04-21 09:12:09 +00:00
committed by Gerrit Code Review
5 changed files with 49 additions and 47 deletions

View File

@@ -23,14 +23,14 @@ class TestBase(testtools.TestCase):
def test_resource_repr(self): def test_resource_repr(self):
r = base.Resource(None, dict(foo="bar", baz="spam")) 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): def test_getid(self):
self.assertEqual(base.getid(4), 4) self.assertEqual(4, base.getid(4))
class TmpObject(object): class TmpObject(object):
id = 4 id = 4
self.assertEqual(base.getid(TmpObject), 4) self.assertEqual(4, base.getid(TmpObject))
def test_two_resources_with_same_id_are_equal(self): def test_two_resources_with_same_id_are_equal(self):
# Two resources of the same type with the same id: equal # 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', kwargs = {'token': u'fake-token',
'identity_headers': identity_headers} 'identity_headers': identity_headers}
http_client_object = http.HTTPClient(self.endpoint, **kwargs) 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. self.assertTrue(http_client_object.identity_headers.
get('X-Auth-Token') is None) get('X-Auth-Token') is None)
@@ -75,7 +75,7 @@ class TestClient(testtools.TestCase):
kwargs = {'token': u'fake-token', kwargs = {'token': u'fake-token',
'identity_headers': identity_headers} 'identity_headers': identity_headers}
http_client_object = http.HTTPClient(self.endpoint, **kwargs) 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. self.assertTrue(http_client_object.identity_headers.
get('X-Auth-Token') is None) get('X-Auth-Token') is None)
@@ -143,20 +143,20 @@ class TestClient(testtools.TestCase):
headers = {"test": u'ni\xf1o'} headers = {"test": u'ni\xf1o'}
resp, body = self.client.raw_request('GET', '/v1/images/detail', resp, body = self.client.raw_request('GET', '/v1/images/detail',
headers=headers) headers=headers)
self.assertEqual(resp, fake) self.assertEqual(fake, resp)
def test_headers_encoding(self): def test_headers_encoding(self):
headers = {"test": u'ni\xf1o'} headers = {"test": u'ni\xf1o'}
encoded = self.client.encode_headers(headers) 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): def test_raw_request(self):
" Verify the path being used for HTTP requests reflects accurately. " " Verify the path being used for HTTP requests reflects accurately. "
def check_request(method, path, **kwargs): def check_request(method, path, **kwargs):
self.assertEqual(method, 'GET') self.assertEqual('GET', method)
# NOTE(kmcdonald): See bug #1179984 for more details. # NOTE(kmcdonald): See bug #1179984 for more details.
self.assertEqual(path, '/v1/images/detail') self.assertEqual('/v1/images/detail', path)
http_client.HTTPConnection.request( http_client.HTTPConnection.request(
mox.IgnoreArg(), mox.IgnoreArg(),
@@ -169,7 +169,7 @@ class TestClient(testtools.TestCase):
self.mock.ReplayAll() self.mock.ReplayAll()
resp, body = self.client.raw_request('GET', '/v1/images/detail') 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): def test_customized_path_raw_request(self):
""" """
@@ -178,13 +178,13 @@ class TestClient(testtools.TestCase):
""" """
def check_request(method, path, **kwargs): def check_request(method, path, **kwargs):
self.assertEqual(method, 'GET') self.assertEqual('GET', method)
self.assertEqual(path, '/customized-path/v1/images/detail') self.assertEqual('/customized-path/v1/images/detail', path)
# NOTE(yuyangbj): see bug 1230032 to get more info # NOTE(yuyangbj): see bug 1230032 to get more info
endpoint = 'http://example.com:9292/customized-path' endpoint = 'http://example.com:9292/customized-path'
client = http.HTTPClient(endpoint, token=u'abc123') 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( http_client.HTTPConnection.request(
mox.IgnoreArg(), mox.IgnoreArg(),
@@ -197,15 +197,15 @@ class TestClient(testtools.TestCase):
self.mock.ReplayAll() self.mock.ReplayAll()
resp, body = client.raw_request('GET', '/v1/images/detail') 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): def test_raw_request_no_content_length(self):
with tempfile.NamedTemporaryFile() as test_file: with tempfile.NamedTemporaryFile() as test_file:
test_file.write(b'abcd') test_file.write(b'abcd')
test_file.seek(0) test_file.seek(0)
data_length = 4 data_length = 4
self.assertEqual(client_utils.get_file_size(test_file), self.assertEqual(data_length,
data_length) client_utils.get_file_size(test_file))
exp_resp = {'body': test_file} exp_resp = {'body': test_file}
exp_resp['headers'] = {'Content-Length': str(data_length), exp_resp['headers'] = {'Content-Length': str(data_length),
@@ -236,8 +236,8 @@ class TestClient(testtools.TestCase):
test_file.write(b'abcd') test_file.write(b'abcd')
test_file.seek(0) test_file.seek(0)
data_length = 4 data_length = 4
self.assertEqual(client_utils.get_file_size(test_file), self.assertEqual(data_length,
data_length) client_utils.get_file_size(test_file))
exp_resp = {'body': test_file} exp_resp = {'body': test_file}
# NOTE: we expect the actual file size to be overridden by the # 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: with tempfile.NamedTemporaryFile() as test_file:
test_file.write(b'abcd') test_file.write(b'abcd')
test_file.seek(0) 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): def mock_request(url, method, **kwargs):
return kwargs return kwargs
@@ -313,7 +313,7 @@ class TestClient(testtools.TestCase):
endpoint = 'http://example.com:9292' endpoint = 'http://example.com:9292'
test_client = http.HTTPClient(endpoint, token=u'adc123') test_client = http.HTTPClient(endpoint, token=u'adc123')
actual = (test_client.get_connection_class('https')) actual = (test_client.get_connection_class('https'))
self.assertEqual(actual, http.VerifiedHTTPSConnection) self.assertEqual(http.VerifiedHTTPSConnection, actual)
def test_get_connections_kwargs_http(self): def test_get_connections_kwargs_http(self):
endpoint = 'http://example.com:9292' endpoint = 'http://example.com:9292'
@@ -399,7 +399,7 @@ class TestResponseBodyIterator(testtools.TestCase):
resp = utils.FakeResponse({}, six.StringIO('X' * 98304)) resp = utils.FakeResponse({}, six.StringIO('X' * 98304))
iterator = http.ResponseBodyIterator(resp) iterator = http.ResponseBodyIterator(resp)
chunks = list(iterator) 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): def test_integrity_check_with_correct_checksum(self):
resp = utils.FakeResponse({}, six.StringIO('CCC')) resp = utils.FakeResponse({}, six.StringIO('CCC'))
@@ -432,4 +432,4 @@ class TestResponseBodyIterator(testtools.TestCase):
resp = utils.FakeResponse( resp = utils.FakeResponse(
{'content-length': str(size)}, six.StringIO('BB')) {'content-length': str(size)}, six.StringIO('BB'))
body = http.ResponseBodyIterator(resp) 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() sys.stdout = output = test_utils.FakeTTYStdout()
# Consume iterator. # Consume iterator.
data = list(progressbar.VerboseIteratorWrapper(iterator, size)) data = list(progressbar.VerboseIteratorWrapper(iterator, size))
self.assertEqual(data, ['X'] * 100) self.assertEqual(['X'] * 100, data)
self.assertEqual( self.assertEqual(
output.getvalue(), '[%s>] 100%%\n' % ('=' * 29),
'[%s>] 100%%\n' % ('=' * 29) output.getvalue()
) )
finally: finally:
sys.stdout = saved_stdout sys.stdout = saved_stdout
@@ -52,8 +52,8 @@ class TestProgressBarWrapper(testtools.TestCase):
while chunk: while chunk:
chunk = file_obj.read(chunksize) chunk = file_obj.read(chunksize)
self.assertEqual( self.assertEqual(
output.getvalue(), '[%s>] 100%%\n' % ('=' * 29),
'[%s>] 100%%\n' % ('=' * 29) output.getvalue()
) )
finally: finally:
sys.stdout = saved_stdout sys.stdout = saved_stdout
@@ -70,6 +70,6 @@ class TestProgressBarWrapper(testtools.TestCase):
while chunk: while chunk:
chunk = file_obj.read(chunksize) chunk = file_obj.read(chunksize)
# If stdout is not a tty progress bar should do nothing. # If stdout is not a tty progress bar should do nothing.
self.assertEqual(output.getvalue(), '') self.assertEqual('', output.getvalue())
finally: finally:
sys.stdout = saved_stdout sys.stdout = saved_stdout

View File

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

View File

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