Fix argument order for assertEqual to (expected, observed)

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.
The following patch fixes this issue

TrivialFix

Change-Id: I62de332ff5f526e7c50038a0a6e4975c779cad3d
Closes-Bug: #1259292
Closes-Bug: #1277104
This commit is contained in:
reedip 2016-01-06 15:45:14 +09:00
parent 8f9ccd7594
commit a1ea116aa2
6 changed files with 38 additions and 41 deletions

View File

@ -93,7 +93,7 @@ for test in tests:
# which would result in only the last test being added.
def _meta_verify_test_builder(self):
self.assertEqual(
duplicated, [], "Expected no test identifiers to be "
[], duplicated, "Expected no test identifiers to be "
"duplicated but found {0}".format(len(duplicated))
)

View File

@ -39,7 +39,7 @@ class TestRoleList(TestRoles):
titles, rows = self.cmd.take_action(parsed_args)
self.assertEqual(titles, ('uuid', 'name', 'version', 'description'))
self.assertEqual(('uuid', 'name', 'version', 'description'), titles)
self.assertEqual([
('UUID1', 'Role 1 Name', 1, 'Mock Role 1'),
('UUID2', 'Role 2 Name', 2, 'Mock Role 2')

View File

@ -48,8 +48,8 @@ class ClientGetClientTest(tutils.TestCase):
@mock.patch.object(client, 'Client')
def test_it_works(self, mocked_Client):
mocked_Client.return_value = 'client'
self.assertEqual(client.get_client(self.api_version, **self.kwargs),
'client')
self.assertEqual('client',
client.get_client(self.api_version, **self.kwargs))
mocked_Client.assert_called_with(self.api_version,
**self.client_kwargs)

View File

@ -31,7 +31,7 @@ class PlanManagerTest(tutils.TestCase):
self.assertThat('_get', tutils.IsMethodOn(self.pm))
self.pm._get = mock.Mock(return_value='fake_plan')
self.assertEqual(self.pm.get('fake_plan'), 'fake_plan')
self.assertEqual('fake_plan', self.pm.get('fake_plan'))
self.pm._get.assert_called_with('/plans/fake_plan')
def test_get_404(self):
@ -39,7 +39,7 @@ class PlanManagerTest(tutils.TestCase):
self.assertThat('_get', tutils.IsMethodOn(self.pm))
self.pm._get = mock.Mock(return_value=None)
self.assertEqual(self.pm.get('fake_plan'), None)
self.assertEqual(None, self.pm.get('fake_plan'))
self.pm._get.assert_called_with('/plans/fake_plan')
def test_list(self):
@ -47,7 +47,7 @@ class PlanManagerTest(tutils.TestCase):
self.assertThat('_list', tutils.IsMethodOn(self.pm))
self.pm._list = mock.Mock(return_value=['fake_plan'])
self.assertEqual(self.pm.list(), ['fake_plan'])
self.assertEqual(['fake_plan'], self.pm.list())
self.pm._list.assert_called_with('/plans')
def test_create(self):
@ -55,9 +55,8 @@ class PlanManagerTest(tutils.TestCase):
self.assertThat('_post', tutils.IsMethodOn(self.pm))
self.pm._post = mock.Mock(return_value=['fake_plan'])
self.assertEqual(
self.pm.create(dummy='dummy plan data'),
['fake_plan'])
self.assertEqual(['fake_plan'],
self.pm.create(dummy='dummy plan data'))
self.pm._post.assert_called_with(
'/plans',
@ -68,10 +67,9 @@ class PlanManagerTest(tutils.TestCase):
self.assertThat('_patch', tutils.IsMethodOn(self.pm))
self.pm._patch = mock.Mock(return_value=['fake_plan'])
self.assertEqual(
self.pm.patch('42', [{'name': 'dummy',
'value': 'dummy plan data'}]),
['fake_plan'])
self.assertEqual(['fake_plan'],
self.pm.patch('42', [{'name': 'dummy',
'value': 'dummy plan data'}]))
self.pm._patch.assert_called_with(
'/plans/42',
@ -83,26 +81,26 @@ class PlanManagerTest(tutils.TestCase):
self.assertThat('_delete', tutils.IsMethodOn(self.pm))
self.pm._delete = mock.Mock(return_value=None)
self.assertEqual(self.pm.delete(42), None)
self.assertEqual(None, self.pm.delete(42))
self.pm._delete.assert_called_with('/plans/42')
def test_roles_path_with_role_id(self):
"""Test for building path for Role using UUID."""
self.assertEqual(self.pm._roles_path('plan_42', 'role_abc'),
'/plans/plan_42/roles/role_abc')
self.assertEqual('/plans/plan_42/roles/role_abc',
self.pm._roles_path('plan_42', 'role_abc'))
def test_roles_path_without_role_id(self):
"""Test for building path for Role for POST requests."""
self.assertEqual(self.pm._roles_path('plan_42'),
'/plans/plan_42/roles')
self.assertEqual('/plans/plan_42/roles',
self.pm._roles_path('plan_42'))
def test_add_role(self):
"""Test assigning Role to a Plan."""
self.assertThat('_post', tutils.IsMethodOn(self.pm))
self.pm._post = mock.Mock(return_value='dummy plan')
self.assertEqual(self.pm.add_role('42', role_uuid='qwert12345'),
'dummy plan')
self.assertEqual('dummy plan',
self.pm.add_role('42', role_uuid='qwert12345'))
self.pm._post.assert_called_with(
'/plans/42/roles',
{'uuid': 'qwert12345'})
@ -115,15 +113,15 @@ class PlanManagerTest(tutils.TestCase):
self.assertThat('resource_class', tutils.IsMethodOn(self.pm))
self.pm.resource_class = mock.Mock(return_value='fake_plan')
self.assertEqual(self.pm.remove_role('42', role_uuid='qwert12345'),
'fake_plan')
self.assertEqual('fake_plan',
self.pm.remove_role('42', role_uuid='qwert12345'))
self.api.delete.assert_called_with('/plans/42/roles/qwert12345')
self.pm.resource_class.assert_called_with(
self.pm, api_delete_return_mock.json())
def test_templates_path(self):
self.assertEqual(self.pm._templates_path('42'),
'/plans/42/templates')
self.assertEqual('/plans/42/templates',
self.pm._templates_path('42'))
def test_templates(self):
"""Test a GET operation to retrieve the plan's templates."""
@ -131,7 +129,7 @@ class PlanManagerTest(tutils.TestCase):
self.pm._get = mock.MagicMock()
self.pm._get.return_value.to_dict.return_value = 'fake_templates_dict'
self.assertEqual(self.pm.templates('fake_plan'), 'fake_templates_dict')
self.assertEqual('fake_templates_dict', self.pm.templates('fake_plan'))
self.pm._get.assert_called_with('/plans/fake_plan/templates')
def test_roles_subresource(self):

View File

@ -176,7 +176,7 @@ class PlansShellTest(BasePlansShellTest):
parameters = [{'name': 'compute-1::count', 'value': '9'}]
self.shell.do_plan_scale(self.tuskar, args, outfile=self.outfile)
self.assertEqual(self.tuskar.plans.patch.call_count, 1)
self.assertEqual(1, self.tuskar.plans.patch.call_count)
self.assertEqual('plan_uuid', self.tuskar.plans.patch.call_args[0][0])
self.assertEqual(
@ -200,7 +200,7 @@ class PlansShellTest(BasePlansShellTest):
parameters = [{'name': 'compute-1::Flavor', 'value': 'baremetalssd'}]
self.shell.do_plan_flavor(self.tuskar, args, outfile=self.outfile)
self.assertEqual(self.tuskar.plans.patch.call_count, 1)
self.assertEqual(1, self.tuskar.plans.patch.call_count)
self.assertEqual('plan_uuid', self.tuskar.plans.patch.call_args[0][0])
self.assertEqual(
@ -218,7 +218,7 @@ class PlansShellTest(BasePlansShellTest):
parameters = [{'name': 'foo_name', 'value': 'foo_value'},
{'name': 'bar_name', 'value': 'bar_value'}]
self.shell.do_plan_patch(self.tuskar, args, outfile=self.outfile)
self.assertEqual(self.tuskar.plans.patch.call_count, 1)
self.assertEqual(1, self.tuskar.plans.patch.call_count)
self.assertEqual('plan_uuid',
self.tuskar.plans.patch.call_args[0][0])
@ -238,7 +238,7 @@ class PlansShellTest(BasePlansShellTest):
parameters = [{'name': 'foo_name', 'value': 'foo_value'},
{'name': 'bar_name', 'value': 'bar_value'}]
self.shell.do_plan_patch(self.tuskar, args, outfile=self.outfile)
self.assertEqual(self.tuskar.plans.patch.call_count, 1)
self.assertEqual(1, self.tuskar.plans.patch.call_count)
self.assertEqual('plan_uuid',
self.tuskar.plans.patch.call_args[0][0])
@ -257,7 +257,7 @@ class PlansShellTest(BasePlansShellTest):
{'name': 'bar_name', 'value': 'bar_value'}]
args.attributes = None
self.shell.do_plan_update(self.tuskar, args, outfile=self.outfile)
self.assertEqual(self.tuskar.plans.patch.call_count, 1)
self.assertEqual(1, self.tuskar.plans.patch.call_count)
self.assertEqual('plan_uuid',
self.tuskar.plans.patch.call_args[0][0])
@ -316,9 +316,8 @@ class PlansShellTest(BasePlansShellTest):
def test_filter_parameters_to_dict(self):
parameters = [{'name': 'compute-1::count', 'value': '2'}]
self.assertEqual(
self.shell.filter_parameters_to_dict(parameters, 'count'),
{'compute-1': '2'}
)
{'compute-1': '2'},
self.shell.filter_parameters_to_dict(parameters, 'count'))
@mock.patch('tuskarclient.v2.plans_shell.print', create=True)
@mock.patch('tuskarclient.v2.plans_shell.os.mkdir', create=True)
@ -357,8 +356,8 @@ class PlansShellTest(BasePlansShellTest):
mock_mkdir.assert_any_call('outdir/subdir')
# Checks and creation of nested directory
self.assertEqual(mock_exists.call_count, 2)
self.assertEqual(mock_makedirs.call_count, 1)
self.assertEqual(2, mock_exists.call_count)
self.assertEqual(1, mock_makedirs.call_count)
mock_makedirs.assert_called_with('outdir/subdir/nested')
self.tuskar.plans.templates.assert_called_with('plan_uuid')
@ -367,18 +366,18 @@ class PlansShellTest(BasePlansShellTest):
mock_open.assert_any_call('outdir/subdir/name_bar', 'w+')
mock_open.assert_any_call('outdir/subdir/nested/name_baz', 'w+')
mock_open.assert_any_call('outdir/subdir/nested/name_zom', 'w+')
self.assertEqual(mock_open.call_count, 4)
self.assertEqual(4, mock_open.call_count)
mock_opened_file = mock_open.return_value.__enter__.return_value
mock_opened_file.write.assert_any_call('value_foo')
mock_opened_file.write.assert_any_call('value_bar')
mock_opened_file.write.assert_any_call('value_baz')
mock_opened_file.write.assert_any_call('value_zom')
self.assertEqual(mock_opened_file.write.call_count, 4)
self.assertEqual(4, mock_opened_file.write.call_count)
mock_print.assert_any_call('The following templates will be written:')
mock_print.assert_any_call('outdir/subdir/name_foo')
mock_print.assert_any_call('outdir/subdir/name_bar')
mock_print.assert_any_call('outdir/subdir/nested/name_baz')
mock_print.assert_any_call('outdir/subdir/nested/name_zom')
self.assertEqual(mock_print.call_count, 5)
self.assertEqual(5, mock_print.call_count)

View File

@ -30,12 +30,12 @@ class RoleManagerTest(tutils.TestCase):
self.assertThat('_list', tutils.IsMethodOn(self.rm))
self.rm._list = mock.Mock(return_value=['fake_role'])
self.assertEqual(self.rm.list(), ['fake_role'])
self.assertEqual(['fake_role'], self.rm.list())
self.rm._list.assert_called_with('/roles')
def test_path_without_id(self):
"""Test _path returns list uri."""
self.assertEqual(self.rm._path(), '/roles')
self.assertEqual('/roles', self.rm._path())
def test_path_with_id(self):
"""Test _path returns single item uri."""