Fixed order of arguments in assertEqual

Some tests used incorrect order of arguments in
assertEqual(observed, expected). The correct order expected
by testtool is assertEqual(expected, observed).

Change-Id: I2f5d59b1115c82c2811aeb753404ac2c99d2746d
This commit is contained in:
sudhir_agarwal 2017-07-13 11:30:15 +05:30 committed by sudhir agarwal
parent f3e9bd6efd
commit fa132e33b1
18 changed files with 67 additions and 77 deletions

View File

@ -55,7 +55,7 @@ class ABClientTest(base.TestCase):
mock_abspath.return_value = ''
client = eisoo.create(self._context, None)
self.assertEqual(client._app_id, 'eisoo_app_id')
self.assertEqual('eisoo_app_id', client._app_id)
def tearDown(self):
super(ABClientTest, self).tearDown()

View File

@ -48,6 +48,6 @@ class SwiftClientTest(base.TestCase):
self.conf.set_override('swift_tenant_name', 'abcd', 'swift_client')
sc = swift.create(self._context, self.conf)
self.assertEqual(sc.authurl, auth_url)
self.assertEqual(sc.user, 'demo')
self.assertEqual(sc.key, 'secrete')
self.assertEqual(sc.os_options['tenant_name'], 'abcd')
self.assertEqual('demo', sc.user)
self.assertEqual('secrete', sc.key)
self.assertEqual('abcd', sc.os_options['tenant_name'])

View File

@ -67,7 +67,7 @@ class ServicesDbTestCase(base.TestCase):
'binary': 'binarytest',
'topic': 'topictest',
'report_count': 0})
self.assertEqual(service_ref['host'], 'hosttest')
self.assertEqual('hosttest', service_ref['host'])
def test_services_get(self):
service_ref = db.service_create(self.ctxt,
@ -77,8 +77,8 @@ class ServicesDbTestCase(base.TestCase):
'report_count': 0})
service_get_ref = db.service_get(self.ctxt, service_ref['id'])
self.assertEqual(service_ref['host'], 'hosttest1')
self.assertEqual(service_get_ref['host'], 'hosttest1')
self.assertEqual('hosttest1', service_ref['host'])
self.assertEqual('hosttest1', service_get_ref['host'])
def test_service_destroy(self):
service_ref = db.service_create(self.ctxt,
@ -103,8 +103,8 @@ class ServicesDbTestCase(base.TestCase):
'binary': 'binarytest4',
'topic': 'topictest4',
'report_count': 0})
self.assertEqual(service_ref['host'], 'hosttest3')
self.assertEqual(service_update_ref['host'], 'hosttest4')
self.assertEqual('hosttest3', service_ref['host'])
self.assertEqual('hosttest4', service_update_ref['host'])
def test_service_get_by_host_and_topic(self):
service_ref = db.service_create(self.ctxt,
@ -116,8 +116,8 @@ class ServicesDbTestCase(base.TestCase):
service_get_ref = db.service_get_by_host_and_topic(self.ctxt,
'hosttest5',
'topictest5')
self.assertEqual(service_ref['host'], 'hosttest5')
self.assertEqual(service_get_ref['host'], 'hosttest5')
self.assertEqual('hosttest5', service_ref['host'])
self.assertEqual('hosttest5', service_get_ref['host'])
class TriggerTestCase(base.TestCase):

View File

@ -79,10 +79,10 @@ class NetworkProtectablePluginTest(base.TestCase):
auth=None)
self.assertEqual('network',
neutronclient.httpclient.service_type)
self.assertEqual(neutronclient.httpclient.endpoint_url,
'http://127.0.0.1:9696')
self.assertEqual(novaclient.client.management_url,
'http://127.0.0.1:8774/v2.1/abcd')
self.assertEqual('http://127.0.0.1:9696',
neutronclient.httpclient.endpoint_url)
self.assertEqual('http://127.0.0.1:8774/v2.1/abcd',
novaclient.client.management_url)
@mock.patch('karbor.services.protection.client_factory.ClientFactory.'
'_generate_session')
@ -98,15 +98,15 @@ class NetworkProtectablePluginTest(base.TestCase):
auth=None)
self.assertEqual('network',
neutronclient.httpclient.service_type)
self.assertEqual(neutronclient.httpclient.endpoint_url,
'http://127.0.0.1:9696')
self.assertEqual(novaclient.client.management_url,
'http://127.0.0.1:8774/v2.1/abcd')
self.assertEqual('http://127.0.0.1:9696',
neutronclient.httpclient.endpoint_url)
self.assertEqual('http://127.0.0.1:8774/v2.1/abcd',
novaclient.client.management_url)
def test_get_resource_type(self):
plugin = NetworkProtectablePlugin(self._context)
self.assertEqual(plugin.get_resource_type(),
constants.NETWORK_RESOURCE_TYPE)
self.assertEqual(constants.NETWORK_RESOURCE_TYPE,
plugin.get_resource_type())
def test_get_parent_resource_type(self):
plugin = NetworkProtectablePlugin(self._context)

View File

@ -126,6 +126,6 @@ class VolumeProtectablePluginTest(base.TestCase):
mock_volume_list.return_value = volumes
self.assertEqual(
plugin.get_dependent_resources(self._context, project),
[Resource('OS::Cinder::Volume', '123', 'name123',
{'availability_zone': 'az1'})])
{'availability_zone': 'az1'})],
plugin.get_dependent_resources(self._context, project))

View File

@ -135,7 +135,7 @@ class BankSectionTest(base.TestCase):
bank.update_object(path, value1)
bank.update_object(path, value2)
res = bank.get_object(path)
self.assertEqual(res, value2)
self.assertEqual(value2, res)
bank.delete_object(path)
self.assertRaises(
exception.BankGetObjectFailed,
@ -162,18 +162,16 @@ class BankSectionTest(base.TestCase):
section.update_object("/KeyB", "value")
section.update_object("KeyC", "value")
expected_result = ["KeyA", "KeyB", "KeyC"]
self.assertEqual(list(section.list_objects("/")), expected_result)
self.assertEqual(list(section.list_objects("///")), expected_result)
self.assertEqual(list(section.list_objects(None)), expected_result)
self.assertEqual(list(section.list_objects("Key")), expected_result)
self.assertEqual(expected_result, list(section.list_objects("/")))
self.assertEqual(expected_result, list(section.list_objects("///")))
self.assertEqual(expected_result, list(section.list_objects(None)))
self.assertEqual(expected_result, list(section.list_objects("Key")))
self.assertEqual(
list(section.list_objects("/", limit=2)),
expected_result[:2],
)
list(section.list_objects("/", limit=2)))
self.assertEqual(
list(section.list_objects("/", limit=2, marker="KeyB")),
expected_result[2:4],
)
list(section.list_objects("/", limit=2, marker="KeyB")))
def test_read_only(self):
bank = self._create_test_bank()
@ -222,8 +220,8 @@ class BankSectionTest(base.TestCase):
mid_section = top_section.get_sub_section("/mid")
bottom_section = mid_section.get_sub_section("/bottom")
bottom_section.update_object("key", "value")
self.assertEqual(bank.get_object("/top/mid/bottom/key"), "value")
self.assertEqual(bottom_section.get_object("key"), "value")
self.assertEqual("value", bank.get_object("/top/mid/bottom/key"))
self.assertEqual("value", bottom_section.get_object("key"))
def test_nested_sections_list(self):
bank = self._create_test_bank()
@ -235,15 +233,13 @@ class BankSectionTest(base.TestCase):
bottom_section.update_object(key, "value")
list_result = set(bottom_section.list_objects(prefix="Key"))
self.assertEqual(list_result, set(keys))
self.assertEqual(set(keys), list_result)
self.assertEqual(
list(bottom_section.list_objects("/", limit=2)),
keys[:2],
)
list(bottom_section.list_objects("/", limit=2)))
self.assertEqual(
list(bottom_section.list_objects("/", limit=2, marker="KeyB")),
keys[2:4],
)
list(bottom_section.list_objects("/", limit=2, marker="KeyB")))
def test_nested_sections_read_only(self):
bank = self._create_test_bank()

View File

@ -435,5 +435,4 @@ class CinderProtectionPluginTest(base.TestCase):
def test_get_supported_resources_types(self):
types = self.plugin.get_supported_resources_types()
self.assertEqual(types,
[constants.VOLUME_RESOURCE_TYPE])
self.assertEqual([constants.VOLUME_RESOURCE_TYPE], types)

View File

@ -194,5 +194,4 @@ class CinderSnapshotProtectionPluginTest(base.TestCase):
def test_get_supported_resources_types(self):
types = self.plugin.get_supported_resources_types()
self.assertEqual(types,
[constants.VOLUME_RESOURCE_TYPE])
self.assertEqual([constants.VOLUME_RESOURCE_TYPE], types)

View File

@ -44,18 +44,18 @@ class FileSystemBankPluginTest(base.TestCase):
self.fs_bank_plugin.delete_object("/key")
object_file = (
self.fs_bank_plugin.object_container_path + "/key")
self.assertEqual(os.path.isfile(object_file), False)
self.assertEqual(False, os.path.isfile(object_file))
def test_get_object(self):
self.fs_bank_plugin.update_object("/key", "value")
value = self.fs_bank_plugin.get_object("/key")
self.assertEqual(value, "value")
self.assertEqual("value", value)
def test_list_objects(self):
self.fs_bank_plugin.update_object("/list/key-1", "value-1")
self.fs_bank_plugin.update_object("/list/key-2", "value-2")
objects = self.fs_bank_plugin.list_objects(prefix="/list")
self.assertEqual(len(objects), 2)
self.assertEqual(2, len(objects))
self.assertIn('key-1', objects)
self.assertIn('key-2', objects)
@ -66,7 +66,7 @@ class FileSystemBankPluginTest(base.TestCase):
self.fs_bank_plugin.object_container_path + "/key-1")
with open(object_file, "r") as f:
contents = f.read()
self.assertEqual(contents, "value-2")
self.assertEqual("value-2", contents)
def test_update_object_with_invaild_path(self):
self.assertRaises(exception.InvalidInput,
@ -79,4 +79,4 @@ class FileSystemBankPluginTest(base.TestCase):
{"key": "value"})
value = self.fs_bank_plugin.get_object(
"/index.json")
self.assertEqual(value, {"key": "value"})
self.assertEqual({"key": "value"}, value)

View File

@ -171,5 +171,4 @@ class GlanceProtectionPluginTest(base.TestCase):
def test_get_supported_resources_types(self):
types = self.plugin.get_supported_resources_types()
self.assertEqual(types,
[constants.IMAGE_RESOURCE_TYPE])
self.assertEqual([constants.IMAGE_RESOURCE_TYPE], types)

View File

@ -43,7 +43,7 @@ class GraphBuilderTest(base.TestCase):
for g, expected_result in test_matrix:
result = graph.build_graph(g.keys(), g.__getitem__)
self.assertEqual({node.value for node in result}, expected_result)
self.assertEqual(expected_result, {node.value for node in result})
def test_detect_cyclic_graph(self):
"""Test that cyclic graphs are detected"""
@ -101,7 +101,7 @@ class GraphBuilderTest(base.TestCase):
test_nodes = {test_root, }
result_graph = graph.build_graph(test_nodes, test_node_children)
test_root_node = result_graph[0]
self.assertEqual(len(test_root_node.child_nodes), 2)
self.assertEqual(2, len(test_root_node.child_nodes))
test_left_node = test_root_node.child_nodes[0]
test_right_node = test_root_node.child_nodes[1]

View File

@ -40,11 +40,11 @@ class ProtectionServiceTest(base.TestCase):
@mock.patch.object(protectable_registry.ProtectableRegistry,
'list_resource_types')
def test_list_protectable_types(self, mocker):
excepted = ["OS::Nova::Server",
expected = ["OS::Nova::Server",
"OS::Cinder::Volume"]
mocker.return_value = excepted
mocker.return_value = expected
result = self.pro_manager.list_protectable_types(None)
self.assertEqual(excepted, result)
self.assertEqual(expected, result)
def test_show_protectable_type(self):
def mock_plugins(self):
@ -139,7 +139,7 @@ class ProtectionServiceTest(base.TestCase):
context = mock.MagicMock()
cp = self.pro_manager.show_checkpoint(context, 'provider1',
'fake_checkpoint')
self.assertEqual(cp['id'], 'fake_checkpoint')
self.assertEqual('fake_checkpoint', cp['id'])
@mock.patch.object(provider.ProviderRegistry, 'show_provider')
@mock.patch.object(fakes.FakeCheckpointCollection, 'get')

View File

@ -194,5 +194,4 @@ class ManilaProtectionPluginTest(base.TestCase):
def test_get_supported_resources_types(self):
types = self.plugin.get_supported_resources_types()
self.assertEqual(types,
[constants.SHARE_RESOURCE_TYPE])
self.assertEqual([constants.SHARE_RESOURCE_TYPE], types)

View File

@ -309,8 +309,7 @@ class NeutronProtectionPluginTest(base.TestCase):
def test_get_supported_resources_types(self):
types = self.plugin.get_supported_resources_types()
self.assertEqual(types,
[constants.NETWORK_RESOURCE_TYPE])
self.assertEqual([constants.NETWORK_RESOURCE_TYPE], types)
@mock.patch('karbor.services.protection.clients.neutron.create')
def test_create_backup(self, mock_neutron_create):

View File

@ -383,9 +383,9 @@ class NovaProtectionPluginTest(base.TestCase):
{})
self.assertEqual(
constants.RESOURCE_STATUS_AVAILABLE,
fake_bank._plugin._objects[
"/resource_data/checkpoint_id/vm_id_2/status"],
constants.RESOURCE_STATUS_AVAILABLE
"/resource_data/checkpoint_id/vm_id_2/status"]
)
resource_definition = {
"resource_id": "vm_id_2",
@ -456,5 +456,4 @@ class NovaProtectionPluginTest(base.TestCase):
def test_get_supported_resources_types(self):
types = self.plugin.get_supported_resources_types()
self.assertEqual(types,
[constants.SERVER_RESOURCE_TYPE])
self.assertEqual([constants.SERVER_RESOURCE_TYPE], types)

View File

@ -86,5 +86,5 @@ class ProtectableRegistryTest(base.TestCase):
for item in g:
expected = set(g_dict[item.value])
found = set(child.value for child in item.child_nodes)
self.assertEqual(found, expected)
self.assertEqual(expected, found)
self.assert_graph(item.child_nodes, g_dict)

View File

@ -45,23 +45,23 @@ class ProviderRegistryTest(base.TestCase):
'_register_plugin')
def test_load_providers(self, mock_load_bank, mock_register_plugin):
pr = provider.ProviderRegistry()
self.assertEqual(mock_register_plugin.call_count, 1)
self.assertEqual(mock_load_bank.call_count, 1)
self.assertEqual(len(pr.providers), 1)
self.assertEqual(1, mock_register_plugin.call_count)
self.assertEqual(1, mock_load_bank.call_count)
self.assertEqual(1, len(pr.providers))
self.assertEqual(pr.providers['fake_id1'].name, 'fake_provider1')
self.assertEqual('fake_provider1', pr.providers['fake_id1'].name)
self.assertNotIn('fake_provider2', pr.providers)
def test_provider_bank_config(self):
pr = provider.ProviderRegistry()
provider1 = pr.show_provider('fake_id1')
self.assertEqual(provider1.bank._plugin.fake_host, 'thor')
self.assertEqual('thor', provider1.bank._plugin.fake_host)
def test_provider_plugin_config(self):
pr = provider.ProviderRegistry()
provider1 = pr.show_provider('fake_id1')
plugins = provider1.load_plugins()
self.assertEqual(plugins['Test::ResourceA'].fake_user, 'user')
self.assertEqual('user', plugins['Test::ResourceA'].fake_user)
def test_list_provider(self):
pr = provider.ProviderRegistry()

View File

@ -67,7 +67,7 @@ class SwiftBankPluginTest(base.TestCase):
expire_time = math.floor(time.time()) + self.conf.lease_expire_window
self.assertEqual(self.swift_bank_plugin.lease_expire_time, expire_time)
is_valid = self.swift_bank_plugin.check_lease_validity()
self.assertEqual(is_valid, True)
self.assertTrue(is_valid)
def test_delete_object(self):
self.swift_bank_plugin.update_object("key", "value")
@ -75,18 +75,18 @@ class SwiftBankPluginTest(base.TestCase):
object_file = os.path.join(self.fake_connection.swiftdir,
"karbor",
"key")
self.assertEqual(os.path.isfile(object_file), False)
self.assertFalse(os.path.isfile(object_file))
def test_get_object(self):
self.swift_bank_plugin.update_object("key", "value")
value = self.swift_bank_plugin.get_object("key")
self.assertEqual(value, "value")
self.assertEqual("value", value)
def test_list_objects(self):
self.swift_bank_plugin.update_object("key-1", "value-1")
self.swift_bank_plugin.update_object("key-2", "value-2")
objects = self.swift_bank_plugin.list_objects(prefix=None)
self.assertEqual(len(objects), 2)
self.assertEqual(2, len(objects))
def test_update_object(self):
self.swift_bank_plugin.update_object("key-1", "value-1")
@ -96,9 +96,9 @@ class SwiftBankPluginTest(base.TestCase):
"key-1")
with open(object_file, "r") as f:
contents = f.read()
self.assertEqual(contents, "value-2")
self.assertEqual("value-2", contents)
def test_create_get_dict_object(self):
self.swift_bank_plugin.update_object("dict_object", {"key": "value"})
value = self.swift_bank_plugin.get_object("dict_object")
self.assertEqual(value, {"key": "value"})
self.assertEqual({"key": "value"}, value)