Fix order of arguments in assertEqual

Some tests used incorrect order assertEqual(observed, expected).

The correct order expected by testtools is...

    def assertEqual(self, expected, observed, message=''):
        """Assert that 'expected' is equal to 'observed'.

        :param expected: The expected value.
        :param observed: The observed value.
        :param message: An optional message to include in the error.
        """

The string length of the sum of the results of repr(expected) and
repr(observed) is greater than 70, then, MismatchError message is
changed, as below.

  Ex.:
        raise mismatch_error
    MismatchError: !=:
    reference = '_123456789_123456789_bar'
    actual    = '_123456789_123456789_123456789_123456789_123456789'

Change-Id: Id02ddfb2ca03df7f432cff67a7bed182cccc4924
Closes-Bug: #1259292
changes/53/76453/4
KIYOHIRO ADACHI 9 years ago
parent b8e6ad0108
commit f3ec081497
  1. 6
      cinderclient/tests/test_base.py
  2. 4
      cinderclient/tests/test_client.py
  3. 12
      cinderclient/tests/test_http.py
  4. 32
      cinderclient/tests/test_service_catalog.py
  5. 2
      cinderclient/tests/test_shell.py
  6. 18
      cinderclient/tests/test_utils.py
  7. 22
      cinderclient/tests/v1/test_auth.py
  8. 8
      cinderclient/tests/v1/test_availability_zone.py
  9. 2
      cinderclient/tests/v1/test_limits.py
  10. 22
      cinderclient/tests/v1/test_services.py
  11. 2
      cinderclient/tests/v1/test_shell.py
  12. 22
      cinderclient/tests/v2/test_auth.py
  13. 8
      cinderclient/tests/v2/test_availability_zone.py
  14. 2
      cinderclient/tests/v2/test_limits.py
  15. 22
      cinderclient/tests/v2/test_services.py

@ -25,14 +25,14 @@ class BaseTest(utils.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_eq(self):
# Two resources of the same type with the same id: equal

@ -25,11 +25,11 @@ class ClientTest(utils.TestCase):
def test_get_client_class_v1(self):
output = cinderclient.client.get_client_class('1')
self.assertEqual(output, cinderclient.v1.client.Client)
self.assertEqual(cinderclient.v1.client.Client, output)
def test_get_client_class_v2(self):
output = cinderclient.client.get_client_class('2')
self.assertEqual(output, cinderclient.v2.client.Client)
self.assertEqual(cinderclient.v2.client.Client, output)
def test_get_client_class_unknown(self):
self.assertRaises(cinderclient.exceptions.UnsupportedVersion,

@ -87,7 +87,7 @@ class ClientTest(utils.TestCase):
headers=headers,
**self.TEST_REQUEST_BASE)
# Automatic JSON parsing
self.assertEqual(body, {"hi": "there"})
self.assertEqual({"hi": "there"}, body)
test_get_call()
@ -111,7 +111,7 @@ class ClientTest(utils.TestCase):
resp, body = cl.get("/hi")
test_get_call()
self.assertEqual(self.requests, [])
self.assertEqual([], self.requests)
def test_get_retry_500(self):
cl = get_authed_client(retries=1)
@ -128,7 +128,7 @@ class ClientTest(utils.TestCase):
resp, body = cl.get("/hi")
test_get_call()
self.assertEqual(self.requests, [])
self.assertEqual([], self.requests)
def test_get_retry_connection_error(self):
cl = get_authed_client(retries=1)
@ -162,7 +162,7 @@ class ClientTest(utils.TestCase):
resp, body = cl.get("/hi")
self.assertRaises(exceptions.ClientException, test_get_call)
self.assertEqual(self.requests, [mock_request])
self.assertEqual([mock_request], self.requests)
def test_get_no_retry_400(self):
cl = get_authed_client(retries=0)
@ -179,7 +179,7 @@ class ClientTest(utils.TestCase):
resp, body = cl.get("/hi")
self.assertRaises(exceptions.BadRequest, test_get_call)
self.assertEqual(self.requests, [mock_request])
self.assertEqual([mock_request], self.requests)
def test_get_retry_400_socket(self):
cl = get_authed_client(retries=1)
@ -196,7 +196,7 @@ class ClientTest(utils.TestCase):
resp, body = cl.get("/hi")
test_get_call()
self.assertEqual(self.requests, [])
self.assertEqual([], self.requests)
def test_post(self):
cl = get_authed_client()

@ -240,10 +240,10 @@ class ServiceCatalogTest(utils.TestCase):
self.assertRaises(exceptions.AmbiguousEndpoints, sc.url_for,
service_type='compute')
self.assertEqual(sc.url_for('tenantId', '1', service_type='compute'),
"https://compute1.host/v1/1234")
self.assertEqual(sc.url_for('tenantId', '2', service_type='compute'),
"https://compute1.host/v1/3456")
self.assertEqual("https://compute1.host/v1/1234",
sc.url_for('tenantId', '1', service_type='compute'))
self.assertEqual("https://compute1.host/v1/3456",
sc.url_for('tenantId', '2', service_type='compute'))
self.assertRaises(exceptions.EndpointNotFound, sc.url_for,
"region", "South", service_type='compute')
@ -253,15 +253,15 @@ class ServiceCatalogTest(utils.TestCase):
self.assertRaises(exceptions.AmbiguousEndpoints, sc.url_for,
service_type='volume')
self.assertEqual(sc.url_for('tenantId', '1', service_type='volume'),
"https://volume1.host/v1/1234")
self.assertEqual(sc.url_for('tenantId', '2', service_type='volume'),
"https://volume1.host/v1/3456")
self.assertEqual("https://volume1.host/v1/1234",
sc.url_for('tenantId', '1', service_type='volume'))
self.assertEqual("https://volume1.host/v1/3456",
sc.url_for('tenantId', '2', service_type='volume'))
self.assertEqual(sc.url_for('tenantId', '2', service_type='volumev2'),
"https://volume1.host/v2/3456")
self.assertEqual(sc.url_for('tenantId', '2', service_type='volumev2'),
"https://volume1.host/v2/3456")
self.assertEqual("https://volume1.host/v2/3456",
sc.url_for('tenantId', '2', service_type='volumev2'))
self.assertEqual("https://volume1.host/v2/3456",
sc.url_for('tenantId', '2', service_type='volumev2'))
self.assertRaises(exceptions.EndpointNotFound, sc.url_for,
"region", "North", service_type='volume')
@ -269,7 +269,7 @@ class ServiceCatalogTest(utils.TestCase):
def test_compatibility_service_type(self):
sc = service_catalog.ServiceCatalog(SERVICE_COMPATIBILITY_CATALOG)
self.assertEqual(sc.url_for('tenantId', '1', service_type='volume'),
"https://volume1.host/v2/1234")
self.assertEqual(sc.url_for('tenantId', '2', service_type='volume'),
"https://volume1.host/v2/3456")
self.assertEqual("https://volume1.host/v2/1234",
sc.url_for('tenantId', '1', service_type='volume'))
self.assertEqual("https://volume1.host/v2/3456",
sc.url_for('tenantId', '2', service_type='volume'))

@ -51,7 +51,7 @@ class ShellTest(utils.TestCase):
_shell.main(argstr.split())
except SystemExit:
exc_type, exc_value, exc_traceback = sys.exc_info()
self.assertEqual(exc_value.code, 0)
self.assertEqual(0, exc_value.code)
finally:
out = sys.stdout.getvalue()
sys.stdout.close()

@ -73,23 +73,23 @@ class FindResourceTestCase(test_utils.TestCase):
def test_find_by_integer_id(self):
output = utils.find_resource(self.manager, 1234)
self.assertEqual(output, self.manager.get('1234'))
self.assertEqual(self.manager.get('1234'), output)
def test_find_by_str_id(self):
output = utils.find_resource(self.manager, '1234')
self.assertEqual(output, self.manager.get('1234'))
self.assertEqual(self.manager.get('1234'), output)
def test_find_by_uuid(self):
output = utils.find_resource(self.manager, UUID)
self.assertEqual(output, self.manager.get(UUID))
self.assertEqual(self.manager.get(UUID), output)
def test_find_by_str_name(self):
output = utils.find_resource(self.manager, 'entity_one')
self.assertEqual(output, self.manager.get('1234'))
self.assertEqual(self.manager.get('1234'), output)
def test_find_by_str_displayname(self):
output = utils.find_resource(self.manager, 'entity_three')
self.assertEqual(output, self.manager.get('4242'))
self.assertEqual(self.manager.get('4242'), output)
class CaptureStdout(object):
@ -113,14 +113,14 @@ class PrintListTestCase(test_utils.TestCase):
to_print = [Row(a=1, b=2), Row(a=3, b=4)]
with CaptureStdout() as cso:
utils.print_list(to_print, ['a', 'b'])
self.assertEqual(cso.read(), """\
self.assertEqual("""\
+---+---+
| a | b |
+---+---+
| 1 | 2 |
| 3 | 4 |
+---+---+
""")
""", cso.read())
def test_print_list_with_generator(self):
Row = collections.namedtuple('Row', ['a', 'b'])
@ -130,11 +130,11 @@ class PrintListTestCase(test_utils.TestCase):
yield row
with CaptureStdout() as cso:
utils.print_list(gen_rows(), ['a', 'b'])
self.assertEqual(cso.read(), """\
self.assertEqual("""\
+---+---+
| a | b |
+---+---+
| 1 | 2 |
| 3 | 4 |
+---+---+
""")
""", cso.read())

@ -82,9 +82,9 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
endpoints = resp["access"]["serviceCatalog"][0]['endpoints']
public_url = endpoints[0]["publicURL"].rstrip('/')
self.assertEqual(cs.client.management_url, public_url)
self.assertEqual(public_url, cs.client.management_url)
token_id = resp["access"]["token"]["id"]
self.assertEqual(cs.client.auth_token, token_id)
self.assertEqual(token_id, cs.client.auth_token)
test_auth_call()
@ -155,11 +155,11 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
endpoints = resp["access"]["serviceCatalog"][0]['endpoints']
public_url = endpoints[0]["publicURL"].rstrip('/')
self.assertEqual(cs.client.management_url, public_url)
self.assertEqual(public_url, cs.client.management_url)
token_id = resp["access"]["token"]["id"]
self.assertEqual(cs.client.auth_token, token_id)
self.assertEqual(token_id, cs.client.auth_token)
tenant_id = resp["access"]["token"]["tenant"]["id"]
self.assertEqual(cs.client.tenant_id, tenant_id)
self.assertEqual(tenant_id, cs.client.tenant_id)
test_auth_call()
@ -258,9 +258,9 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
resp = dict_correct_response
endpoints = resp["access"]["serviceCatalog"][0]['endpoints']
public_url = endpoints[0]["publicURL"].rstrip('/')
self.assertEqual(cs.client.management_url, public_url)
self.assertEqual(public_url, cs.client.management_url)
token_id = resp["access"]["token"]["id"]
self.assertEqual(cs.client.auth_token, token_id)
self.assertEqual(token_id, cs.client.auth_token)
test_auth_call()
@ -294,10 +294,10 @@ class AuthenticationTests(utils.TestCase):
headers=headers,
**self.TEST_REQUEST_BASE)
self.assertEqual(cs.client.management_url,
auth_response.headers['x-server-management-url'])
self.assertEqual(cs.client.auth_token,
auth_response.headers['x-auth-token'])
self.assertEqual(auth_response.headers['x-server-management-url'],
cs.client.management_url)
self.assertEqual(auth_response.headers['x-auth-token'],
cs.client.auth_token)
test_auth_call()

@ -28,8 +28,8 @@ cs = fakes.FakeClient()
class AvailabilityZoneTest(utils.TestCase):
def _assertZone(self, zone, name, status):
self.assertEqual(zone.zoneName, name)
self.assertEqual(zone.zoneState, status)
self.assertEqual(name, zone.zoneName)
self.assertEqual(status, zone.zoneState)
def test_list_availability_zone(self):
zones = cs.availability_zones.list(detailed=False)
@ -47,7 +47,7 @@ class AvailabilityZoneTest(utils.TestCase):
z0 = shell._treeizeAvailabilityZone(zones[0])
z1 = shell._treeizeAvailabilityZone(zones[1])
self.assertEqual((len(z0), len(z1)), (1, 1))
self.assertEqual((1, 1), (len(z0), len(z1)))
self._assertZone(z0[0], l0[0], l0[1])
self._assertZone(z1[0], l1[0], l1[1])
@ -76,7 +76,7 @@ class AvailabilityZoneTest(utils.TestCase):
z1 = shell._treeizeAvailabilityZone(zones[1])
z2 = shell._treeizeAvailabilityZone(zones[2])
self.assertEqual((len(z0), len(z1), len(z2)), (3, 3, 1))
self.assertEqual((3, 3, 1), (len(z0), len(z1), len(z2)))
self._assertZone(z0[0], l0[0], l0[1])
self._assertZone(z0[1], l1[0], l1[1])

@ -161,4 +161,4 @@ class TestLimitsManager(utils.TestCase):
self.assertIsInstance(lim, limits.Limits)
for l in lim.absolute:
self.assertEqual(l, l1)
self.assertEqual(l1, l)

@ -26,44 +26,44 @@ class ServicesTest(utils.TestCase):
def test_list_services(self):
svs = cs.services.list()
cs.assert_called('GET', '/os-services')
self.assertEqual(len(svs), 3)
self.assertEqual(3, len(svs))
[self.assertIsInstance(s, services.Service) for s in svs]
def test_list_services_with_hostname(self):
svs = cs.services.list(host='host2')
cs.assert_called('GET', '/os-services?host=host2')
self.assertEqual(len(svs), 2)
self.assertEqual(2, len(svs))
[self.assertIsInstance(s, services.Service) for s in svs]
[self.assertEqual(s.host, 'host2') for s in svs]
[self.assertEqual('host2', s.host) for s in svs]
def test_list_services_with_binary(self):
svs = cs.services.list(binary='cinder-volume')
cs.assert_called('GET', '/os-services?binary=cinder-volume')
self.assertEqual(len(svs), 2)
self.assertEqual(2, len(svs))
[self.assertIsInstance(s, services.Service) for s in svs]
[self.assertEqual(s.binary, 'cinder-volume') for s in svs]
[self.assertEqual('cinder-volume', s.binary) for s in svs]
def test_list_services_with_host_binary(self):
svs = cs.services.list('host2', 'cinder-volume')
cs.assert_called('GET', '/os-services?host=host2&binary=cinder-volume')
self.assertEqual(len(svs), 1)
self.assertEqual(1, len(svs))
[self.assertIsInstance(s, services.Service) for s in svs]
[self.assertEqual(s.host, 'host2') for s in svs]
[self.assertEqual(s.binary, 'cinder-volume') for s in svs]
[self.assertEqual('host2', s.host) for s in svs]
[self.assertEqual('cinder-volume', s.binary) for s in svs]
def test_services_enable(self):
s = cs.services.enable('host1', 'cinder-volume')
values = {"host": "host1", 'binary': 'cinder-volume'}
cs.assert_called('PUT', '/os-services/enable', values)
self.assertIsInstance(s, services.Service)
self.assertEqual(s.status, 'enabled')
self.assertEqual('enabled', s.status)
def test_services_disable(self):
s = cs.services.disable('host1', 'cinder-volume')
values = {"host": "host1", 'binary': 'cinder-volume'}
cs.assert_called('PUT', '/os-services/disable', values)
self.assertIsInstance(s, services.Service)
self.assertEqual(s.status, 'disabled')
self.assertEqual('disabled', s.status)
def test_services_disable_log_reason(self):
s = cs.services.disable_log_reason(
@ -72,4 +72,4 @@ class ServicesTest(utils.TestCase):
"disabled_reason": "disable bad host"}
cs.assert_called('PUT', '/os-services/disable-log-reason', values)
self.assertIsInstance(s, services.Service)
self.assertEqual(s.status, 'disabled')
self.assertEqual('disabled', s.status)

@ -94,7 +94,7 @@ class ShellTest(utils.TestCase):
for input in inputs:
args = Arguments(metadata=input[0])
self.assertEqual(shell_v1._extract_metadata(args), input[1])
self.assertEqual(input[1], shell_v1._extract_metadata(args))
def test_translate_volume_keys(self):
cs = fakes.FakeClient()

@ -85,9 +85,9 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
endpoints = resp["access"]["serviceCatalog"][0]['endpoints']
public_url = endpoints[0]["publicURL"].rstrip('/')
self.assertEqual(cs.client.management_url, public_url)
self.assertEqual(public_url, cs.client.management_url)
token_id = resp["access"]["token"]["id"]
self.assertEqual(cs.client.auth_token, token_id)
self.assertEqual(token_id, cs.client.auth_token)
test_auth_call()
@ -158,11 +158,11 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
endpoints = resp["access"]["serviceCatalog"][0]['endpoints']
public_url = endpoints[0]["publicURL"].rstrip('/')
self.assertEqual(cs.client.management_url, public_url)
self.assertEqual(public_url, cs.client.management_url)
token_id = resp["access"]["token"]["id"]
self.assertEqual(cs.client.auth_token, token_id)
self.assertEqual(token_id, cs.client.auth_token)
tenant_id = resp["access"]["token"]["tenant"]["id"]
self.assertEqual(cs.client.tenant_id, tenant_id)
self.assertEqual(tenant_id, cs.client.tenant_id)
test_auth_call()
@ -261,9 +261,9 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
resp = dict_correct_response
endpoints = resp["access"]["serviceCatalog"][0]['endpoints']
public_url = endpoints[0]["publicURL"].rstrip('/')
self.assertEqual(cs.client.management_url, public_url)
self.assertEqual(public_url, cs.client.management_url)
token_id = resp["access"]["token"]["id"]
self.assertEqual(cs.client.auth_token, token_id)
self.assertEqual(token_id, cs.client.auth_token)
test_auth_call()
@ -297,10 +297,10 @@ class AuthenticationTests(utils.TestCase):
headers=headers,
**self.TEST_REQUEST_BASE)
self.assertEqual(cs.client.management_url,
auth_response.headers['x-server-management-url'])
self.assertEqual(cs.client.auth_token,
auth_response.headers['x-auth-token'])
self.assertEqual(auth_response.headers['x-server-management-url'],
cs.client.management_url)
self.assertEqual(auth_response.headers['x-auth-token'],
cs.client.auth_token)
test_auth_call()

@ -28,8 +28,8 @@ cs = fakes.FakeClient()
class AvailabilityZoneTest(utils.TestCase):
def _assertZone(self, zone, name, status):
self.assertEqual(zone.zoneName, name)
self.assertEqual(zone.zoneState, status)
self.assertEqual(name, zone.zoneName)
self.assertEqual(status, zone.zoneState)
def test_list_availability_zone(self):
zones = cs.availability_zones.list(detailed=False)
@ -47,7 +47,7 @@ class AvailabilityZoneTest(utils.TestCase):
z0 = shell._treeizeAvailabilityZone(zones[0])
z1 = shell._treeizeAvailabilityZone(zones[1])
self.assertEqual((len(z0), len(z1)), (1, 1))
self.assertEqual((1, 1), (len(z0), len(z1)))
self._assertZone(z0[0], l0[0], l0[1])
self._assertZone(z1[0], l1[0], l1[1])
@ -76,7 +76,7 @@ class AvailabilityZoneTest(utils.TestCase):
z1 = shell._treeizeAvailabilityZone(zones[1])
z2 = shell._treeizeAvailabilityZone(zones[2])
self.assertEqual((len(z0), len(z1), len(z2)), (3, 3, 1))
self.assertEqual((3, 3, 1), (len(z0), len(z1), len(z2)))
self._assertZone(z0[0], l0[0], l0[1])
self._assertZone(z0[1], l1[0], l1[1])

@ -161,4 +161,4 @@ class TestLimitsManager(utils.TestCase):
self.assertIsInstance(lim, limits.Limits)
for l in lim.absolute:
self.assertEqual(l, l1)
self.assertEqual(l1, l)

@ -26,44 +26,44 @@ class ServicesTest(utils.TestCase):
def test_list_services(self):
svs = cs.services.list()
cs.assert_called('GET', '/os-services')
self.assertEqual(len(svs), 3)
self.assertEqual(3, len(svs))
[self.assertIsInstance(s, services.Service) for s in svs]
def test_list_services_with_hostname(self):
svs = cs.services.list(host='host2')
cs.assert_called('GET', '/os-services?host=host2')
self.assertEqual(len(svs), 2)
self.assertEqual(2, len(svs))
[self.assertIsInstance(s, services.Service) for s in svs]
[self.assertEqual(s.host, 'host2') for s in svs]
[self.assertEqual('host2', s.host) for s in svs]
def test_list_services_with_binary(self):
svs = cs.services.list(binary='cinder-volume')
cs.assert_called('GET', '/os-services?binary=cinder-volume')
self.assertEqual(len(svs), 2)
self.assertEqual(2, len(svs))
[self.assertIsInstance(s, services.Service) for s in svs]
[self.assertEqual(s.binary, 'cinder-volume') for s in svs]
[self.assertEqual('cinder-volume', s.binary) for s in svs]
def test_list_services_with_host_binary(self):
svs = cs.services.list('host2', 'cinder-volume')
cs.assert_called('GET', '/os-services?host=host2&binary=cinder-volume')
self.assertEqual(len(svs), 1)
self.assertEqual(1, len(svs))
[self.assertIsInstance(s, services.Service) for s in svs]
[self.assertEqual(s.host, 'host2') for s in svs]
[self.assertEqual(s.binary, 'cinder-volume') for s in svs]
[self.assertEqual('host2', s.host) for s in svs]
[self.assertEqual('cinder-volume', s.binary) for s in svs]
def test_services_enable(self):
s = cs.services.enable('host1', 'cinder-volume')
values = {"host": "host1", 'binary': 'cinder-volume'}
cs.assert_called('PUT', '/os-services/enable', values)
self.assertIsInstance(s, services.Service)
self.assertEqual(s.status, 'enabled')
self.assertEqual('enabled', s.status)
def test_services_disable(self):
s = cs.services.disable('host1', 'cinder-volume')
values = {"host": "host1", 'binary': 'cinder-volume'}
cs.assert_called('PUT', '/os-services/disable', values)
self.assertIsInstance(s, services.Service)
self.assertEqual(s.status, 'disabled')
self.assertEqual('disabled', s.status)
def test_services_disable_log_reason(self):
s = cs.services.disable_log_reason(
@ -72,4 +72,4 @@ class ServicesTest(utils.TestCase):
"disabled_reason": "disable bad host"}
cs.assert_called('PUT', '/os-services/disable-log-reason', values)
self.assertIsInstance(s, services.Service)
self.assertEqual(s.status, 'disabled')
self.assertEqual('disabled', s.status)

Loading…
Cancel
Save