Fix arg order of assertEqual and use assertTrue

assertEqual expects that the arguments provided to it should be
(expected, observed).If a particluar order is kept as a convention,
then it helps to provide a cleaner message to the developer if Unit Tests
fail. There are several Unit Test files where the arguments for assertEqual
have been swapped. This commit fixes the issue in python-neutronclient.

Additionally instead of using assertEqual(True,xxx), assertTrue(xxx) should
be used. The same has been fixed in this patch.

Partial-Bug: #1259292
Related-Bug: #1259292

Change-Id: I83ec45af75f61f8005a60efc8176db0df5cfbe9a
This commit is contained in:
Reedip Banerjee 2015-10-07 13:35:44 +05:30
parent cc1ce7a24f
commit 18ce7d9f2e
6 changed files with 21 additions and 21 deletions

View File

@ -140,7 +140,7 @@ class CLITestAuthNoAuth(testtools.TestCase):
self.requests.get(ENDPOINT_URL + '/resource')
self.client.do_request('/resource', 'GET')
self.assertEqual(url, self.requests.last_request.url)
self.assertEqual(self.client.endpoint_url, ENDPOINT_URL)
self.assertEqual(ENDPOINT_URL, self.client.endpoint_url)
class CLITestAuthKeystone(testtools.TestCase):
@ -177,7 +177,7 @@ class CLITestAuthKeystone(testtools.TestCase):
'auth_tenant_id': None,
'auth_user_id': None,
'endpoint_url': self.client.endpoint_url}
self.assertEqual(client_.get_auth_info(), expected)
self.assertEqual(expected, client_.get_auth_info())
def test_get_token(self):
auth_session, auth_plugin = setup_keystone_v2(self.requests)
@ -264,7 +264,7 @@ class CLITestAuthKeystone(testtools.TestCase):
username=USERNAME, tenant_name=TENANT_NAME, password=PASSWORD,
auth_url=AUTH_URL, region_name=REGION,
endpoint_url=ENDPOINT_OVERRIDE)
self.assertEqual(self.client.endpoint_url, ENDPOINT_OVERRIDE)
self.assertEqual(ENDPOINT_OVERRIDE, self.client.endpoint_url)
token_id = uuid.uuid4().hex
self.client.auth_token = token_id
@ -273,7 +273,7 @@ class CLITestAuthKeystone(testtools.TestCase):
self.client.do_request('/resource', 'GET')
self.assertEqual(self.client.endpoint_url, ENDPOINT_OVERRIDE)
self.assertEqual(ENDPOINT_OVERRIDE, self.client.endpoint_url)
self.assertEqual(token_id,
self.requests.last_request.headers['X-Auth-Token'])
@ -316,7 +316,7 @@ class CLITestAuthKeystone(testtools.TestCase):
auth_url=AUTH_URL, region_name=REGION,
session=auth_session, auth=auth_plugin)
self.assertEqual(self.client.endpoint_url, PUBLIC_ENDPOINT_URL)
self.assertEqual(PUBLIC_ENDPOINT_URL, self.client.endpoint_url)
# Test admin url
self.client = client.construct_http_client(
@ -324,7 +324,7 @@ class CLITestAuthKeystone(testtools.TestCase):
auth_url=AUTH_URL, region_name=REGION, endpoint_type='adminURL',
session=auth_session, auth=auth_plugin)
self.assertEqual(self.client.endpoint_url, ADMIN_ENDPOINT_URL)
self.assertEqual(ADMIN_ENDPOINT_URL, self.client.endpoint_url)
# Test public url
self.client = client.construct_http_client(
@ -332,7 +332,7 @@ class CLITestAuthKeystone(testtools.TestCase):
auth_url=AUTH_URL, region_name=REGION, endpoint_type='publicURL',
session=auth_session, auth=auth_plugin)
self.assertEqual(self.client.endpoint_url, PUBLIC_ENDPOINT_URL)
self.assertEqual(PUBLIC_ENDPOINT_URL, self.client.endpoint_url)
# Test internal url
self.client = client.construct_http_client(
@ -340,7 +340,7 @@ class CLITestAuthKeystone(testtools.TestCase):
auth_url=AUTH_URL, region_name=REGION, endpoint_type='internalURL',
session=auth_session, auth=auth_plugin)
self.assertEqual(self.client.endpoint_url, INTERNAL_ENDPOINT_URL)
self.assertEqual(INTERNAL_ENDPOINT_URL, self.client.endpoint_url)
# Test url that isn't found in the service catalog
self.client = client.construct_http_client(

View File

@ -612,7 +612,7 @@ class ClientV2TestJson(CLITestV20Base):
self.mox.UnsetStubs()
# test response with unicode
self.assertEqual(res_body, body)
self.assertEqual(body, res_body)
def test_do_request_error_without_response_body(self):
self.client.format = self.format
@ -765,10 +765,10 @@ class CLITestV20ExceptionHandler(CLITestV20Base):
def test_exception_status(self):
e = exceptions.BadRequest()
self.assertEqual(e.status_code, 400)
self.assertEqual(400, e.status_code)
e = exceptions.BadRequest(status_code=499)
self.assertEqual(e.status_code, 499)
self.assertEqual(499, e.status_code)
# SslCertificateValidationError has no explicit status_code,
# but should have a 'safe' defined fallback.
@ -776,7 +776,7 @@ class CLITestV20ExceptionHandler(CLITestV20Base):
self.assertIsNotNone(e.status_code)
e = exceptions.SslCertificateValidationError(status_code=599)
self.assertEqual(e.status_code, 599)
self.assertEqual(599, e.status_code)
def test_connection_failed(self):
self.mox.StubOutWithMock(self.client.httpclient, 'request')

View File

@ -281,11 +281,11 @@ class CLITestV20NetworkJSON(test_cli20.CLITestV20Base):
self.mox.VerifyAll()
self.mox.UnsetStubs()
_result = [x for x in result[1]]
self.assertEqual(len(_result), len(expected))
self.assertEqual(len(expected), len(_result))
for res, exp in zip(_result, expected):
self.assertEqual(len(res), len(exp))
for a, b in zip(res, exp):
self.assertEqual(a, b)
self.assertEqual(len(exp), len(res))
for obsrvd, expctd in zip(res, exp):
self.assertEqual(expctd, obsrvd)
def test_list_nets_extend_subnets(self):
data = [{'id': 'netid1', 'name': 'net1', 'subnets': ['mysubid1']},

View File

@ -384,7 +384,7 @@ class CLITestV20SecurityGroupsJSON(test_cli20.CLITestV20Base):
self.assertEqual(expected['cols'], result[0])
# Check data
_result = [x for x in result[1]]
self.assertEqual(len(_result), len(expected['data']))
self.assertEqual(len(expected['data']), len(_result))
for res, exp in zip(_result, expected['data']):
self.assertEqual(len(exp), len(res))
self.assertEqual(exp, res)

View File

@ -32,7 +32,7 @@ class TestCommandMeta(testtools.TestCase):
self.assertTrue(helpers.safe_hasattr(FakeCommand, 'log'))
self.assertIsInstance(FakeCommand.log, logging.getLoggerClass())
self.assertEqual(FakeCommand.log.name, __name__ + ".FakeCommand")
self.assertEqual(__name__ + ".FakeCommand", FakeCommand.log.name)
def test_neutron_command_log_defined_explicitly(self):
class FakeCommand(neutronV20.NeutronCommand):

View File

@ -77,7 +77,7 @@ class ShellTest(testtools.TestCase):
_shell.run(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:
stdout = sys.stdout.getvalue()
stderr = sys.stderr.getvalue()
@ -444,7 +444,7 @@ class ShellTest(testtools.TestCase):
def test_build_option_parser(self):
neutron_shell = openstack_shell.NeutronShell('2.0')
result = neutron_shell.build_option_parser('descr', '2.0')
self.assertEqual(True, isinstance(result, argparse.ArgumentParser))
self.assertIsInstance(result, argparse.ArgumentParser)
def test_main_with_unicode(self):
self.mox.StubOutClassWithMocks(openstack_shell, 'NeutronShell')
@ -457,7 +457,7 @@ class ShellTest(testtools.TestCase):
ret = openstack_shell.main(argv=argv)
self.mox.VerifyAll()
self.mox.UnsetStubs()
self.assertEqual(ret, 0)
self.assertEqual(0, ret)
def test_endpoint_option(self):
shell = openstack_shell.NeutronShell('2.0')