Fix order of arguments in assertEqual

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

The correct order expected by testtools is
assertEqual(expected, observed).

At some places, corrected argument order for assertNotEqual method as well.

Change-Id: I6d63e77620b8dd9d6415424783b99a7e2e381a22
Partial-Bug: #1259292
This commit is contained in:
Rajesh Tailor 2015-09-10 23:30:35 -07:00
parent b5414f1cbe
commit 3f74823fb8
13 changed files with 63 additions and 64 deletions

View File

@ -30,7 +30,7 @@ class FormatUrlTests(unit.BaseTestCase):
actual_url = core.format_url(url_template, values)
expected_url = 'http://server:9090/A/B'
self.assertEqual(actual_url, expected_url)
self.assertEqual(expected_url, actual_url)
def test_raises_malformed_on_missing_key(self):
self.assertRaises(exception.MalformedEndpoint,

View File

@ -256,9 +256,9 @@ class BaseNotificationTest(test_v3.RestfulTestCase):
return
self.assertTrue(len(self._notifications) > 0)
note = self._notifications[-1]
self.assertEqual(note['operation'], operation)
self.assertEqual(note['resource_id'], resource_id)
self.assertEqual(note['resource_type'], resource_type)
self.assertEqual(operation, note['operation'])
self.assertEqual(resource_id, note['resource_id'])
self.assertEqual(resource_type, note['resource_type'])
self.assertTrue(note['send_notification_called'])
def _assert_last_audit(self, resource_id, operation, resource_type,
@ -810,13 +810,13 @@ class CadfNotificationsWrapperTestCase(test_v3.RestfulTestCase):
def _assert_last_note(self, action, user_id, event_type=None):
self.assertTrue(self._notifications)
note = self._notifications[-1]
self.assertEqual(note['action'], action)
self.assertEqual(action, note['action'])
initiator = note['initiator']
self.assertEqual(initiator.id, user_id)
self.assertEqual(initiator.host.address, self.LOCAL_HOST)
self.assertEqual(user_id, initiator.id)
self.assertEqual(self.LOCAL_HOST, initiator.host.address)
self.assertTrue(note['send_notification_called'])
if event_type:
self.assertEqual(note['event_type'], event_type)
self.assertEqual(event_type, note['event_type'])
def _assert_event(self, role_id, project=None, domain=None,
user=None, group=None, inherit=False):
@ -944,7 +944,7 @@ class CadfNotificationsWrapperTestCase(test_v3.RestfulTestCase):
self.assertTrue(self._notifications)
note = self._notifications[-1]
self.assertEqual(note['action'], 'created.role_assignment')
self.assertEqual('created.role_assignment', note['action'])
self.assertTrue(note['send_notification_called'])
self._assert_event(self.role_id, project=tenant_id, user=self.user_id)
@ -958,7 +958,7 @@ class CadfNotificationsWrapperTestCase(test_v3.RestfulTestCase):
self.assertTrue(self._notifications)
note = self._notifications[-1]
self.assertEqual(note['action'], 'deleted.role_assignment')
self.assertEqual('deleted.role_assignment', note['action'])
self.assertTrue(note['send_notification_called'])
self._assert_event(self.role_id, project=self.project_id,

View File

@ -32,14 +32,14 @@ class TestModelDictMixin(unit.BaseTestCase):
def test_creating_a_model_instance_from_a_dict(self):
d = {'id': utils.new_uuid(), 'text': utils.new_uuid()}
m = TestModel.from_dict(d)
self.assertEqual(m.id, d['id'])
self.assertEqual(m.text, d['text'])
self.assertEqual(d['id'], m.id)
self.assertEqual(d['text'], m.text)
def test_creating_a_dict_from_a_model_instance(self):
m = TestModel(id=utils.new_uuid(), text=utils.new_uuid())
d = m.to_dict()
self.assertEqual(m.id, d['id'])
self.assertEqual(m.text, d['text'])
self.assertEqual(d['id'], m.id)
self.assertEqual(d['text'], m.text)
def test_creating_a_model_instance_from_an_invalid_dict(self):
d = {'id': utils.new_uuid(), 'text': utils.new_uuid(), 'extra': None}
@ -49,4 +49,4 @@ class TestModelDictMixin(unit.BaseTestCase):
expected = {'id': utils.new_uuid(), 'text': utils.new_uuid()}
m = TestModel(id=expected['id'], text=expected['text'])
m.extra = 'this should not be in the dictionary'
self.assertEqual(m.to_dict(), expected)
self.assertEqual(expected, m.to_dict())

View File

@ -117,8 +117,7 @@ class RestfulTestCase(unit.TestCase):
self.assertResponseStatus(response, http_client.NO_CONTENT)
"""
self.assertEqual(
response.status_code,
expected_status,
expected_status, response.status_code,
'Status code %s is not %s, as expected\n\n%s' %
(response.status_code, expected_status, response.body))
@ -133,9 +132,9 @@ class RestfulTestCase(unit.TestCase):
Subclasses can override this function based on the expected response.
"""
self.assertEqual(response.status_code, expected_status)
self.assertEqual(expected_status, response.status_code)
error = response.result['error']
self.assertEqual(error['code'], response.status_code)
self.assertEqual(response.status_code, error['code'])
self.assertIsNotNone(error.get('title'))
def _to_content_type(self, body, headers, content_type=None):

View File

@ -282,7 +282,7 @@ class EndpointFilterTokenRequestTestCase(TestExtensionCase):
require_catalog=True,
endpoint_filter=True,
ep_filter_assoc=1)
self.assertEqual(r.result['token']['project']['id'], project['id'])
self.assertEqual(project['id'], r.result['token']['project']['id'])
def test_default_scoped_token_using_endpoint_filter(self):
"""Verify endpoints from default scoped token filtered."""
@ -302,8 +302,8 @@ class EndpointFilterTokenRequestTestCase(TestExtensionCase):
require_catalog=True,
endpoint_filter=True,
ep_filter_assoc=1)
self.assertEqual(r.result['token']['project']['id'],
self.project['id'])
self.assertEqual(self.project['id'],
r.result['token']['project']['id'])
def test_scoped_token_with_no_catalog_using_endpoint_filter(self):
"""Verify endpoint filter does not affect no catalog."""
@ -320,8 +320,8 @@ class EndpointFilterTokenRequestTestCase(TestExtensionCase):
self.assertValidProjectScopedTokenResponse(
r,
require_catalog=False)
self.assertEqual(r.result['token']['project']['id'],
self.project['id'])
self.assertEqual(self.project['id'],
r.result['token']['project']['id'])
def test_invalid_endpoint_project_association(self):
"""Verify an invalid endpoint-project association is handled."""
@ -360,8 +360,8 @@ class EndpointFilterTokenRequestTestCase(TestExtensionCase):
require_catalog=True,
endpoint_filter=True,
ep_filter_assoc=1)
self.assertEqual(r.result['token']['project']['id'],
self.project['id'])
self.assertEqual(self.project['id'],
r.result['token']['project']['id'])
def test_disabled_endpoint(self):
"""Test that a disabled endpoint is handled."""
@ -941,7 +941,7 @@ class EndpointGroupCRUDTestCase(TestExtensionCase):
'project_id': self.default_domain_project_id}
r = self.get(endpoints_url)
endpoints = self.assertValidEndpointListResponse(r)
self.assertEqual(len(endpoints), 2)
self.assertEqual(2, len(endpoints))
# Now remove project endpoint group association
url = self._get_project_endpoint_group_url(
@ -955,7 +955,7 @@ class EndpointGroupCRUDTestCase(TestExtensionCase):
r = self.get(endpoints_url)
endpoints = self.assertValidEndpointListResponse(r)
self.assertEqual(len(endpoints), 1)
self.assertEqual(1, len(endpoints))
def test_endpoint_group_project_cleanup_with_project(self):
# create endpoint group

View File

@ -183,7 +183,7 @@ class TestMapped(unit.TestCase):
# make sure Mapped plugin got invoked with the correct payload
((context, auth_payload, auth_context),
kwargs) = authenticate.call_args
self.assertEqual(auth_payload['protocol'], method_name)
self.assertEqual(method_name, auth_payload['protocol'])
def test_supporting_multiple_methods(self):
for method_name in ['saml2', 'openid', 'x509']:

View File

@ -1014,8 +1014,8 @@ class IdentityTests(AssignmentTestHelperMixin):
user_id=user_ref['id'],
tenant_id=project_ref['id'])
self.assertEqual(set(role_list),
set([r['id'] for r in role_ref_list]))
self.assertEqual(set([r['id'] for r in role_ref_list]),
set(role_list))
def test_get_role_by_user_and_project(self):
roles_ref = self.assignment_api.get_roles_for_user_and_project(
@ -2746,7 +2746,7 @@ class IdentityTests(AssignmentTestHelperMixin):
ref = self.resource_api.create_project(sub_project['id'], sub_project)
# The parent_id should be set to the domain_id
self.assertEqual(ref['parent_id'], project['id'])
self.assertEqual(project['id'], ref['parent_id'])
def test_check_leaf_projects(self):
projects_hierarchy = self._create_projects_hierarchy()
@ -3552,7 +3552,7 @@ class IdentityTests(AssignmentTestHelperMixin):
self.resource_api.update_project(leaf_project['id'], leaf_project)
project_ref = self.resource_api.get_project(leaf_project['id'])
self.assertEqual(project_ref['enabled'], leaf_project['enabled'])
self.assertEqual(leaf_project['enabled'], project_ref['enabled'])
def test_disable_hierarchical_not_leaf_project(self):
projects_hierarchy = self._create_projects_hierarchy()
@ -6600,7 +6600,7 @@ class FilterTests(filtering.FilterTests):
hints.add_filter('name', entity_list[10]['name'])
entities = self._list_entities(entity)(hints=hints)
self.assertEqual(1, len(entities))
self.assertEqual(entities[0]['id'], entity_list[10]['id'])
self.assertEqual(entity_list[10]['id'], entities[0]['id'])
# Check the driver has removed the filter from the list hints
self.assertFalse(hints.get_exact_filter_by_name('name'))
self._delete_test_data(entity, entity_list)

View File

@ -151,22 +151,22 @@ class LdapPoolCommonTestMixin(object):
# Open 3 connections first
with _get_conn() as _: # conn1
self.assertEqual(len(ldappool_cm), 1)
self.assertEqual(1, len(ldappool_cm))
with _get_conn() as _: # conn2
self.assertEqual(len(ldappool_cm), 2)
self.assertEqual(2, len(ldappool_cm))
with _get_conn() as _: # conn2
_.unbind_ext_s()
self.assertEqual(len(ldappool_cm), 3)
self.assertEqual(3, len(ldappool_cm))
# Then open 3 connections again and make sure size does not grow
# over 3
with _get_conn() as _: # conn1
self.assertEqual(len(ldappool_cm), 1)
self.assertEqual(1, len(ldappool_cm))
with _get_conn() as _: # conn2
self.assertEqual(len(ldappool_cm), 2)
self.assertEqual(2, len(ldappool_cm))
with _get_conn() as _: # conn3
_.unbind_ext_s()
self.assertEqual(len(ldappool_cm), 3)
self.assertEqual(3, len(ldappool_cm))
def test_password_change_with_pool(self):
old_password = self.user_sna['password']

View File

@ -176,7 +176,7 @@ class SqlIdentity(SqlTests, test_backend.IdentityTests):
def test_password_hashed(self):
session = sql.get_session()
user_ref = self.identity_api._get_user(session, self.user_foo['id'])
self.assertNotEqual(user_ref['password'], self.user_foo['password'])
self.assertNotEqual(self.user_foo['password'], user_ref['password'])
def test_delete_user_with_project_association(self):
user = {'name': uuid.uuid4().hex,
@ -550,12 +550,12 @@ class SqlToken(SqlTests, test_backend.TokenTests):
if i == 0:
# The first time the batch iterator returns, it should return
# the first result that comes back from the database.
self.assertEqual(x, 'test')
self.assertEqual('test', x)
elif i == 1:
# The second time, the database range function should return
# nothing, so the batch iterator returns the result of the
# upper_bound function
self.assertEqual(x, "final value")
self.assertEqual("final value", x)
else:
self.fail("range batch function returned more than twice")
@ -568,15 +568,15 @@ class SqlToken(SqlTests, test_backend.TokenTests):
tok = token_sql.Token()
db2_strategy = tok._expiry_range_strategy('ibm_db_sa')
self.assertIsInstance(db2_strategy, functools.partial)
self.assertEqual(db2_strategy.func, token_sql._expiry_range_batched)
self.assertEqual(db2_strategy.keywords, {'batch_size': 100})
self.assertEqual(token_sql._expiry_range_batched, db2_strategy.func)
self.assertEqual({'batch_size': 100}, db2_strategy.keywords)
def test_expiry_range_strategy_mysql(self):
tok = token_sql.Token()
mysql_strategy = tok._expiry_range_strategy('mysql')
self.assertIsInstance(mysql_strategy, functools.partial)
self.assertEqual(mysql_strategy.func, token_sql._expiry_range_batched)
self.assertEqual(mysql_strategy.keywords, {'batch_size': 1000})
self.assertEqual(token_sql._expiry_range_batched, mysql_strategy.func)
self.assertEqual({'batch_size': 1000}, mysql_strategy.keywords)
class SqlCatalog(SqlTests, test_backend.CatalogTests):
@ -890,7 +890,7 @@ class SqlCredential(SqlTests):
def _validateCredentialList(self, retrieved_credentials,
expected_credentials):
self.assertEqual(len(retrieved_credentials), len(expected_credentials))
self.assertEqual(len(expected_credentials), len(retrieved_credentials))
retrived_ids = [c['id'] for c in retrieved_credentials]
for cred in expected_credentials:
self.assertIn(cred['id'], retrived_ids)

View File

@ -82,7 +82,7 @@ class V2CatalogTestCase(rest.RestfulTestCase):
self.assertIn('endpoint', response.result)
self.assertIn('id', response.result['endpoint'])
for field, value in req_body['endpoint'].items():
self.assertEqual(response.result['endpoint'][field], value)
self.assertEqual(value, response.result['endpoint'][field])
def test_endpoint_create_with_null_adminurl(self):
req_body, response = self._endpoint_create(adminurl=None)

View File

@ -124,7 +124,7 @@ class CredentialTestCase(CredentialBaseTestCase):
self.assertValidCredentialListResponse(r_ec2, ref=ec2_resp)
self.assertEqual('ec2', cred_ec2['type'])
self.assertEqual(cred_ec2['id'], ec2_credential['id'])
self.assertEqual(ec2_credential['id'], cred_ec2['id'])
def test_list_credentials_filtered_by_type_and_user_id(self):
"""Call ``GET /credentials?user_id={user_id}&type={type}``."""
@ -200,8 +200,8 @@ class CredentialTestCase(CredentialBaseTestCase):
self.assertValidCredentialResponse(r, ref)
# Assert credential id is same as hash of access key id for
# ec2 credentials
self.assertEqual(r.result['credential']['id'],
hashlib.sha256(blob['access']).hexdigest())
self.assertEqual(hashlib.sha256(blob['access']).hexdigest(),
r.result['credential']['id'])
# Create second ec2 credential with the same access key id and check
# for conflict.
self.post(
@ -241,8 +241,8 @@ class CredentialTestCase(CredentialBaseTestCase):
self.assertValidCredentialResponse(r, ref)
# Assert credential id is not same as hash of access key id for
# non-ec2 credentials
self.assertNotEqual(r.result['credential']['id'],
hashlib.sha256(blob['access']).hexdigest())
self.assertNotEqual(hashlib.sha256(blob['access']).hexdigest(),
r.result['credential']['id'])
def test_create_ec2_credential_with_missing_project_id(self):
"""Call ``POST /credentials`` for creating ec2
@ -342,8 +342,8 @@ class TestCredentialTrustScoped(test_v3.RestfulTestCase):
# Assert credential id is same as hash of access key id for
# ec2 credentials
self.assertEqual(r.result['credential']['id'],
hashlib.sha256(blob['access']).hexdigest())
self.assertEqual(hashlib.sha256(blob['access']).hexdigest(),
r.result['credential']['id'])
# Create second ec2 credential with the same access key id and check
# for conflict.
@ -399,8 +399,8 @@ class TestCredentialEc2(CredentialBaseTestCase):
body={'credential': ref})
self.assertValidCredentialResponse(r, ref)
# Assert credential id is same as hash of access key id
self.assertEqual(r.result['credential']['id'],
hashlib.sha256(blob['access']).hexdigest())
self.assertEqual(hashlib.sha256(blob['access']).hexdigest(),
r.result['credential']['id'])
cred_blob = json.loads(r.result['credential']['blob'])
self.assertEqual(blob, cred_blob)

View File

@ -539,7 +539,7 @@ class IdentityV3toV2MethodsTestCase(unit.TestCase):
user_list = [self.user1, self.user2, self.user3, self.user4]
updated_list = controller.V2Controller.v3_to_v2_user(user_list)
self.assertEqual(len(updated_list), len(user_list))
self.assertEqual(len(user_list), len(updated_list))
for i, ref in enumerate(updated_list):
# Order should not change.

View File

@ -85,7 +85,7 @@ class ApplicationTest(BaseWSGITest):
def test_response_content_type(self):
req = self._make_request()
resp = req.get_response(self.app)
self.assertEqual(resp.content_type, 'application/json')
self.assertEqual('application/json', resp.content_type)
def test_query_string_available(self):
class FakeApp(wsgi.Application):
@ -93,7 +93,7 @@ class ApplicationTest(BaseWSGITest):
return context['query_string']
req = self._make_request(url='/?1=2')
resp = req.get_response(FakeApp())
self.assertEqual(jsonutils.loads(resp.body), {'1': '2'})
self.assertEqual({'1': '2'}, jsonutils.loads(resp.body))
def test_headers_available(self):
class FakeApp(wsgi.Application):
@ -182,7 +182,7 @@ class ApplicationTest(BaseWSGITest):
resp = wsgi.render_response({'id': uuid.uuid4().hex}, method='HEAD')
self.assertEqual(http_client.OK, resp.status_int)
self.assertEqual(b'', resp.body)
self.assertNotEqual(resp.headers.get('Content-Length'), '0')
self.assertNotEqual('0', resp.headers.get('Content-Length'))
self.assertEqual('application/json', resp.headers.get('Content-Type'))
def test_application_local_config(self):
@ -346,8 +346,8 @@ class LocalizedResponseTest(unit.TestCase):
def test_static_translated_string_is_lazy_translatable(self):
# Statically created message strings are an object that can get
# lazy-translated rather than a regular string.
self.assertNotEqual(type(exception.Unauthorized.message_format),
six.text_type)
self.assertNotEqual(six.text_type,
type(exception.Unauthorized.message_format))
@mock.patch.object(oslo_i18n, 'get_available_languages')
def test_get_localized_response(self, mock_gal):