diff --git a/nova/tests/functional/api_sample_tests/test_volumes.py b/nova/tests/functional/api_sample_tests/test_volumes.py index 6d941f4cbc43..5dc33b030f2b 100644 --- a/nova/tests/functional/api_sample_tests/test_volumes.py +++ b/nova/tests/functional/api_sample_tests/test_volumes.py @@ -76,8 +76,8 @@ class SnapshotsSampleJsonTests(api_sample_base.ApiSampleTestBaseV3): fakes.stub_snapshot_delete) self._create_snapshot() response = self._do_delete('os-snapshots/100') - self.assertEqual(response.status_code, 202) - self.assertEqual(response.content, '') + self.assertEqual(202, response.status_code) + self.assertEqual('', response.content) def test_snapshots_detail(self): response = self._do_get('os-snapshots/detail') @@ -207,8 +207,8 @@ class VolumesSampleJsonTest(test_servers.ServersSampleBase): self._post_volume() vol_id = self._get_volume_id() response = self._do_delete('os-volumes/%s' % vol_id) - self.assertEqual(response.status_code, 202) - self.assertEqual(response.content, '') + self.assertEqual(202, response.status_code) + self.assertEqual('', response.content) class VolumeAttachmentsSampleBase(test_servers.ServersSampleBase): @@ -319,8 +319,8 @@ class VolumeAttachmentsSampleJsonTest(VolumeAttachmentsSampleBase): self.stubs.Set(compute_api.API, 'detach_volume', lambda *a, **k: None) response = self._do_delete('servers/%s/os-volume_attachments/%s' % (server_id, attach_id)) - self.assertEqual(response.status_code, 202) - self.assertEqual(response.content, '') + self.assertEqual(202, response.status_code) + self.assertEqual('', response.content) def test_volume_attachment_update(self): self.stubs.Set(cinder.API, 'get', fakes.stub_volume_get) @@ -337,5 +337,5 @@ class VolumeAttachmentsSampleJsonTest(VolumeAttachmentsSampleBase): % (server_id, attach_id), 'update-volume-req', subs) - self.assertEqual(response.status_code, 202) - self.assertEqual(response.content, '') + self.assertEqual(202, response.status_code) + self.assertEqual('', response.content) diff --git a/nova/tests/functional/api_samples_test_base.py b/nova/tests/functional/api_samples_test_base.py index 022e2352315a..54f447c800a1 100644 --- a/nova/tests/functional/api_samples_test_base.py +++ b/nova/tests/functional/api_samples_test_base.py @@ -224,7 +224,7 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase): return subs def _verify_response(self, name, subs, response, exp_code): - self.assertEqual(response.status_code, exp_code) + self.assertEqual(exp_code, response.status_code) response_data = response.content response_data = self._pretty_data(response_data) if not os.path.exists(self._get_template(name, diff --git a/nova/tests/unit/test_availability_zones.py b/nova/tests/unit/test_availability_zones.py index 335bf3103e5d..05e4b1aff032 100644 --- a/nova/tests/unit/test_availability_zones.py +++ b/nova/tests/unit/test_availability_zones.py @@ -97,9 +97,9 @@ class AvailabilityZoneTestCases(test.TestCase): agg_az1 = self._create_az('agg-az1', az_name) self._add_to_aggregate(service, agg_az1) az.update_host_availability_zone_cache(self.context, self.host) - self.assertEqual(az._get_cache().get(cache_key), 'az1') + self.assertEqual('az1', az._get_cache().get(cache_key)) az.update_host_availability_zone_cache(self.context, self.host, 'az2') - self.assertEqual(az._get_cache().get(cache_key), 'az2') + self.assertEqual('az2', az._get_cache().get(cache_key)) def test_set_availability_zone_compute_service(self): """Test for compute service get right availability zone.""" @@ -109,15 +109,14 @@ class AvailabilityZoneTestCases(test.TestCase): # The service is not add into aggregate, so confirm it is default # availability zone. new_service = az.set_availability_zones(self.context, services)[0] - self.assertEqual(new_service['availability_zone'], - self.default_az) + self.assertEqual(self.default_az, new_service['availability_zone']) # The service is added into aggregate, confirm return the aggregate # availability zone. self._add_to_aggregate(service, self.agg) new_service = az.set_availability_zones(self.context, services)[0] - self.assertEqual(new_service['availability_zone'], - self.availability_zone) + self.assertEqual(self.availability_zone, + new_service['availability_zone']) self._destroy_service(service) @@ -136,8 +135,7 @@ class AvailabilityZoneTestCases(test.TestCase): service = self._create_service_with_topic('network', self.host) services = db.service_get_all(self.context) new_service = az.set_availability_zones(self.context, services)[0] - self.assertEqual(new_service['availability_zone'], - self.default_in_az) + self.assertEqual(self.default_in_az, new_service['availability_zone']) self._destroy_service(service) def test_get_host_availability_zone(self): @@ -220,12 +218,12 @@ class AvailabilityZoneTestCases(test.TestCase): zones, not_zones = az.get_availability_zones(self.context) - self.assertEqual(zones, ['nova-test', 'nova-test2']) - self.assertEqual(not_zones, ['nova-test3', 'nova']) + self.assertEqual(['nova-test', 'nova-test2'], zones) + self.assertEqual(['nova-test3', 'nova'], not_zones) zones = az.get_availability_zones(self.context, True) - self.assertEqual(zones, ['nova-test', 'nova-test2']) + self.assertEqual(['nova-test', 'nova-test2'], zones) zones, not_zones = az.get_availability_zones(self.context, with_hosts=True) diff --git a/nova/tests/unit/test_baserpc.py b/nova/tests/unit/test_baserpc.py index 1d427f6eed7e..be0f3f091d5f 100644 --- a/nova/tests/unit/test_baserpc.py +++ b/nova/tests/unit/test_baserpc.py @@ -42,9 +42,9 @@ class BaseAPITestCase(test.TestCase): def test_ping(self): res = self.base_rpcapi.ping(self.context, 'foo') - self.assertEqual(res, {'service': 'compute', 'arg': 'foo'}) + self.assertEqual({'service': 'compute', 'arg': 'foo'}, res) def test_get_backdoor_port(self): res = self.base_rpcapi.get_backdoor_port(self.context, self.compute.host) - self.assertEqual(res, self.compute.backdoor_port) + self.assertEqual(self.compute.backdoor_port, res) diff --git a/nova/tests/unit/test_block_device.py b/nova/tests/unit/test_block_device.py index 2ae39d515f2a..354d1ae6eebc 100644 --- a/nova/tests/unit/test_block_device.py +++ b/nova/tests/unit/test_block_device.py @@ -77,12 +77,10 @@ class BlockDeviceTestCase(test.NoDBTestCase): 'root_device_name': root_device1} self.assertIsNone(block_device.properties_root_device_name({})) - self.assertEqual( - block_device.properties_root_device_name(properties0), - root_device0) - self.assertEqual( - block_device.properties_root_device_name(properties1), - root_device1) + self.assertEqual(root_device0, + block_device.properties_root_device_name(properties0)) + self.assertEqual(root_device1, + block_device.properties_root_device_name(properties1)) def test_ephemeral(self): self.assertFalse(block_device.is_ephemeral('ephemeral')) @@ -93,9 +91,9 @@ class BlockDeviceTestCase(test.NoDBTestCase): self.assertFalse(block_device.is_ephemeral('swap')) self.assertFalse(block_device.is_ephemeral('/dev/sda1')) - self.assertEqual(block_device.ephemeral_num('ephemeral0'), 0) - self.assertEqual(block_device.ephemeral_num('ephemeral1'), 1) - self.assertEqual(block_device.ephemeral_num('ephemeral11'), 11) + self.assertEqual(0, block_device.ephemeral_num('ephemeral0')) + self.assertEqual(1, block_device.ephemeral_num('ephemeral1')) + self.assertEqual(11, block_device.ephemeral_num('ephemeral11')) self.assertFalse(block_device.is_swap_or_ephemeral('ephemeral')) self.assertTrue(block_device.is_swap_or_ephemeral('ephemeral0')) @@ -122,28 +120,28 @@ class BlockDeviceTestCase(test.NoDBTestCase): {'virtual': 'ephemeral2', 'device': '/dev/sde'}] prepended = block_device.mappings_prepend_dev(mapping) - self.assertEqual(prepended.sort(), expected.sort()) + self.assertEqual(expected.sort(), prepended.sort()) def test_strip_dev(self): - self.assertEqual(block_device.strip_dev('/dev/sda'), 'sda') - self.assertEqual(block_device.strip_dev('sda'), 'sda') + self.assertEqual('sda', block_device.strip_dev('/dev/sda')) + self.assertEqual('sda', block_device.strip_dev('sda')) def test_strip_prefix(self): - self.assertEqual(block_device.strip_prefix('/dev/sda'), 'a') - self.assertEqual(block_device.strip_prefix('a'), 'a') - self.assertEqual(block_device.strip_prefix('xvda'), 'a') - self.assertEqual(block_device.strip_prefix('vda'), 'a') - self.assertEqual(block_device.strip_prefix('hda'), 'a') + self.assertEqual('a', block_device.strip_prefix('/dev/sda')) + self.assertEqual('a', block_device.strip_prefix('a')) + self.assertEqual('a', block_device.strip_prefix('xvda')) + self.assertEqual('a', block_device.strip_prefix('vda')) + self.assertEqual('a', block_device.strip_prefix('hda')) def test_get_device_letter(self): - self.assertEqual(block_device.get_device_letter(''), '') - self.assertEqual(block_device.get_device_letter('/dev/sda1'), 'a') - self.assertEqual(block_device.get_device_letter('/dev/xvdb'), 'b') - self.assertEqual(block_device.get_device_letter('/dev/d'), 'd') - self.assertEqual(block_device.get_device_letter('a'), 'a') - self.assertEqual(block_device.get_device_letter('sdb2'), 'b') - self.assertEqual(block_device.get_device_letter('vdc'), 'c') - self.assertEqual(block_device.get_device_letter('hdc'), 'c') + self.assertEqual('', block_device.get_device_letter('')) + self.assertEqual('a', block_device.get_device_letter('/dev/sda1')) + self.assertEqual('b', block_device.get_device_letter('/dev/xvdb')) + self.assertEqual('d', block_device.get_device_letter('/dev/d')) + self.assertEqual('a', block_device.get_device_letter('a')) + self.assertEqual('b', block_device.get_device_letter('sdb2')) + self.assertEqual('c', block_device.get_device_letter('vdc')) + self.assertEqual('c', block_device.get_device_letter('hdc')) def test_volume_in_mapping(self): swap = {'device_name': '/dev/sdb', @@ -169,7 +167,7 @@ class BlockDeviceTestCase(test.NoDBTestCase): def _assert_volume_in_mapping(device_name, true_or_false): in_mapping = block_device.volume_in_mapping( device_name, block_device_info) - self.assertEqual(in_mapping, true_or_false) + self.assertEqual(true_or_false, in_mapping) _assert_volume_in_mapping('sda', False) _assert_volume_in_mapping('sdb', True) @@ -468,7 +466,7 @@ class TestBlockDeviceDict(test.NoDBTestCase): cool_volume_size_bdm['volume_size'] = '42' cool_volume_size_bdm = block_device.BlockDeviceDict( cool_volume_size_bdm) - self.assertEqual(cool_volume_size_bdm['volume_size'], 42) + self.assertEqual(42, cool_volume_size_bdm['volume_size']) lame_volume_size_bdm = dict(self.new_mapping[2]) lame_volume_size_bdm['volume_size'] = 'some_non_int_string' @@ -479,7 +477,7 @@ class TestBlockDeviceDict(test.NoDBTestCase): truthy_bdm = dict(self.new_mapping[2]) truthy_bdm['delete_on_termination'] = '1' truthy_bdm = block_device.BlockDeviceDict(truthy_bdm) - self.assertEqual(truthy_bdm['delete_on_termination'], True) + self.assertEqual(True, truthy_bdm['delete_on_termination']) verbose_bdm = dict(self.new_mapping[2]) verbose_bdm['boot_index'] = 'first' @@ -501,7 +499,7 @@ class TestBlockDeviceDict(test.NoDBTestCase): return [bdm for bdm in bdms if bdm['boot_index'] >= 0] new_no_img = block_device.from_legacy_mapping(self.legacy_mapping) - self.assertEqual(len(_get_image_bdms(new_no_img)), 0) + self.assertEqual(0, len(_get_image_bdms(new_no_img))) for new, expected in zip(new_no_img, self.new_mapping): self.assertThat(new, matchers.IsSubDictOf(expected)) @@ -510,24 +508,24 @@ class TestBlockDeviceDict(test.NoDBTestCase): self.legacy_mapping, 'fake_image_ref') image_bdms = _get_image_bdms(new_with_img) boot_bdms = _get_bootable_bdms(new_with_img) - self.assertEqual(len(image_bdms), 1) - self.assertEqual(len(boot_bdms), 1) - self.assertEqual(image_bdms[0]['boot_index'], 0) - self.assertEqual(boot_bdms[0]['source_type'], 'image') + self.assertEqual(1, len(image_bdms)) + self.assertEqual(1, len(boot_bdms)) + self.assertEqual(0, image_bdms[0]['boot_index']) + self.assertEqual('image', boot_bdms[0]['source_type']) new_with_img_and_root = block_device.from_legacy_mapping( self.legacy_mapping, 'fake_image_ref', 'sda1') image_bdms = _get_image_bdms(new_with_img_and_root) boot_bdms = _get_bootable_bdms(new_with_img_and_root) - self.assertEqual(len(image_bdms), 0) - self.assertEqual(len(boot_bdms), 1) - self.assertEqual(boot_bdms[0]['boot_index'], 0) - self.assertEqual(boot_bdms[0]['source_type'], 'volume') + self.assertEqual(0, len(image_bdms)) + self.assertEqual(1, len(boot_bdms)) + self.assertEqual(0, boot_bdms[0]['boot_index']) + self.assertEqual('volume', boot_bdms[0]['source_type']) new_no_root = block_device.from_legacy_mapping( self.legacy_mapping, 'fake_image_ref', 'sda1', no_root=True) - self.assertEqual(len(_get_image_bdms(new_no_root)), 0) - self.assertEqual(len(_get_bootable_bdms(new_no_root)), 0) + self.assertEqual(0, len(_get_image_bdms(new_no_root))) + self.assertEqual(0, len(_get_bootable_bdms(new_no_root))) def test_from_api(self): for api, new in zip(self.api_mapping, self.new_mapping): @@ -573,9 +571,8 @@ class TestBlockDeviceDict(test.NoDBTestCase): 'destination_type': 'local', 'volume_id': 'fake-volume-id-1', 'boot_index': 0}) - self.assertEqual( - block_device.BlockDeviceDict.from_api(api_dict, True), - retexp) + self.assertEqual(retexp, + block_device.BlockDeviceDict.from_api(api_dict, True)) def test_from_api_invalid_source_to_local_mapping_with_string_bi(self): api_dict = {'id': 1, @@ -655,15 +652,15 @@ class TestBlockDeviceDict(test.NoDBTestCase): def _test_snapshot_from_bdm(self, template): snapshot = block_device.snapshot_from_bdm('new-snapshot-id', template) - self.assertEqual(snapshot['snapshot_id'], 'new-snapshot-id') - self.assertEqual(snapshot['source_type'], 'snapshot') - self.assertEqual(snapshot['destination_type'], 'volume') + self.assertEqual('new-snapshot-id', snapshot['snapshot_id']) + self.assertEqual('snapshot', snapshot['source_type']) + self.assertEqual('volume', snapshot['destination_type']) self.assertEqual(template.volume_size, snapshot['volume_size']) self.assertEqual(template.delete_on_termination, snapshot['delete_on_termination']) self.assertEqual(template.device_name, snapshot['device_name']) for key in ['disk_bus', 'device_type', 'boot_index']: - self.assertEqual(snapshot[key], template[key]) + self.assertEqual(template[key], snapshot[key]) def test_snapshot_from_bdm(self): for bdm in self.new_mapping: diff --git a/nova/tests/unit/test_cinder.py b/nova/tests/unit/test_cinder.py index 1240b9547a32..1a32cb7e5361 100644 --- a/nova/tests/unit/test_cinder.py +++ b/nova/tests/unit/test_cinder.py @@ -71,7 +71,7 @@ class BaseCinderTestCase(object): def test_cinder_api_cacert_file(self): cacert = "/etc/ssl/certs/ca-certificates.crt" self.flags(cafile=cacert, group='cinder') - self.assertEqual(self.create_client().client.session.verify, cacert) + self.assertEqual(cacert, self.create_client().client.session.verify) class CinderTestCase(BaseCinderTestCase, test.NoDBTestCase): @@ -129,7 +129,7 @@ class CinderTestCase(BaseCinderTestCase, test.NoDBTestCase): self.assertThat(m.last_request.path, matchers.EndsWith('/volumes/5678')) self.assertIn('volume_image_metadata', volume) - self.assertEqual(volume['volume_image_metadata'], _image_metadata) + self.assertEqual(_image_metadata, volume['volume_image_metadata']) class CinderV2TestCase(BaseCinderTestCase, test.NoDBTestCase): diff --git a/nova/tests/unit/test_context.py b/nova/tests/unit/test_context.py index 5b4056eade49..3a2215c54f05 100644 --- a/nova/tests/unit/test_context.py +++ b/nova/tests/unit/test_context.py @@ -40,28 +40,28 @@ class ContextTestCase(test.NoDBTestCase): ctxt = context.RequestContext('111', '222', roles=['admin', 'weasel']) - self.assertEqual(ctxt.is_admin, True) + self.assertEqual(True, ctxt.is_admin) def test_request_context_sets_is_admin_by_role(self): ctxt = context.RequestContext('111', '222', roles=['administrator']) - self.assertEqual(ctxt.is_admin, True) + self.assertEqual(True, ctxt.is_admin) def test_request_context_sets_is_admin_upcase(self): ctxt = context.RequestContext('111', '222', roles=['Admin', 'weasel']) - self.assertEqual(ctxt.is_admin, True) + self.assertEqual(True, ctxt.is_admin) def test_request_context_read_deleted(self): ctxt = context.RequestContext('111', '222', read_deleted='yes') - self.assertEqual(ctxt.read_deleted, 'yes') + self.assertEqual('yes', ctxt.read_deleted) ctxt.read_deleted = 'no' - self.assertEqual(ctxt.read_deleted, 'no') + self.assertEqual('no', ctxt.read_deleted) def test_request_context_read_deleted_invalid(self): self.assertRaises(ValueError, @@ -93,15 +93,15 @@ class ContextTestCase(test.NoDBTestCase): def test_service_catalog_default(self): ctxt = context.RequestContext('111', '222') - self.assertEqual(ctxt.service_catalog, []) + self.assertEqual([], ctxt.service_catalog) ctxt = context.RequestContext('111', '222', service_catalog=[]) - self.assertEqual(ctxt.service_catalog, []) + self.assertEqual([], ctxt.service_catalog) ctxt = context.RequestContext('111', '222', service_catalog=None) - self.assertEqual(ctxt.service_catalog, []) + self.assertEqual([], ctxt.service_catalog) def test_service_catalog_cinder_only(self): service_catalog = [ @@ -118,7 +118,7 @@ class ContextTestCase(test.NoDBTestCase): volume_catalog = [{u'type': u'volume', u'name': u'cinder'}] ctxt = context.RequestContext('111', '222', service_catalog=service_catalog) - self.assertEqual(ctxt.service_catalog, volume_catalog) + self.assertEqual(volume_catalog, ctxt.service_catalog) def test_to_dict_from_dict_no_log(self): warns = [] @@ -136,7 +136,7 @@ class ContextTestCase(test.NoDBTestCase): context.RequestContext.from_dict(ctxt.to_dict()) - self.assertEqual(len(warns), 0, warns) + self.assertEqual(0, len(warns), warns) def test_store_when_no_overwrite(self): # If no context exists we store one even if overwrite is false @@ -217,9 +217,9 @@ class ContextTestCase(test.NoDBTestCase): 'request_id': 'req-956637ad-354a-4bc5-b969-66fd1cc00f50', 'user_domain': None} ctx = context.RequestContext.from_dict(values) - self.assertEqual(ctx.user, '111') - self.assertEqual(ctx.tenant, '222') - self.assertEqual(ctx.user_id, '111') - self.assertEqual(ctx.project_id, '222') + self.assertEqual('111', ctx.user) + self.assertEqual('222', ctx.tenant) + self.assertEqual('111', ctx.user_id) + self.assertEqual('222', ctx.project_id) values2 = ctx.to_dict() self.assertEqual(values, values2) diff --git a/nova/tests/unit/test_exception.py b/nova/tests/unit/test_exception.py index 3b54f485d954..12c87894ba7e 100644 --- a/nova/tests/unit/test_exception.py +++ b/nova/tests/unit/test_exception.py @@ -56,9 +56,9 @@ class WrapExceptionTestCase(test.NoDBTestCase): ctxt = context.get_admin_context() self.assertRaises(test.TestingException, wrapped(bad_function_exception), 1, ctxt, 3, zoo=3) - self.assertEqual(notifier.provided_event, "bad_function_exception") + self.assertEqual("bad_function_exception", notifier.provided_event) self.assertEqual(notifier.provided_context, ctxt) - self.assertEqual(notifier.provided_payload['args']['extra'], 3) + self.assertEqual(3, notifier.provided_payload['args']['extra']) for key in ['exception', 'args']: self.assertIn(key, notifier.provided_payload.keys()) @@ -69,34 +69,34 @@ class NovaExceptionTestCase(test.NoDBTestCase): msg_fmt = "default message" exc = FakeNovaException() - self.assertEqual(six.text_type(exc), 'default message') + self.assertEqual('default message', six.text_type(exc)) def test_error_msg(self): - self.assertEqual(six.text_type(exception.NovaException('test')), - 'test') + self.assertEqual('test', + six.text_type(exception.NovaException('test'))) def test_default_error_msg_with_kwargs(self): class FakeNovaException(exception.NovaException): msg_fmt = "default message: %(code)s" exc = FakeNovaException(code=500) - self.assertEqual(six.text_type(exc), 'default message: 500') - self.assertEqual(exc.message, 'default message: 500') + self.assertEqual('default message: 500', six.text_type(exc)) + self.assertEqual('default message: 500', exc.message) def test_error_msg_exception_with_kwargs(self): class FakeNovaException(exception.NovaException): msg_fmt = "default message: %(misspelled_code)s" exc = FakeNovaException(code=500, misspelled_code='blah') - self.assertEqual(six.text_type(exc), 'default message: blah') - self.assertEqual(exc.message, 'default message: blah') + self.assertEqual('default message: blah', six.text_type(exc)) + self.assertEqual('default message: blah', exc.message) def test_default_error_code(self): class FakeNovaException(exception.NovaException): code = 404 exc = FakeNovaException() - self.assertEqual(exc.kwargs['code'], 404) + self.assertEqual(404, exc.kwargs['code']) def test_error_code_from_kwarg(self): class FakeNovaException(exception.NovaException): @@ -107,10 +107,10 @@ class NovaExceptionTestCase(test.NoDBTestCase): def test_cleanse_dict(self): kwargs = {'foo': 1, 'blah_pass': 2, 'zoo_password': 3, '_pass': 4} - self.assertEqual(exception._cleanse_dict(kwargs), {'foo': 1}) + self.assertEqual({'foo': 1}, exception._cleanse_dict(kwargs)) kwargs = {} - self.assertEqual(exception._cleanse_dict(kwargs), {}) + self.assertEqual({}, exception._cleanse_dict(kwargs)) def test_format_message_local(self): class FakeNovaException(exception.NovaException): @@ -131,8 +131,8 @@ class NovaExceptionTestCase(test.NoDBTestCase): return u"print the whole trace" exc = FakeNovaException_Remote() - self.assertEqual(six.text_type(exc), u"print the whole trace") - self.assertEqual(exc.format_message(), "some message") + self.assertEqual(u"print the whole trace", six.text_type(exc)) + self.assertEqual("some message", exc.format_message()) def test_format_message_remote_error(self): class FakeNovaException_Remote(exception.NovaException): @@ -143,7 +143,7 @@ class NovaExceptionTestCase(test.NoDBTestCase): self.flags(fatal_exception_format_errors=False) exc = FakeNovaException_Remote(lame_arg='lame') - self.assertEqual(exc.format_message(), "some message %(somearg)s") + self.assertEqual("some message %(somearg)s", exc.format_message()) class ExceptionTestCase(test.NoDBTestCase): diff --git a/nova/tests/unit/test_fixtures.py b/nova/tests/unit/test_fixtures.py index 130682e071e3..2c5c05be0a31 100644 --- a/nova/tests/unit/test_fixtures.py +++ b/nova/tests/unit/test_fixtures.py @@ -63,11 +63,11 @@ class TestConfFixture(testtools.TestCase): """ def _test_override(self): - self.assertEqual(CONF.api_paste_config, 'api-paste.ini') - self.assertEqual(CONF.fake_network, False) + self.assertEqual('api-paste.ini', CONF.api_paste_config) + self.assertEqual(False, CONF.fake_network) self.useFixture(conf_fixture.ConfFixture()) CONF.set_default('api_paste_config', 'foo') - self.assertEqual(CONF.fake_network, True) + self.assertEqual(True, CONF.fake_network) def test_override1(self): self._test_override() @@ -89,8 +89,8 @@ class TestOutputStream(testtools.TestCase): out = self.useFixture(fixtures.OutputStreamCapture()) sys.stdout.write("foo") sys.stderr.write("bar") - self.assertEqual(out.stdout, "foo") - self.assertEqual(out.stderr, "bar") + self.assertEqual("foo", out.stdout) + self.assertEqual("bar", out.stderr) # TODO(sdague): nuke the out and err buffers so it doesn't # make it to testr @@ -100,7 +100,7 @@ class TestLogging(testtools.TestCase): stdlog = self.useFixture(fixtures.StandardLogging()) root = logging.getLogger() # there should be a null handler as well at DEBUG - self.assertEqual(len(root.handlers), 2, root.handlers) + self.assertEqual(2, len(root.handlers), root.handlers) log = logging.getLogger(__name__) log.info("at info") log.debug("at debug") @@ -125,7 +125,7 @@ class TestLogging(testtools.TestCase): stdlog = self.useFixture(fixtures.StandardLogging()) root = logging.getLogger() # there should no longer be a null handler - self.assertEqual(len(root.handlers), 1, root.handlers) + self.assertEqual(1, len(root.handlers), root.handlers) log = logging.getLogger(__name__) log.info("at info") log.debug("at debug") @@ -147,11 +147,11 @@ class TestTimeout(testtools.TestCase): # various things that should work. timeout = fixtures.Timeout(10) - self.assertEqual(timeout.test_timeout, 10) + self.assertEqual(10, timeout.test_timeout) timeout = fixtures.Timeout("10") - self.assertEqual(timeout.test_timeout, 10) + self.assertEqual(10, timeout.test_timeout) timeout = fixtures.Timeout("10", 2) - self.assertEqual(timeout.test_timeout, 20) + self.assertEqual(20, timeout.test_timeout) class TestOSAPIFixture(testtools.TestCase): @@ -164,7 +164,7 @@ class TestOSAPIFixture(testtools.TestCase): # request the API root, which provides us the versions of the API resp = api.api_request('/', strip_version=True) - self.assertEqual(resp.status_code, 200, resp.content) + self.assertEqual(200, resp.status_code, resp.content) # request a bad root url, should be a 404 # @@ -177,7 +177,7 @@ class TestOSAPIFixture(testtools.TestCase): # request a known bad url, and we should get a 404 resp = api.api_request('/foo') - self.assertEqual(resp.status_code, 404, resp.content) + self.assertEqual(404, resp.status_code, resp.content) class TestDatabaseFixture(testtools.TestCase): @@ -189,7 +189,7 @@ class TestDatabaseFixture(testtools.TestCase): conn = engine.connect() result = conn.execute("select * from instance_types") rows = result.fetchall() - self.assertEqual(len(rows), 5, "Rows %s" % rows) + self.assertEqual(5, len(rows), "Rows %s" % rows) # insert a 6th instance type, column 5 below is an int id # which has a constraint on it, so if new standard instance @@ -199,7 +199,7 @@ class TestDatabaseFixture(testtools.TestCase): ", 1.0, 40, 0, 0, 1, 0)") result = conn.execute("select * from instance_types") rows = result.fetchall() - self.assertEqual(len(rows), 6, "Rows %s" % rows) + self.assertEqual(6, len(rows), "Rows %s" % rows) # reset by invoking the fixture again # @@ -210,7 +210,7 @@ class TestDatabaseFixture(testtools.TestCase): conn = engine.connect() result = conn.execute("select * from instance_types") rows = result.fetchall() - self.assertEqual(len(rows), 5, "Rows %s" % rows) + self.assertEqual(5, len(rows), "Rows %s" % rows) def test_api_fixture_reset(self): # This sets up reasonable db connection strings @@ -220,14 +220,14 @@ class TestDatabaseFixture(testtools.TestCase): conn = engine.connect() result = conn.execute("select * from cell_mappings") rows = result.fetchall() - self.assertEqual(len(rows), 0, "Rows %s" % rows) + self.assertEqual(0, len(rows), "Rows %s" % rows) uuid = uuidutils.generate_uuid() conn.execute("insert into cell_mappings (uuid, name) VALUES " "('%s', 'fake-cell')" % (uuid,)) result = conn.execute("select * from cell_mappings") rows = result.fetchall() - self.assertEqual(len(rows), 1, "Rows %s" % rows) + self.assertEqual(1, len(rows), "Rows %s" % rows) # reset by invoking the fixture again # @@ -238,7 +238,7 @@ class TestDatabaseFixture(testtools.TestCase): conn = engine.connect() result = conn.execute("select * from cell_mappings") rows = result.fetchall() - self.assertEqual(len(rows), 0, "Rows %s" % rows) + self.assertEqual(0, len(rows), "Rows %s" % rows) def test_fixture_cleanup(self): # because this sets up reasonable db connection strings @@ -269,7 +269,7 @@ class TestDatabaseFixture(testtools.TestCase): "('%s', 'fake-cell')" % (uuid,)) result = conn.execute("select * from cell_mappings") rows = result.fetchall() - self.assertEqual(len(rows), 1, "Rows %s" % rows) + self.assertEqual(1, len(rows), "Rows %s" % rows) # Manually do the cleanup that addCleanup will do fix.cleanup() @@ -278,7 +278,7 @@ class TestDatabaseFixture(testtools.TestCase): engine = session.get_api_engine() conn = engine.connect() schema = "".join(line for line in conn.connection.iterdump()) - self.assertEqual(schema, "BEGIN TRANSACTION;COMMIT;") + self.assertEqual("BEGIN TRANSACTION;COMMIT;", schema) class TestIndirectionAPIFixture(testtools.TestCase):