diff --git a/manila/tests/test_conf.py b/manila/tests/test_conf.py index 6964d1386f..2c9e897a0f 100644 --- a/manila/tests/test_conf.py +++ b/manila/tests/test_conf.py @@ -35,19 +35,19 @@ class ConfigTestCase(test.TestCase): self.assertNotIn('answer', CONF) CONF.import_opt('answer', 'manila.tests.declare_conf') self.assertIn('answer', CONF) - self.assertEqual(CONF.answer, 42) + self.assertEqual(42, CONF.answer) # Make sure we don't overwrite anything CONF.set_override('answer', 256) - self.assertEqual(CONF.answer, 256) + self.assertEqual(256, CONF.answer) CONF.import_opt('answer', 'manila.tests.declare_conf') - self.assertEqual(CONF.answer, 256) + self.assertEqual(256, CONF.answer) def test_runtime_and_unknown_flags(self): self.assertNotIn('runtime_answer', CONF) import manila.tests.runtime_conf # noqa self.assertIn('runtime_answer', CONF) - self.assertEqual(CONF.runtime_answer, 54) + self.assertEqual(54, CONF.runtime_answer) def test_long_vs_short_flags(self): CONF.clear() @@ -60,22 +60,22 @@ class ConfigTestCase(test.TestCase): argv = ['--duplicate_answer=60'] CONF(argv, default_config_files=[]) - self.assertEqual(CONF.duplicate_answer, 60) - self.assertEqual(CONF.duplicate_answer_long, 'val') + self.assertEqual(60, CONF.duplicate_answer) + self.assertEqual('val', CONF.duplicate_answer_long) def test_flag_leak_left(self): - self.assertEqual(CONF.conf_unittest, 'foo') + self.assertEqual('foo', CONF.conf_unittest) self.flags(conf_unittest='bar') - self.assertEqual(CONF.conf_unittest, 'bar') + self.assertEqual('bar', CONF.conf_unittest) def test_flag_leak_right(self): - self.assertEqual(CONF.conf_unittest, 'foo') + self.assertEqual('foo', CONF.conf_unittest) self.flags(conf_unittest='bar') - self.assertEqual(CONF.conf_unittest, 'bar') + self.assertEqual('bar', CONF.conf_unittest) def test_flag_overrides(self): - self.assertEqual(CONF.conf_unittest, 'foo') + self.assertEqual('foo', CONF.conf_unittest) self.flags(conf_unittest='bar') - self.assertEqual(CONF.conf_unittest, 'bar') + self.assertEqual('bar', CONF.conf_unittest) CONF.reset() - self.assertEqual(CONF.conf_unittest, 'foo') + self.assertEqual('foo', CONF.conf_unittest) diff --git a/manila/tests/test_context.py b/manila/tests/test_context.py index 4db80c66d1..444b0c89be 100644 --- a/manila/tests/test_context.py +++ b/manila/tests/test_context.py @@ -32,22 +32,22 @@ class ContextTestCase(test.TestCase): ctxt = context.RequestContext('111', '222', roles=['admin', 'weasel']) - self.assertEqual(ctxt.is_admin, True) + self.assertTrue(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.assertTrue(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, diff --git a/manila/tests/test_exception.py b/manila/tests/test_exception.py index f1a4b6c59b..68081a7afe 100644 --- a/manila/tests/test_exception.py +++ b/manila/tests/test_exception.py @@ -46,43 +46,43 @@ class ManilaExceptionTestCase(test.TestCase): message = "default message" exc = FakeManilaException() - 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.ManilaException('test')), - 'test') + self.assertEqual('test', + six.text_type(exception.ManilaException('test'))) def test_default_error_msg_with_kwargs(self): class FakeManilaException(exception.ManilaException): message = "default message: %(code)s" exc = FakeManilaException(code=500) - self.assertEqual(six.text_type(exc), 'default message: 500') + self.assertEqual('default message: 500', six.text_type(exc)) def test_error_msg_exception_with_kwargs(self): # NOTE(dprince): disable format errors for this test self.flags(fatal_exception_format_errors=False) class FakeManilaException(exception.ManilaException): - message = "default message: %(mispelled_code)s" + message = "default message: %(misspelled_code)s" exc = FakeManilaException(code=500) - self.assertEqual(six.text_type(exc), - 'default message: %(mispelled_code)s') + self.assertEqual('default message: %(misspelled_code)s', + six.text_type(exc)) def test_default_error_code(self): class FakeManilaException(exception.ManilaException): code = 404 exc = FakeManilaException() - self.assertEqual(exc.kwargs['code'], 404) + self.assertEqual(404, exc.kwargs['code']) def test_error_code_from_kwarg(self): class FakeManilaException(exception.ManilaException): code = 500 exc = FakeManilaException(code=404) - self.assertEqual(exc.kwargs['code'], 404) + self.assertEqual(404, exc.kwargs['code']) def test_error_msg_is_exception_to_string(self): msg = 'test message' @@ -124,100 +124,100 @@ class ManilaExceptionResponseCode400(test.TestCase): def test_invalid(self): # Verify response code for exception.Invalid e = exception.Invalid() - self.assertEqual(e.code, 400) + self.assertEqual(400, e.code) def test_invalid_input(self): # Verify response code for exception.InvalidInput reason = "fake_reason" e = exception.InvalidInput(reason=reason) - self.assertEqual(e.code, 400) + self.assertEqual(400, e.code) self.assertIn(reason, e.msg) def test_invalid_request(self): # Verify response code for exception.InvalidRequest e = exception.InvalidRequest() - self.assertEqual(e.code, 400) + self.assertEqual(400, e.code) def test_invalid_results(self): # Verify response code for exception.InvalidResults e = exception.InvalidResults() - self.assertEqual(e.code, 400) + self.assertEqual(400, e.code) def test_invalid_uuid(self): # Verify response code for exception.InvalidUUID uuid = "fake_uuid" e = exception.InvalidUUID(uuid=uuid) - self.assertEqual(e.code, 400) + self.assertEqual(400, e.code) self.assertIn(uuid, e.msg) def test_invalid_content_type(self): # Verify response code for exception.InvalidContentType content_type = "fake_content_type" e = exception.InvalidContentType(content_type=content_type) - self.assertEqual(e.code, 400) + self.assertEqual(400, e.code) self.assertIn(content_type, e.msg) def test_invalid_parameter_value(self): # Verify response code for exception.InvalidParameterValue err = "fake_err" e = exception.InvalidParameterValue(err=err) - self.assertEqual(e.code, 400) + self.assertEqual(400, e.code) self.assertIn(err, e.msg) def test_invalid_reservation_expiration(self): # Verify response code for exception.InvalidReservationExpiration expire = "fake_expire" e = exception.InvalidReservationExpiration(expire=expire) - self.assertEqual(e.code, 400) + self.assertEqual(400, e.code) self.assertIn(expire, e.msg) def test_invalid_quota_value(self): # Verify response code for exception.InvalidQuotaValue unders = '-1' e = exception.InvalidQuotaValue(unders=unders) - self.assertEqual(e.code, 400) + self.assertEqual(400, e.code) def test_invalid_share(self): # Verify response code for exception.InvalidShare reason = "fake_reason" e = exception.InvalidShare(reason=reason) - self.assertEqual(e.code, 400) + self.assertEqual(400, e.code) self.assertIn(reason, e.msg) def test_invalid_share_access(self): # Verify response code for exception.InvalidShareAccess reason = "fake_reason" e = exception.InvalidShareAccess(reason=reason) - self.assertEqual(e.code, 400) + self.assertEqual(400, e.code) self.assertIn(reason, e.msg) def test_invalid_share_snapshot(self): # Verify response code for exception.InvalidShareSnapshot reason = "fake_reason" e = exception.InvalidShareSnapshot(reason=reason) - self.assertEqual(e.code, 400) + self.assertEqual(400, e.code) self.assertIn(reason, e.msg) def test_invalid_share_metadata(self): # Verify response code for exception.InvalidShareMetadata e = exception.InvalidShareMetadata() - self.assertEqual(e.code, 400) + self.assertEqual(400, e.code) def test_invalid_share_metadata_size(self): # Verify response code for exception.InvalidShareMetadataSize e = exception.InvalidShareMetadataSize() - self.assertEqual(e.code, 400) + self.assertEqual(400, e.code) def test_invalid_volume(self): # Verify response code for exception.InvalidVolume e = exception.InvalidVolume() - self.assertEqual(e.code, 400) + self.assertEqual(400, e.code) def test_invalid_share_type(self): # Verify response code for exception.InvalidShareType reason = "fake_reason" e = exception.InvalidShareType(reason=reason) - self.assertEqual(e.code, 400) + self.assertEqual(400, e.code) self.assertIn(reason, e.msg) @@ -226,18 +226,18 @@ class ManilaExceptionResponseCode403(test.TestCase): def test_not_authorized(self): # Verify response code for exception.NotAuthorized e = exception.NotAuthorized() - self.assertEqual(e.code, 403) + self.assertEqual(403, e.code) def test_admin_required(self): # Verify response code for exception.AdminRequired e = exception.AdminRequired() - self.assertEqual(e.code, 403) + self.assertEqual(403, e.code) def test_policy_not_authorized(self): # Verify response code for exception.PolicyNotAuthorized action = "fake_action" e = exception.PolicyNotAuthorized(action=action) - self.assertEqual(e.code, 403) + self.assertEqual(403, e.code) self.assertIn(action, e.msg) @@ -246,20 +246,20 @@ class ManilaExceptionResponseCode404(test.TestCase): def test_not_found(self): # Verify response code for exception.NotFound e = exception.NotFound() - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) def test_share_network_not_found(self): # Verify response code for exception.ShareNetworkNotFound share_network_id = "fake_share_network_id" e = exception.ShareNetworkNotFound(share_network_id=share_network_id) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(share_network_id, e.msg) def test_share_server_not_found(self): # Verify response code for exception.ShareServerNotFound share_server_id = "fake_share_server_id" e = exception.ShareServerNotFound(share_server_id=share_server_id) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(share_server_id, e.msg) def test_share_server_not_found_by_filters(self): @@ -267,35 +267,35 @@ class ManilaExceptionResponseCode404(test.TestCase): filters_description = "host = fakeHost" e = exception.ShareServerNotFoundByFilters( filters_description=filters_description) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(filters_description, e.msg) def test_service_not_found(self): # Verify response code for exception.ServiceNotFound service_id = "fake_service_id" e = exception.ServiceNotFound(service_id=service_id) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(service_id, e.msg) def test_host_not_found(self): # Verify response code for exception.HostNotFound host = "fake_host" e = exception.HostNotFound(host=host) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(host, e.msg) def test_scheduler_host_filter_not_found(self): # Verify response code for exception.SchedulerHostFilterNotFound filter_name = "fake_filter_name" e = exception.SchedulerHostFilterNotFound(filter_name=filter_name) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(filter_name, e.msg) def test_scheduler_host_weigher_not_found(self): # Verify response code for exception.SchedulerHostWeigherNotFound weigher_name = "fake_weigher_name" e = exception.SchedulerHostWeigherNotFound(weigher_name=weigher_name) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(weigher_name, e.msg) def test_host_binary_not_found(self): @@ -303,50 +303,50 @@ class ManilaExceptionResponseCode404(test.TestCase): host = "fake_host" binary = "fake_binary" e = exception.HostBinaryNotFound(binary=binary, host=host) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(binary, e.msg) self.assertIn(host, e.msg) def test_quota_not_found(self): # Verify response code for exception.QuotaNotFound e = exception.QuotaNotFound() - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) def test_quota_resource_unknown(self): # Verify response code for exception.QuotaResourceUnknown unknown = "fake_quota_resource" e = exception.QuotaResourceUnknown(unknown=unknown) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) def test_project_quota_not_found(self): # Verify response code for exception.ProjectQuotaNotFound project_id = "fake_tenant_id" e = exception.ProjectQuotaNotFound(project_id=project_id) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) def test_quota_class_not_found(self): # Verify response code for exception.QuotaClassNotFound class_name = "FakeQuotaClass" e = exception.QuotaClassNotFound(class_name=class_name) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) def test_quota_usage_not_found(self): # Verify response code for exception.QuotaUsageNotFound project_id = "fake_tenant_id" e = exception.QuotaUsageNotFound(project_id=project_id) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) def test_reservation_not_found(self): # Verify response code for exception.ReservationNotFound uuid = "fake_uuid" e = exception.ReservationNotFound(uuid=uuid) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) def test_migration_not_found(self): # Verify response code for exception.MigrationNotFound migration_id = "fake_migration_id" e = exception.MigrationNotFound(migration_id=migration_id) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(migration_id, e.msg) def test_migration_not_found_by_status(self): @@ -355,7 +355,7 @@ class ManilaExceptionResponseCode404(test.TestCase): instance_id = "fake_instance_id" e = exception.MigrationNotFoundByStatus(status=status, instance_id=instance_id) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(status, e.msg) self.assertIn(instance_id, e.msg) @@ -363,14 +363,14 @@ class ManilaExceptionResponseCode404(test.TestCase): # Verify response code for exception.FileNotFound file_path = "fake_file_path" e = exception.FileNotFound(file_path=file_path) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(file_path, e.msg) def test_config_not_found(self): # Verify response code for exception.ConfigNotFound path = "fake_path" e = exception.ConfigNotFound(path=path) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(path, e.msg) def test_paste_app_not_found(self): @@ -378,7 +378,7 @@ class ManilaExceptionResponseCode404(test.TestCase): name = "fake_name" path = "fake_path" e = exception.PasteAppNotFound(name=name, path=path) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(name, e.msg) self.assertIn(path, e.msg) @@ -386,41 +386,41 @@ class ManilaExceptionResponseCode404(test.TestCase): # Verify response code for exception.ShareSnapshotNotFound snapshot_id = "fake_snapshot_id" e = exception.VolumeSnapshotNotFound(snapshot_id=snapshot_id) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(snapshot_id, e.msg) def test_share_metadata_not_found(self): # verify response code for exception.ShareMetadataNotFound e = exception.ShareMetadataNotFound() - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) def test_security_service_not_found(self): # verify response code for exception.SecurityServiceNotFound security_service_id = "fake_security_service_id" e = exception.SecurityServiceNotFound( security_service_id=security_service_id) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(security_service_id, e.msg) def test_volume_not_found(self): # verify response code for exception.VolumeNotFound volume_id = "fake_volume_id" e = exception.VolumeNotFound(volume_id=volume_id) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(volume_id, e.msg) def test_volume_snapshot_not_found(self): # verify response code for exception.VolumeSnapshotNotFound snapshot_id = "fake_snapshot_id" e = exception.VolumeSnapshotNotFound(snapshot_id=snapshot_id) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(snapshot_id, e.msg) def test_share_type_not_found(self): # verify response code for exception.ShareTypeNotFound share_type_id = "fake_share_type_id" e = exception.ShareTypeNotFound(share_type_id=share_type_id) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(share_type_id, e.msg) def test_share_type_not_found_by_name(self): @@ -428,7 +428,7 @@ class ManilaExceptionResponseCode404(test.TestCase): share_type_name = "fake_share_type_name" e = exception.ShareTypeNotFoundByName( share_type_name=share_type_name) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(share_type_name, e.msg) def test_share_type_extra_specs_not_found(self): @@ -437,7 +437,7 @@ class ManilaExceptionResponseCode404(test.TestCase): extra_specs_key = "fake_extra_specs_key" e = exception.ShareTypeExtraSpecsNotFound( share_type_id=share_type_id, extra_specs_key=extra_specs_key) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(share_type_id, e.msg) self.assertIn(extra_specs_key, e.msg) @@ -445,7 +445,7 @@ class ManilaExceptionResponseCode404(test.TestCase): # verify response code for exception.InstanceNotFound instance_id = "fake_instance_id" e = exception.InstanceNotFound(instance_id=instance_id) - self.assertEqual(e.code, 404) + self.assertEqual(404, e.code) self.assertIn(instance_id, e.msg) @@ -454,35 +454,35 @@ class ManilaExceptionResponseCode413(test.TestCase): def test_quota_error(self): # verify response code for exception.QuotaError e = exception.QuotaError() - self.assertEqual(e.code, 413) + self.assertEqual(413, e.code) def test_share_size_exceeds_available_quota(self): # verify response code for exception.ShareSizeExceedsAvailableQuota e = exception.ShareSizeExceedsAvailableQuota() - self.assertEqual(e.code, 413) + self.assertEqual(413, e.code) def test_share_limit_exceeded(self): # verify response code for exception.ShareLimitExceeded allowed = 776 # amount of allowed shares e = exception.ShareLimitExceeded(allowed=allowed) - self.assertEqual(e.code, 413) + self.assertEqual(413, e.code) self.assertIn(str(allowed), e.msg) def test_snapshot_limit_exceeded(self): # verify response code for exception.SnapshotLimitExceeded allowed = 777 # amount of allowed snapshots e = exception.SnapshotLimitExceeded(allowed=allowed) - self.assertEqual(e.code, 413) + self.assertEqual(413, e.code) self.assertIn(str(allowed), e.msg) def test_share_networks_limit_exceeded(self): # verify response code for exception.ShareNetworksLimitExceeded allowed = 778 # amount of allowed share networks e = exception.ShareNetworksLimitExceeded(allowed=allowed) - self.assertEqual(e.code, 413) + self.assertEqual(413, e.code) self.assertIn(str(allowed), e.msg) def test_port_limit_exceeded(self): # verify response code for exception.PortLimitExceeded e = exception.PortLimitExceeded() - self.assertEqual(e.code, 413) + self.assertEqual(413, e.code) diff --git a/manila/tests/test_hacking.py b/manila/tests/test_hacking.py index c7f8219a85..a3c22179fe 100644 --- a/manila/tests/test_hacking.py +++ b/manila/tests/test_hacking.py @@ -58,43 +58,43 @@ class HackingTestCase(test.TestCase): """ def test_no_translate_debug_logs(self): - self.assertEqual(len(list(checks.no_translate_debug_logs( - "LOG.debug(_('foo'))", "manila/scheduler/foo.py"))), 1) + self.assertEqual(1, len(list(checks.no_translate_debug_logs( + "LOG.debug(_('foo'))", "manila/scheduler/foo.py")))) - self.assertEqual(len(list(checks.no_translate_debug_logs( - "LOG.debug('foo')", "manila/scheduler/foo.py"))), 0) + self.assertEqual(0, len(list(checks.no_translate_debug_logs( + "LOG.debug('foo')", "manila/scheduler/foo.py")))) - self.assertEqual(len(list(checks.no_translate_debug_logs( - "LOG.info(_('foo'))", "manila/scheduler/foo.py"))), 0) + self.assertEqual(0, len(list(checks.no_translate_debug_logs( + "LOG.info(_('foo'))", "manila/scheduler/foo.py")))) def test_check_explicit_underscore_import(self): - self.assertEqual(len(list(checks.check_explicit_underscore_import( + self.assertEqual(1, len(list(checks.check_explicit_underscore_import( "LOG.info(_('My info message'))", - "cinder/tests/other_files.py"))), 1) - self.assertEqual(len(list(checks.check_explicit_underscore_import( + "cinder/tests/other_files.py")))) + self.assertEqual(1, len(list(checks.check_explicit_underscore_import( "msg = _('My message')", - "cinder/tests/other_files.py"))), 1) - self.assertEqual(len(list(checks.check_explicit_underscore_import( + "cinder/tests/other_files.py")))) + self.assertEqual(0, len(list(checks.check_explicit_underscore_import( "from cinder.i18n import _", - "cinder/tests/other_files.py"))), 0) - self.assertEqual(len(list(checks.check_explicit_underscore_import( + "cinder/tests/other_files.py")))) + self.assertEqual(0, len(list(checks.check_explicit_underscore_import( "LOG.info(_('My info message'))", - "cinder/tests/other_files.py"))), 0) - self.assertEqual(len(list(checks.check_explicit_underscore_import( + "cinder/tests/other_files.py")))) + self.assertEqual(0, len(list(checks.check_explicit_underscore_import( "msg = _('My message')", - "cinder/tests/other_files.py"))), 0) - self.assertEqual(len(list(checks.check_explicit_underscore_import( + "cinder/tests/other_files.py")))) + self.assertEqual(0, len(list(checks.check_explicit_underscore_import( "from cinder.i18n import _, _LW", - "cinder/tests/other_files2.py"))), 0) - self.assertEqual(len(list(checks.check_explicit_underscore_import( + "cinder/tests/other_files2.py")))) + self.assertEqual(0, len(list(checks.check_explicit_underscore_import( "msg = _('My message')", - "cinder/tests/other_files2.py"))), 0) - self.assertEqual(len(list(checks.check_explicit_underscore_import( + "cinder/tests/other_files2.py")))) + self.assertEqual(0, len(list(checks.check_explicit_underscore_import( "_ = translations.ugettext", - "cinder/tests/other_files3.py"))), 0) - self.assertEqual(len(list(checks.check_explicit_underscore_import( + "cinder/tests/other_files3.py")))) + self.assertEqual(0, len(list(checks.check_explicit_underscore_import( "msg = _('My message')", - "cinder/tests/other_files3.py"))), 0) + "cinder/tests/other_files3.py")))) # We are patching pep8 so that only the check under test is actually # installed. diff --git a/manila/tests/test_manager.py b/manila/tests/test_manager.py index d8e3d46da0..25e874dc80 100644 --- a/manila/tests/test_manager.py +++ b/manila/tests/test_manager.py @@ -41,7 +41,7 @@ class ManagerTestCase(test.TestCase): self.assertTrue(hasattr(fake_manager, 'init_host')) self.assertTrue(hasattr(fake_manager, 'service_version')) self.assertTrue(hasattr(fake_manager, 'service_config')) - self.assertEqual(fake_manager.host, self.host) + self.assertEqual(self.host, fake_manager.host) importutils.import_module.assert_called_once_with(self.db_driver) @ddt.data(True, False) @@ -84,8 +84,8 @@ class SchedulerDependentManagerTestCase(test.TestCase): 'update_service_capabilities')) self.assertTrue(hasattr(self.sched_manager, '_publish_service_capabilities')) - self.assertEqual(self.sched_manager.host, self.host) - self.assertEqual(self.sched_manager.service_name, self.service_name) + self.assertEqual(self.host, self.sched_manager.host) + self.assertEqual(self.service_name, self.sched_manager.service_name) importutils.import_module.assert_called_once_with(self.db_driver) @ddt.data(None, {}, [], '') @@ -118,5 +118,4 @@ class SchedulerDependentManagerTestCase(test.TestCase): @ddt.data(None, '', [], {}, {'foo': 'bar'}) def test_update_service_capabilities(self, capabilities): self.sched_manager.update_service_capabilities(capabilities) - self.assertEqual(capabilities, self.sched_manager.last_capabilities) diff --git a/manila/tests/test_quota.py b/manila/tests/test_quota.py index 0736d2f15d..5a9b24d910 100644 --- a/manila/tests/test_quota.py +++ b/manila/tests/test_quota.py @@ -164,26 +164,26 @@ class BaseResourceTestCase(test.TestCase): def test_no_flag(self): resource = quota.BaseResource('test_resource') - self.assertEqual(resource.name, 'test_resource') + self.assertEqual('test_resource', resource.name) self.assertIsNone(resource.flag) - self.assertEqual(resource.default, -1) + self.assertEqual(-1, resource.default) def test_with_flag(self): # We know this flag exists, so use it... self.flags(quota_shares=10) resource = quota.BaseResource('test_resource', 'quota_shares') - self.assertEqual(resource.name, 'test_resource') - self.assertEqual(resource.flag, 'quota_shares') - self.assertEqual(resource.default, 10) + self.assertEqual('test_resource', resource.name) + self.assertEqual('quota_shares', resource.flag) + self.assertEqual(10, resource.default) def test_with_flag_no_quota(self): self.flags(quota_shares=-1) resource = quota.BaseResource('test_resource', 'quota_shares') - self.assertEqual(resource.name, 'test_resource') - self.assertEqual(resource.flag, 'quota_shares') - self.assertEqual(resource.default, -1) + self.assertEqual('test_resource', resource.name) + self.assertEqual('quota_shares', resource.flag) + self.assertEqual(-1, resource.default) def test_quota_no_project_no_class(self): self.flags(quota_shares=10) @@ -192,7 +192,7 @@ class BaseResourceTestCase(test.TestCase): context = FakeContext(None, None) quota_value = resource.quota(driver, context) - self.assertEqual(quota_value, 10) + self.assertEqual(10, quota_value) def test_quota_with_project_no_class(self): self.flags(quota_shares=10) @@ -203,7 +203,7 @@ class BaseResourceTestCase(test.TestCase): context = FakeContext('test_project', None) quota_value = resource.quota(driver, context) - self.assertEqual(quota_value, 15) + self.assertEqual(15, quota_value) def test_quota_no_project_with_class(self): self.flags(quota_shares=10) @@ -214,7 +214,7 @@ class BaseResourceTestCase(test.TestCase): context = FakeContext(None, 'test_class') quota_value = resource.quota(driver, context) - self.assertEqual(quota_value, 20) + self.assertEqual(20, quota_value) def test_quota_with_project_with_class(self): self.flags(quota_shares=10) @@ -225,7 +225,7 @@ class BaseResourceTestCase(test.TestCase): context = FakeContext('test_project', 'test_class') quota_value = resource.quota(driver, context) - self.assertEqual(quota_value, 15) + self.assertEqual(15, quota_value) def test_quota_override_project_with_class(self): self.flags(quota_shares=10) @@ -237,7 +237,7 @@ class BaseResourceTestCase(test.TestCase): quota_value = resource.quota(driver, context, project_id='override_project') - self.assertEqual(quota_value, 20) + self.assertEqual(20, quota_value) def test_quota_with_project_override_class(self): self.flags(quota_shares=10) @@ -249,35 +249,35 @@ class BaseResourceTestCase(test.TestCase): quota_value = resource.quota(driver, context, quota_class='override_class') - self.assertEqual(quota_value, 20) + self.assertEqual(20, quota_value) class QuotaEngineTestCase(test.TestCase): def test_init(self): quota_obj = quota.QuotaEngine() - self.assertEqual(quota_obj._resources, {}) + self.assertEqual({}, quota_obj._resources) self.assertTrue(isinstance(quota_obj._driver, quota.DbQuotaDriver)) def test_init_override_string(self): quota_obj = quota.QuotaEngine( quota_driver_class='manila.tests.test_quota.FakeDriver') - self.assertEqual(quota_obj._resources, {}) + self.assertEqual({}, quota_obj._resources) self.assertTrue(isinstance(quota_obj._driver, FakeDriver)) def test_init_override_obj(self): quota_obj = quota.QuotaEngine(quota_driver_class=FakeDriver) - self.assertEqual(quota_obj._resources, {}) - self.assertEqual(quota_obj._driver, FakeDriver) + self.assertEqual({}, quota_obj._resources) + self.assertEqual(FakeDriver, quota_obj._driver) def test_register_resource(self): quota_obj = quota.QuotaEngine() resource = quota.AbsoluteResource('test_resource') quota_obj.register_resource(resource) - self.assertEqual(quota_obj._resources, dict(test_resource=resource)) + self.assertEqual(dict(test_resource=resource), quota_obj._resources) def test_register_resources(self): quota_obj = quota.QuotaEngine() @@ -287,10 +287,10 @@ class QuotaEngineTestCase(test.TestCase): quota.AbsoluteResource('test_resource3'), ] quota_obj.register_resources(resources) - self.assertEqual(quota_obj._resources, - dict(test_resource1=resources[0], + self.assertEqual(dict(test_resource1=resources[0], test_resource2=resources[1], - test_resource3=resources[2], )) + test_resource3=resources[2], ), + quota_obj._resources) def test_sync_predeclared(self): quota_obj = quota.QuotaEngine() @@ -301,7 +301,7 @@ class QuotaEngineTestCase(test.TestCase): resource = quota.ReservableResource('test_resource', spam) quota_obj.register_resource(resource) - self.assertEqual(resource.sync, spam) + self.assertEqual(spam, resource.sync) def test_sync_multi(self): quota_obj = quota.QuotaEngine() @@ -316,10 +316,10 @@ class QuotaEngineTestCase(test.TestCase): quota.ReservableResource('test_resource4', spam), ] quota_obj.register_resources(resources[:2]) - self.assertEqual(resources[0].sync, spam) - self.assertEqual(resources[1].sync, spam) - self.assertEqual(resources[2].sync, spam) - self.assertEqual(resources[3].sync, spam) + self.assertEqual(spam, resources[0].sync) + self.assertEqual(spam, resources[1].sync) + self.assertEqual(spam, resources[2].sync) + self.assertEqual(spam, resources[3].sync) def test_get_by_project(self): context = FakeContext('test_project', 'test_class') @@ -330,12 +330,11 @@ class QuotaEngineTestCase(test.TestCase): result = quota_obj.get_by_project(context, 'test_project', 'test_resource') - self.assertEqual(driver.called, - [('get_by_project', + self.assertEqual([('get_by_project', context, 'test_project', - 'test_resource'), ]) - self.assertEqual(result, 42) + 'test_resource'), ], driver.called) + self.assertEqual(42, result) def test_get_by_class(self): context = FakeContext('test_project', 'test_class') @@ -345,11 +344,11 @@ class QuotaEngineTestCase(test.TestCase): quota_obj = quota.QuotaEngine(quota_driver_class=driver) result = quota_obj.get_by_class(context, 'test_class', 'test_resource') - self.assertEqual(driver.called, [('get_by_class', - context, - 'test_class', - 'test_resource'), ]) - self.assertEqual(result, 42) + self.assertEqual([('get_by_class', + context, + 'test_class', + 'test_resource'), ], driver.called) + self.assertEqual(42, result) def _make_quota_obj(self, driver): quota_obj = quota.QuotaEngine(quota_driver_class=driver) @@ -368,10 +367,11 @@ class QuotaEngineTestCase(test.TestCase): quota_obj = self._make_quota_obj(driver) result = quota_obj.get_defaults(context) - self.assertEqual(driver.called, [('get_defaults', - context, - quota_obj._resources), ]) - self.assertEqual(result, quota_obj._resources) + self.assertEqual([('get_defaults', + context, + quota_obj._resources), ], + driver.called) + self.assertEqual(quota_obj._resources, result) def test_get_class_quotas(self): context = FakeContext(None, None) @@ -380,16 +380,16 @@ class QuotaEngineTestCase(test.TestCase): result1 = quota_obj.get_class_quotas(context, 'test_class') result2 = quota_obj.get_class_quotas(context, 'test_class', False) - self.assertEqual(driver.called, [ + self.assertEqual([ ('get_class_quotas', context, quota_obj._resources, 'test_class', True), ('get_class_quotas', context, quota_obj._resources, - 'test_class', False), ]) - self.assertEqual(result1, quota_obj._resources) - self.assertEqual(result2, quota_obj._resources) + 'test_class', False), ], driver.called) + self.assertEqual(quota_obj._resources, result1) + self.assertEqual(quota_obj._resources, result2) def test_get_project_quotas(self): context = FakeContext(None, None) @@ -401,7 +401,7 @@ class QuotaEngineTestCase(test.TestCase): defaults=False, usages=False) - self.assertEqual(driver.called, [ + self.assertEqual([ ('get_project_quotas', context, quota_obj._resources, @@ -417,9 +417,10 @@ class QuotaEngineTestCase(test.TestCase): 'test_class', False, False, - False), ]) - self.assertEqual(result1, quota_obj._resources) - self.assertEqual(result2, quota_obj._resources) + False), ], + driver.called) + self.assertEqual(quota_obj._resources, result1) + self.assertEqual(quota_obj._resources, result2) def test_count_no_resource(self): context = FakeContext(None, None) @@ -439,8 +440,8 @@ class QuotaEngineTestCase(test.TestCase): def test_count(self): def fake_count(context, *args, **kwargs): - self.assertEqual(args, (True,)) - self.assertEqual(kwargs, dict(foo='bar')) + self.assertEqual((True,), args) + self.assertEqual(dict(foo='bar'), kwargs) return 5 context = FakeContext(None, None) @@ -450,7 +451,7 @@ class QuotaEngineTestCase(test.TestCase): fake_count)) result = quota_obj.count(context, 'test_resource5', True, foo='bar') - self.assertEqual(result, 5) + self.assertEqual(5, result) def test_limit_check(self): context = FakeContext(None, None) @@ -459,7 +460,7 @@ class QuotaEngineTestCase(test.TestCase): quota_obj.limit_check(context, test_resource1=4, test_resource2=3, test_resource3=2, test_resource4=1) - self.assertEqual(driver.called, [ + self.assertEqual([ ('limit_check', context, quota_obj._resources, @@ -468,7 +469,8 @@ class QuotaEngineTestCase(test.TestCase): test_resource2=3, test_resource3=2, test_resource4=1,), - None, None), ]) + None, None), ], + driver.called) def test_reserve(self): context = FakeContext(None, None) @@ -487,7 +489,7 @@ class QuotaEngineTestCase(test.TestCase): test_resource1=1, test_resource2=2, test_resource3=3, test_resource4=4) - self.assertEqual(driver.called, [ + self.assertEqual([ ('reserve', context, quota_obj._resources, @@ -519,19 +521,20 @@ class QuotaEngineTestCase(test.TestCase): test_resource3=3, test_resource4=4, ), None, - 'fake_project', None), ]) - self.assertEqual(result1, ['resv-01', - 'resv-02', - 'resv-03', - 'resv-04', ]) - self.assertEqual(result2, ['resv-01', - 'resv-02', - 'resv-03', - 'resv-04', ]) - self.assertEqual(result3, ['resv-01', - 'resv-02', - 'resv-03', - 'resv-04', ]) + 'fake_project', None), ], + driver.called) + self.assertEqual(['resv-01', + 'resv-02', + 'resv-03', + 'resv-04', ], result1) + self.assertEqual(['resv-01', + 'resv-02', + 'resv-03', + 'resv-04', ], result2) + self.assertEqual(['resv-01', + 'resv-02', + 'resv-03', + 'resv-04', ], result3) def test_commit(self): context = FakeContext(None, None) @@ -539,13 +542,12 @@ class QuotaEngineTestCase(test.TestCase): quota_obj = self._make_quota_obj(driver) quota_obj.commit(context, ['resv-01', 'resv-02', 'resv-03']) - self.assertEqual(driver.called, - [('commit', + self.assertEqual([('commit', context, ['resv-01', 'resv-02', 'resv-03'], - None, None), ]) + None, None), ], driver.called) def test_rollback(self): context = FakeContext(None, None) @@ -553,13 +555,12 @@ class QuotaEngineTestCase(test.TestCase): quota_obj = self._make_quota_obj(driver) quota_obj.rollback(context, ['resv-01', 'resv-02', 'resv-03']) - self.assertEqual(driver.called, - [('rollback', + self.assertEqual([('rollback', context, ['resv-01', 'resv-02', 'resv-03'], - None, None), ]) + None, None), ], driver.called) def test_destroy_all_by_project_and_user(self): context = FakeContext(None, None) @@ -568,10 +569,9 @@ class QuotaEngineTestCase(test.TestCase): quota_obj.destroy_all_by_project_and_user(context, 'test_project', 'fake_user') - self.assertEqual(driver.called, [ + self.assertEqual([ ('destroy_all_by_project_and_user', context, 'test_project', - 'fake_user'), - ]) + 'fake_user'), ], driver.called) def test_destroy_all_by_project(self): context = FakeContext(None, None) @@ -579,10 +579,9 @@ class QuotaEngineTestCase(test.TestCase): quota_obj = self._make_quota_obj(driver) quota_obj.destroy_all_by_project(context, 'test_project') - self.assertEqual(driver.called, - [('destroy_all_by_project', + self.assertEqual([('destroy_all_by_project', context, - 'test_project'), ]) + 'test_project'), ], driver.called) def test_expire(self): context = FakeContext(None, None) @@ -590,14 +589,14 @@ class QuotaEngineTestCase(test.TestCase): quota_obj = self._make_quota_obj(driver) quota_obj.expire(context) - self.assertEqual(driver.called, [('expire', context), ]) + self.assertEqual([('expire', context), ], driver.called) def test_resources(self): quota_obj = self._make_quota_obj(None) - self.assertEqual(quota_obj.resources, - ['test_resource1', 'test_resource2', - 'test_resource3', 'test_resource4']) + self.assertEqual(['test_resource1', 'test_resource2', + 'test_resource3', 'test_resource4'], + quota_obj.resources) class DbQuotaDriverTestCase(test.TestCase): @@ -644,7 +643,7 @@ class DbQuotaDriverTestCase(test.TestCase): # Stub out quota_class_get_all_by_name def fake_qcgabn(context, quota_class): self.calls.append('quota_class_get_all_by_name') - self.assertEqual(quota_class, 'test_class') + self.assertEqual('test_class', quota_class) return dict(gigabytes=500, shares=10, snapshot_gigabytes=50) self.mock_object(db, 'quota_class_get_all_by_name', fake_qcgabn) @@ -653,7 +652,7 @@ class DbQuotaDriverTestCase(test.TestCase): result = self.driver.get_class_quotas(None, quota.QUOTAS._resources, 'test_class') - self.assertEqual(self.calls, ['quota_class_get_all_by_name']) + self.assertEqual(['quota_class_get_all_by_name'], self.calls) expected = { "shares": 10, "gigabytes": 500, @@ -668,30 +667,30 @@ class DbQuotaDriverTestCase(test.TestCase): result = self.driver.get_class_quotas(None, quota.QUOTAS._resources, 'test_class', False) - self.assertEqual(self.calls, ['quota_class_get_all_by_name']) + self.assertEqual(['quota_class_get_all_by_name'], self.calls) self.assertEqual( dict(shares=10, gigabytes=500, snapshot_gigabytes=50), result) def _stub_get_by_project_and_user(self): def fake_qgabpu(context, project_id, user_id): self.calls.append('quota_get_all_by_project_and_user') - self.assertEqual(project_id, 'test_project') - self.assertEqual(user_id, 'fake_user') + self.assertEqual('test_project', project_id) + self.assertEqual('fake_user', user_id) return dict( shares=10, gigabytes=50, snapshots=10, snapshot_gigabytes=50, reserved=0) def fake_qgabp(context, project_id): self.calls.append('quota_get_all_by_project') - self.assertEqual(project_id, 'test_project') + self.assertEqual('test_project', project_id) return dict( shares=10, gigabytes=50, snapshots=10, snapshot_gigabytes=50, reserved=0) def fake_qugabpu(context, project_id, user_id): self.calls.append('quota_usage_get_all_by_project_and_user') - self.assertEqual(project_id, 'test_project') - self.assertEqual(user_id, 'fake_user') + self.assertEqual('test_project', project_id) + self.assertEqual('fake_user', user_id) return dict( shares=dict(in_use=2, reserved=0), gigabytes=dict(in_use=10, reserved=0), @@ -712,24 +711,23 @@ class DbQuotaDriverTestCase(test.TestCase): FakeContext('test_project', 'test_class'), quota.QUOTAS._resources, 'test_project', 'fake_user') - self.assertEqual(self.calls, [ + self.assertEqual([ 'quota_get_all_by_project_and_user', 'quota_get_all_by_project', 'quota_usage_get_all_by_project_and_user', - 'quota_class_get_all_by_name', - ]) + 'quota_class_get_all_by_name', ], self.calls) self.assertEqual(self.expected_all_context, result) def _stub_get_by_project(self): def fake_qgabp(context, project_id): self.calls.append('quota_get_all_by_project') - self.assertEqual(project_id, 'test_project') + self.assertEqual('test_project', project_id) return dict( shares=10, gigabytes=50, snapshot_gigabytes=50, reserved=0) def fake_qugabp(context, project_id): self.calls.append('quota_usage_get_all_by_project') - self.assertEqual(project_id, 'test_project') + self.assertEqual('test_project', project_id) return dict( shares=dict(in_use=2, reserved=0), snapshots=dict(in_use=4, reserved=0), @@ -747,9 +745,9 @@ class DbQuotaDriverTestCase(test.TestCase): FakeContext('test_project', 'test_class'), quota.QUOTAS._resources, 'test_project') - self.assertEqual(self.calls, ['quota_get_all_by_project', - 'quota_usage_get_all_by_project', - 'quota_class_get_all_by_name', ]) + self.assertEqual(['quota_get_all_by_project', + 'quota_usage_get_all_by_project', + 'quota_class_get_all_by_name', ], self.calls) self.assertEqual(self.expected_all_context, result) def test_get_project_quotas_with_remains(self): @@ -766,11 +764,10 @@ class DbQuotaDriverTestCase(test.TestCase): FakeContext('other_project', None), quota.QUOTAS._resources, 'test_project', 'fake_user') - self.assertEqual(self.calls, [ + self.assertEqual([ 'quota_get_all_by_project_and_user', 'quota_get_all_by_project', - 'quota_usage_get_all_by_project_and_user', - ]) + 'quota_usage_get_all_by_project_and_user', ], self.calls) self.assertEqual(self.expected_all_context, result) def test_get_project_quotas_alt_context_no_class(self): @@ -779,8 +776,8 @@ class DbQuotaDriverTestCase(test.TestCase): FakeContext('other_project', None), quota.QUOTAS._resources, 'test_project') - self.assertEqual(self.calls, ['quota_get_all_by_project', - 'quota_usage_get_all_by_project', ]) + self.assertEqual(['quota_get_all_by_project', + 'quota_usage_get_all_by_project', ], self.calls) self.assertEqual(self.expected_all_context, result) def test_get_user_quotas_alt_context_with_class(self): @@ -790,12 +787,11 @@ class DbQuotaDriverTestCase(test.TestCase): quota.QUOTAS._resources, 'test_project', 'fake_user', quota_class='test_class') - self.assertEqual(self.calls, [ + self.assertEqual([ 'quota_get_all_by_project_and_user', 'quota_get_all_by_project', 'quota_usage_get_all_by_project_and_user', - 'quota_class_get_all_by_name', - ]) + 'quota_class_get_all_by_name', ], self.calls) self.assertEqual(self.expected_all_context, result) def test_get_project_quotas_alt_context_with_class(self): @@ -804,9 +800,9 @@ class DbQuotaDriverTestCase(test.TestCase): FakeContext('other_project', 'other_class'), quota.QUOTAS._resources, 'test_project', quota_class='test_class') - self.assertEqual(self.calls, ['quota_get_all_by_project', - 'quota_usage_get_all_by_project', - 'quota_class_get_all_by_name', ]) + self.assertEqual(['quota_get_all_by_project', + 'quota_usage_get_all_by_project', + 'quota_class_get_all_by_name', ], self.calls) self.assertEqual(self.expected_all_context, result) def test_get_user_quotas_no_defaults(self): @@ -816,12 +812,11 @@ class DbQuotaDriverTestCase(test.TestCase): quota.QUOTAS._resources, 'test_project', 'fake_user', defaults=False) - self.assertEqual(self.calls, [ + self.assertEqual([ 'quota_get_all_by_project_and_user', 'quota_get_all_by_project', 'quota_usage_get_all_by_project_and_user', - 'quota_class_get_all_by_name', - ]) + 'quota_class_get_all_by_name', ], self.calls) expected = { "shares": {"limit": 10, "in_use": 2, "reserved": 0, }, "gigabytes": {"limit": 50, "in_use": 10, "reserved": 0, }, @@ -836,9 +831,9 @@ class DbQuotaDriverTestCase(test.TestCase): FakeContext('test_project', 'test_class'), quota.QUOTAS._resources, 'test_project', defaults=False) - self.assertEqual(self.calls, ['quota_get_all_by_project', - 'quota_usage_get_all_by_project', - 'quota_class_get_all_by_name', ]) + self.assertEqual(['quota_get_all_by_project', + 'quota_usage_get_all_by_project', + 'quota_class_get_all_by_name', ], self.calls) expected = { "shares": {"limit": 10, "in_use": 2, "reserved": 0, }, "gigabytes": {"limit": 50, "in_use": 10, "reserved": 0, }, @@ -852,11 +847,10 @@ class DbQuotaDriverTestCase(test.TestCase): FakeContext('test_project', 'test_class'), quota.QUOTAS._resources, 'test_project', 'fake_user', usages=False) - self.assertEqual(self.calls, [ + self.assertEqual([ 'quota_get_all_by_project_and_user', 'quota_get_all_by_project', - 'quota_class_get_all_by_name', - ]) + 'quota_class_get_all_by_name', ], self.calls) expected = { "shares": {"limit": 10, }, "gigabytes": {"limit": 50, }, @@ -864,7 +858,7 @@ class DbQuotaDriverTestCase(test.TestCase): "snapshots": {"limit": 10, }, "share_networks": {"limit": 10, }, } - self.assertEqual(result, expected, result) + self.assertEqual(expected, result, result) def test_get_project_quotas_no_usages(self): self._stub_get_by_project() @@ -872,8 +866,8 @@ class DbQuotaDriverTestCase(test.TestCase): FakeContext('test_project', 'test_class'), quota.QUOTAS._resources, 'test_project', usages=False) - self.assertEqual(self.calls, ['quota_get_all_by_project', - 'quota_class_get_all_by_name', ]) + self.assertEqual(['quota_get_all_by_project', + 'quota_class_get_all_by_name', ], self.calls) expected = { "shares": {"limit": 10, }, "gigabytes": {"limit": 50, }, @@ -924,11 +918,10 @@ class DbQuotaDriverTestCase(test.TestCase): FakeContext('test_project', 'test_class'), quota.QUOTAS._resources, 'test_project', user_id='test_user') - self.assertEqual(self.calls, [ + self.assertEqual([ 'get_project_quotas', 'get_user_quotas', - 'quota_get_all_by_project_and_user', - ]) + 'quota_get_all_by_project_and_user', ], self.calls) expected = { "shares": {"minimum": 0, "maximum": 12, }, "gigabytes": {"minimum": 0, "maximum": 1000, }, @@ -936,7 +929,7 @@ class DbQuotaDriverTestCase(test.TestCase): "snapshots": {"minimum": 0, "maximum": 10, }, "share_networks": {"minimum": 0, "maximum": 10, }, } - self.assertEqual(result, expected) + self.assertEqual(expected, result) def test_get_settable_quotas_without_user(self): self._stub_get_settable_quotas() @@ -944,9 +937,7 @@ class DbQuotaDriverTestCase(test.TestCase): FakeContext('test_project', 'test_class'), quota.QUOTAS._resources, 'test_project') - self.assertEqual(self.calls, [ - 'get_project_quotas', - ]) + self.assertEqual(['get_project_quotas', ], self.calls) expected = { "shares": {"minimum": 0, "maximum": -1, }, "gigabytes": {"minimum": 0, "maximum": -1, }, @@ -954,7 +945,7 @@ class DbQuotaDriverTestCase(test.TestCase): "snapshots": {"minimum": 0, "maximum": -1, }, "share_networks": {"minimum": 0, "maximum": -1, }, } - self.assertEqual(result, expected) + self.assertEqual(expected, result) def _stub_get_project_quotas(self): def fake_get_project_quotas(context, resources, project_id, @@ -973,7 +964,7 @@ class DbQuotaDriverTestCase(test.TestCase): self.driver._get_quotas, None, quota.QUOTAS._resources, ['unknown'], True) - self.assertEqual(self.calls, []) + self.assertEqual([], self.calls) def test_get_quotas_no_sync_unknown(self): self._stub_get_project_quotas() @@ -981,7 +972,7 @@ class DbQuotaDriverTestCase(test.TestCase): self.driver._get_quotas, None, quota.QUOTAS._resources, ['unknown'], False) - self.assertEqual(self.calls, []) + self.assertEqual([], self.calls) def test_get_quotas_has_sync_no_sync_resource(self): self._stub_get_project_quotas() @@ -989,7 +980,7 @@ class DbQuotaDriverTestCase(test.TestCase): self.driver._get_quotas, None, quota.QUOTAS._resources, ['metadata_items'], True) - self.assertEqual(self.calls, []) + self.assertEqual([], self.calls) def test_get_quotas_no_sync_has_sync_resource(self): self._stub_get_project_quotas() @@ -997,7 +988,7 @@ class DbQuotaDriverTestCase(test.TestCase): self.driver._get_quotas, None, quota.QUOTAS._resources, ['shares'], False) - self.assertEqual(self.calls, []) + self.assertEqual([], self.calls) def test_get_quotas_has_sync(self): self._stub_get_project_quotas() @@ -1007,8 +998,8 @@ class DbQuotaDriverTestCase(test.TestCase): ['shares', 'gigabytes'], True) - self.assertEqual(self.calls, ['get_project_quotas']) - self.assertEqual(result, dict(shares=10, gigabytes=1000, )) + self.assertEqual(['get_project_quotas'], self.calls) + self.assertEqual(dict(shares=10, gigabytes=1000, ), result) def _stub_quota_reserve(self): def fake_quota_reserve(context, resources, quotas, user_quotas, @@ -1027,7 +1018,7 @@ class DbQuotaDriverTestCase(test.TestCase): FakeContext('test_project', 'test_class'), quota.QUOTAS._resources, dict(shares=2), expire='invalid') - self.assertEqual(self.calls, []) + self.assertEqual([], self.calls) def test_reserve_default_expire(self): self._stub_get_project_quotas() @@ -1037,9 +1028,9 @@ class DbQuotaDriverTestCase(test.TestCase): dict(shares=2)) expire = timeutils.utcnow() + datetime.timedelta(seconds=86400) - self.assertEqual(self.calls, ['get_project_quotas', - ('quota_reserve', expire, 0, 0), ]) - self.assertEqual(result, ['resv-1', 'resv-2', 'resv-3']) + self.assertEqual(['get_project_quotas', + ('quota_reserve', expire, 0, 0), ], self.calls) + self.assertEqual(['resv-1', 'resv-2', 'resv-3'], result) def test_reserve_int_expire(self): self._stub_get_project_quotas() @@ -1049,9 +1040,9 @@ class DbQuotaDriverTestCase(test.TestCase): dict(shares=2), expire=3600) expire = timeutils.utcnow() + datetime.timedelta(seconds=3600) - self.assertEqual(self.calls, ['get_project_quotas', - ('quota_reserve', expire, 0, 0), ]) - self.assertEqual(result, ['resv-1', 'resv-2', 'resv-3']) + self.assertEqual(['get_project_quotas', + ('quota_reserve', expire, 0, 0), ], self.calls) + self.assertEqual(['resv-1', 'resv-2', 'resv-3'], result) def test_reserve_timedelta_expire(self): self._stub_get_project_quotas() @@ -1062,9 +1053,9 @@ class DbQuotaDriverTestCase(test.TestCase): dict(shares=2), expire=expire_delta) expire = timeutils.utcnow() + expire_delta - self.assertEqual(self.calls, ['get_project_quotas', - ('quota_reserve', expire, 0, 0), ]) - self.assertEqual(result, ['resv-1', 'resv-2', 'resv-3']) + self.assertEqual(['get_project_quotas', + ('quota_reserve', expire, 0, 0), ], self.calls) + self.assertEqual(['resv-1', 'resv-2', 'resv-3'], result) def test_reserve_datetime_expire(self): self._stub_get_project_quotas() @@ -1074,9 +1065,9 @@ class DbQuotaDriverTestCase(test.TestCase): quota.QUOTAS._resources, dict(shares=2), expire=expire) - self.assertEqual(self.calls, ['get_project_quotas', - ('quota_reserve', expire, 0, 0), ]) - self.assertEqual(result, ['resv-1', 'resv-2', 'resv-3']) + self.assertEqual(['get_project_quotas', + ('quota_reserve', expire, 0, 0), ], self.calls) + self.assertEqual(['resv-1', 'resv-2', 'resv-3'], result) def test_reserve_until_refresh(self): self._stub_get_project_quotas() @@ -1087,9 +1078,9 @@ class DbQuotaDriverTestCase(test.TestCase): quota.QUOTAS._resources, dict(shares=2), expire=expire) - self.assertEqual(self.calls, ['get_project_quotas', - ('quota_reserve', expire, 500, 0), ]) - self.assertEqual(result, ['resv-1', 'resv-2', 'resv-3']) + self.assertEqual(['get_project_quotas', + ('quota_reserve', expire, 500, 0), ], self.calls) + self.assertEqual(['resv-1', 'resv-2', 'resv-3'], result) def test_reserve_max_age(self): self._stub_get_project_quotas() @@ -1100,9 +1091,9 @@ class DbQuotaDriverTestCase(test.TestCase): quota.QUOTAS._resources, dict(shares=2), expire=expire) - self.assertEqual(self.calls, ['get_project_quotas', - ('quota_reserve', expire, 0, 86400), ]) - self.assertEqual(result, ['resv-1', 'resv-2', 'resv-3']) + self.assertEqual(['get_project_quotas', + ('quota_reserve', expire, 0, 86400), ], self.calls) + self.assertEqual(['resv-1', 'resv-2', 'resv-3'], result) def _stub_quota_delete_all_by_project(self): def fake_quota_delete_all_by_project(context, project_id): @@ -1116,8 +1107,8 @@ class DbQuotaDriverTestCase(test.TestCase): self.driver.destroy_all_by_project(FakeContext('test_project', 'test_class'), 'test_project') - self.assertEqual(self.calls, [('quota_destroy_all_by_project', - ('test_project')), ]) + self.assertEqual([('quota_destroy_all_by_project', + ('test_project')), ], self.calls) class FakeSession(object): @@ -1257,9 +1248,9 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): resource = usage['resource'] for key, value in usage.items(): actual = getattr(usage_dict[resource], key) - self.assertEqual(actual, value, + self.assertEqual(value, actual, "%s != %s on usage for resource %s" % - (actual, value, resource)) + (value, actual, resource)) def _make_reservation(self, uuid, usage_id, project_id, user_id, resource, delta, expire, created_at, updated_at): @@ -1289,11 +1280,11 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): for key, value in resv.items(): actual = getattr(resv_obj, key) - self.assertEqual(actual, value, + self.assertEqual(value, actual, "%s != %s on reservation for resource %s" % - (actual, value, resource)) + (value, actual, resource)) - self.assertEqual(len(reservations), 0) + self.assertEqual(0, len(reservations)) def test_quota_reserve_create_usages(self): context = FakeContext('test_project', 'test_class') @@ -1304,7 +1295,7 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): result = sqa_api.quota_reserve(context, self.resources, quotas, quotas, deltas, self.expire, 0, 0) - self.assertEqual(self.sync_called, set(['shares', 'gigabytes'])) + self.assertEqual(set(['shares', 'gigabytes']), self.sync_called) self.compare_usage(self.usages_created, [dict(resource='shares', project_id='test_project', @@ -1339,7 +1330,7 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): result = sqa_api.quota_reserve(context, self.resources, quotas, quotas, deltas, self.expire, 5, 0) - self.assertEqual(self.sync_called, set(['shares', 'gigabytes'])) + self.assertEqual(set(['shares', 'gigabytes']), self.sync_called) self.compare_usage(self.usages, [dict(resource='shares', project_id='test_project', in_use=2, @@ -1350,7 +1341,7 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): in_use=2, reserved=2 * 1024, until_refresh=5), ]) - self.assertEqual(self.usages_created, {}) + self.assertEqual({}, self.usages_created) self.compare_reservation(result, [dict(resource='shares', usage_id=self.usages['shares'], @@ -1371,7 +1362,7 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): result = sqa_api.quota_reserve(context, self.resources, quotas, quotas, deltas, self.expire, 5, 0) - self.assertEqual(self.sync_called, set(['shares', 'gigabytes'])) + self.assertEqual(set(['shares', 'gigabytes']), self.sync_called) self.compare_usage(self.usages, [dict(resource='shares', project_id='test_project', in_use=2, @@ -1382,7 +1373,7 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): in_use=2, reserved=2 * 1024, until_refresh=5), ]) - self.assertEqual(self.usages_created, {}) + self.assertEqual({}, self.usages_created) self.compare_reservation(result, [dict(resource='shares', usage_id=self.usages['shares'], @@ -1407,7 +1398,7 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): quotas, deltas, self.expire, 0, max_age) - self.assertEqual(self.sync_called, set(['shares', 'gigabytes'])) + self.assertEqual(set(['shares', 'gigabytes']), self.sync_called) self.compare_usage(self.usages, [dict(resource='shares', project_id='test_project', in_use=2, @@ -1418,7 +1409,7 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): in_use=2, reserved=2 * 1024, until_refresh=None), ]) - self.assertEqual(self.usages_created, {}) + self.assertEqual({}, self.usages_created) self.compare_reservation(result, [dict(resource='shares', usage_id=self.usages['shares'], @@ -1437,7 +1428,7 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): result = sqa_api.quota_reserve(context, self.resources, quotas, quotas, deltas, self.expire, 0, 0) - self.assertEqual(self.sync_called, set([])) + self.assertEqual(set([]), self.sync_called) self.compare_usage(self.usages, [dict(resource='shares', project_id='test_project', in_use=3, @@ -1448,7 +1439,7 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): in_use=3, reserved=2 * 1024, until_refresh=None), ]) - self.assertEqual(self.usages_created, {}) + self.assertEqual({}, self.usages_created) self.compare_reservation(result, [dict(resource='shares', usage_id=self.usages['shares'], @@ -1467,7 +1458,7 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): result = sqa_api.quota_reserve(context, self.resources, quotas, quotas, deltas, self.expire, 0, 0) - self.assertEqual(self.sync_called, set([])) + self.assertEqual(set([]), self.sync_called) self.compare_usage(self.usages, [dict(resource='shares', project_id='test_project', in_use=1, @@ -1478,7 +1469,7 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): in_use=1 * 1024, reserved=0, until_refresh=None), ]) - self.assertEqual(self.usages_created, {}) + self.assertEqual({}, self.usages_created) self.compare_reservation(result, [dict(resource='shares', usage_id=self.usages['shares'], @@ -1500,7 +1491,7 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): context, self.resources, quotas, quotas, deltas, self.expire, 0, 0) - self.assertEqual(self.sync_called, set([])) + self.assertEqual(set([]), self.sync_called) self.compare_usage(self.usages, [dict(resource='shares', project_id='test_project', in_use=4, @@ -1511,8 +1502,8 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): in_use=10 * 1024, reserved=0, until_refresh=None), ]) - self.assertEqual(self.usages_created, {}) - self.assertEqual(self.reservations_created, {}) + self.assertEqual({}, self.usages_created) + self.assertEqual({}, self.reservations_created) def test_quota_reserve_reduction(self): self.init_usage('test_project', 'test_user', 'shares', 10, 0) @@ -1524,7 +1515,7 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): result = sqa_api.quota_reserve(context, self.resources, quotas, quotas, deltas, self.expire, 0, 0) - self.assertEqual(self.sync_called, set([])) + self.assertEqual(set([]), self.sync_called) self.compare_usage(self.usages, [dict(resource='shares', project_id='test_project', in_use=10, @@ -1535,7 +1526,7 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): in_use=20 * 1024, reserved=0, until_refresh=None), ]) - self.assertEqual(self.usages_created, {}) + self.assertEqual({}, self.usages_created) self.compare_reservation(result, [dict(resource='shares', usage_id=self.usages['shares'], diff --git a/manila/tests/test_service.py b/manila/tests/test_service.py index c680aa91af..ff64b8d958 100644 --- a/manila/tests/test_service.py +++ b/manila/tests/test_service.py @@ -73,12 +73,12 @@ class ServiceManagerTestCase(test.TestCase): def test_message_gets_to_manager(self): serv = service.Service('test', 'test', 'test', CONF.fake_manager) serv.start() - self.assertEqual(serv.test_method(), 'manager') + self.assertEqual('manager', serv.test_method()) def test_override_manager_method(self): serv = ExtendedService('test', 'test', 'test', CONF.fake_manager) serv.start() - self.assertEqual(serv.test_method(), 'service') + self.assertEqual('service', serv.test_method()) class ServiceFlagsTestCase(test.TestCase): diff --git a/manila/tests/test_utils.py b/manila/tests/test_utils.py index 5db267977b..46b6f3ac3c 100644 --- a/manila/tests/test_utils.py +++ b/manila/tests/test_utils.py @@ -217,13 +217,13 @@ class GenericUtilsTestCase(test.TestCase): self.reload_called = False def test_reload(reloaded_data): - self.assertEqual(reloaded_data, fake_contents) + self.assertEqual(fake_contents, reloaded_data) self.reload_called = True data = utils.read_cached_file("/this/is/a/fake", cache_data, reload_func=test_reload) - self.assertEqual(data, fake_contents) + self.assertEqual(fake_contents, data) self.assertTrue(self.reload_called) fake_file.read.assert_called_once_with() fake_context_manager.__enter__.assert_any_call() @@ -238,7 +238,7 @@ class GenericUtilsTestCase(test.TestCase): self.mock_object(utils, 'execute', fake_execute) contents = utils.read_file_as_root('good') - self.assertEqual(contents, 'fakecontents') + self.assertEqual('fakecontents', contents) self.assertRaises(exception.FileNotFound, utils.read_file_as_root, 'bad') @@ -250,8 +250,8 @@ class GenericUtilsTestCase(test.TestCase): with tempfile.NamedTemporaryFile() as f: with utils.temporary_chown(f.name, owner_uid=2): - self.assertEqual(fake_execute.uid, 2) - self.assertEqual(fake_execute.uid, os.getuid()) + self.assertEqual(2, fake_execute.uid) + self.assertEqual(os.getuid(), fake_execute.uid) def test_service_is_up(self): fts_func = datetime.datetime.fromtimestamp @@ -375,14 +375,14 @@ class MonkeyPatchTestCase(test.TestCase): exampleA = example_a.ExampleClassA() exampleA.example_method() ret_a = exampleA.example_method_add(3, 5) - self.assertEqual(ret_a, 8) + self.assertEqual(8, ret_a) self.assertEqual('Example function', example_b.example_function_b()) exampleB = example_b.ExampleClassB() exampleB.example_method() ret_b = exampleB.example_method_add(3, 5) - self.assertEqual(ret_b, 8) + self.assertEqual(8, ret_b) package_a = self.example_package + 'example_a.' self.assertTrue(package_a + 'example_function_a' in manila.tests.monkey_patch_example.CALLED_FUNCTION) diff --git a/manila/tests/test_wsgi.py b/manila/tests/test_wsgi.py index a19fa6346b..0f9927290e 100644 --- a/manila/tests/test_wsgi.py +++ b/manila/tests/test_wsgi.py @@ -254,7 +254,7 @@ class ExceptionTest(test.TestCase): 'The server has either erred or is incapable ' 'of performing the requested operation.') self.assertIn(expected, six.text_type(resp.body), resp.body) - self.assertEqual(resp.status_int, 500, resp.body) + self.assertEqual(500, resp.status_int, resp.body) def test_safe_exceptions_are_described_in_faults(self): self._do_test_exception_safety_reflected_in_faults(True) @@ -270,12 +270,12 @@ class ExceptionTest(test.TestCase): api = self._wsgi_app(fail) resp = webob.Request.blank('/').get_response(api) self.assertIn(msg, six.text_type(resp.body), resp.body) - self.assertEqual(resp.status_int, exception_type.code, resp.body) + self.assertEqual(exception_type.code, resp.status_int, resp.body) if hasattr(exception_type, 'headers'): for (key, value) in six.iteritems(exception_type.headers): self.assertTrue(key in resp.headers) - self.assertEqual(resp.headers[key], value) + self.assertEqual(value, resp.headers[key]) def test_quota_error_mapping(self): self._do_test_exception_mapping(exception.QuotaError, 'too many used')