Merge "Completely remove mox from Cinder unittest"
This commit is contained in:
commit
8e1fcabbe0
@ -36,7 +36,6 @@ from oslo_messaging import conffixture as messaging_conffixture
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import strutils
|
||||
from oslo_utils import timeutils
|
||||
from oslotest import moxstubout
|
||||
import six
|
||||
import testtools
|
||||
|
||||
@ -203,11 +202,6 @@ class TestCase(testtools.TestCase):
|
||||
objects_base.CinderObjectRegistry._registry._obj_classes)
|
||||
self.addCleanup(self._restore_obj_registry)
|
||||
|
||||
# emulate some of the mox stuff, we can't use the metaclass
|
||||
# because it screws with our generators
|
||||
mox_fixture = self.useFixture(moxstubout.MoxStubout())
|
||||
self.mox = mox_fixture.mox
|
||||
self.stubs = mox_fixture.stubs
|
||||
self.addCleanup(CONF.reset)
|
||||
self.addCleanup(self._common_cleanup)
|
||||
self.injected = []
|
||||
|
@ -54,8 +54,8 @@ class BackupProjectAttributeTest(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(BackupProjectAttributeTest, self).setUp()
|
||||
self.stubs.Set(backup_api.API, 'get', fake_backup_get)
|
||||
self.stubs.Set(backup_api.API, 'get_all', fake_backup_get_all)
|
||||
self.mock_object(backup_api.API, 'get', fake_backup_get)
|
||||
self.mock_object(backup_api.API, 'get_all', fake_backup_get_all)
|
||||
|
||||
def _send_backup_request(self, ctx, detail=False,
|
||||
version=mv.BACKUP_PROJECT):
|
||||
|
@ -36,7 +36,7 @@ UPDATE_NAME_AFTER_DELETE_TYPE = fake.VOLUME_TYPE5_ID
|
||||
NOT_FOUND_VOLUME_TYPE = fake.WILL_NOT_BE_FOUND_ID
|
||||
|
||||
|
||||
def stub_volume_type(id):
|
||||
def fake_volume_type(id):
|
||||
specs = {"key1": "value1",
|
||||
"key2": "value2",
|
||||
"key3": "value3",
|
||||
@ -48,7 +48,7 @@ def stub_volume_type(id):
|
||||
extra_specs=specs)
|
||||
|
||||
|
||||
def stub_volume_type_updated(id, is_public=True):
|
||||
def fake_volume_type_updated(id, is_public=True):
|
||||
return dict(id=id,
|
||||
name='vol_type_%s_%s' % (six.text_type(id), six.text_type(id)),
|
||||
is_public=is_public,
|
||||
@ -56,7 +56,7 @@ def stub_volume_type_updated(id, is_public=True):
|
||||
six.text_type(id), six.text_type(id)))
|
||||
|
||||
|
||||
def stub_volume_type_updated_desc_only(id):
|
||||
def fake_volume_type_updated_desc_only(id):
|
||||
return dict(id=id,
|
||||
name='vol_type_%s' % six.text_type(id),
|
||||
description='vol_type_desc_%s_%s' % (
|
||||
@ -66,7 +66,7 @@ def stub_volume_type_updated_desc_only(id):
|
||||
def return_volume_types_get_volume_type(context, id):
|
||||
if id == fake.WILL_NOT_BE_FOUND_ID:
|
||||
raise exception.VolumeTypeNotFound(volume_type_id=id)
|
||||
return stub_volume_type(id)
|
||||
return fake_volume_type(id)
|
||||
|
||||
|
||||
def return_volume_types_destroy(context, name):
|
||||
@ -97,13 +97,13 @@ def return_volume_types_create_duplicate_type(context,
|
||||
raise exception.VolumeTypeExists(id=name)
|
||||
|
||||
|
||||
def stub_volume_type_updated_name_only(id):
|
||||
def fake_volume_type_updated_name_only(id):
|
||||
return dict(id=id,
|
||||
name='vol_type_%s_%s' % (six.text_type(id), six.text_type(id)),
|
||||
description='vol_type_desc_%s' % six.text_type(id))
|
||||
|
||||
|
||||
def stub_volume_type_updated_name_after_delete(id):
|
||||
def fake_volume_type_updated_name_after_delete(id):
|
||||
return dict(id=id,
|
||||
name='vol_type_%s' % six.text_type(id),
|
||||
description='vol_type_desc_%s' % six.text_type(id))
|
||||
@ -113,24 +113,24 @@ def return_volume_types_get_volume_type_updated(id, is_public=True):
|
||||
if id == NOT_FOUND_VOLUME_TYPE:
|
||||
raise exception.VolumeTypeNotFound(volume_type_id=id)
|
||||
if id == UPDATE_DESC_ONLY_TYPE:
|
||||
return stub_volume_type_updated_desc_only(id)
|
||||
return fake_volume_type_updated_desc_only(id)
|
||||
if id == UPDATE_NAME_ONLY_TYPE:
|
||||
return stub_volume_type_updated_name_only(id)
|
||||
return fake_volume_type_updated_name_only(id)
|
||||
if id == UPDATE_NAME_AFTER_DELETE_TYPE:
|
||||
return stub_volume_type_updated_name_after_delete(id)
|
||||
return fake_volume_type_updated_name_after_delete(id)
|
||||
|
||||
# anything else
|
||||
return stub_volume_type_updated(id, is_public=is_public)
|
||||
return fake_volume_type_updated(id, is_public=is_public)
|
||||
|
||||
|
||||
def return_volume_types_get_by_name(context, name):
|
||||
if name == NOT_FOUND_VOLUME_TYPE:
|
||||
raise exception.VolumeTypeNotFoundByName(volume_type_name=name)
|
||||
return stub_volume_type(name.split("_")[2])
|
||||
return fake_volume_type(name.split("_")[2])
|
||||
|
||||
|
||||
def return_volume_types_get_default():
|
||||
return stub_volume_type(DEFAULT_VOLUME_TYPE)
|
||||
return fake_volume_type(DEFAULT_VOLUME_TYPE)
|
||||
|
||||
|
||||
def return_volume_types_get_default_not_found():
|
||||
@ -146,10 +146,10 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
"""to reset notifier drivers left over from other api/contrib tests"""
|
||||
|
||||
def test_volume_types_delete(self):
|
||||
self.stubs.Set(volume_types, 'get_volume_type',
|
||||
return_volume_types_get_volume_type)
|
||||
self.stubs.Set(volume_types, 'destroy',
|
||||
return_volume_types_destroy)
|
||||
self.mock_object(volume_types, 'get_volume_type',
|
||||
return_volume_types_get_volume_type)
|
||||
self.mock_object(volume_types, 'destroy',
|
||||
return_volume_types_destroy)
|
||||
|
||||
req = fakes.HTTPRequest.blank('/v2/%s/types/%s' % (
|
||||
fake.PROJECT_ID, DEFAULT_VOLUME_TYPE))
|
||||
@ -158,10 +158,10 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
|
||||
def test_volume_types_delete_not_found(self):
|
||||
self.stubs.Set(volume_types, 'get_volume_type',
|
||||
return_volume_types_get_volume_type)
|
||||
self.stubs.Set(volume_types, 'destroy',
|
||||
return_volume_types_destroy)
|
||||
self.mock_object(volume_types, 'get_volume_type',
|
||||
return_volume_types_get_volume_type)
|
||||
self.mock_object(volume_types, 'destroy',
|
||||
return_volume_types_destroy)
|
||||
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
req = fakes.HTTPRequest.blank('/v2/%s/types/%s' % (
|
||||
@ -171,10 +171,10 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
|
||||
def test_volume_types_with_volumes_destroy(self):
|
||||
self.stubs.Set(volume_types, 'get_volume_type',
|
||||
return_volume_types_get_volume_type)
|
||||
self.stubs.Set(volume_types, 'destroy',
|
||||
return_volume_types_with_volumes_destroy)
|
||||
self.mock_object(volume_types, 'get_volume_type',
|
||||
return_volume_types_get_volume_type)
|
||||
self.mock_object(volume_types, 'destroy',
|
||||
return_volume_types_with_volumes_destroy)
|
||||
req = fakes.HTTPRequest.blank('/v2/%s/types/%s' % (
|
||||
fake.PROJECT_ID, DEFAULT_VOLUME_TYPE))
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
@ -210,10 +210,10 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
req, DEFAULT_VOLUME_TYPE)
|
||||
|
||||
def test_create(self):
|
||||
self.stubs.Set(volume_types, 'create',
|
||||
return_volume_types_create)
|
||||
self.stubs.Set(volume_types, 'get_volume_type_by_name',
|
||||
return_volume_types_get_by_name)
|
||||
self.mock_object(volume_types, 'create',
|
||||
return_volume_types_create)
|
||||
self.mock_object(volume_types, 'get_volume_type_by_name',
|
||||
return_volume_types_get_by_name)
|
||||
|
||||
body = {"volume_type": {"name": "vol_type_1",
|
||||
"os-volume-type-access:is_public": True,
|
||||
@ -268,10 +268,10 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
self.controller._create, req, body)
|
||||
|
||||
def test_create_duplicate_type_fail(self):
|
||||
self.stubs.Set(volume_types, 'create',
|
||||
return_volume_types_create_duplicate_type)
|
||||
self.stubs.Set(volume_types, 'get_volume_type_by_name',
|
||||
return_volume_types_get_by_name)
|
||||
self.mock_object(volume_types, 'create',
|
||||
return_volume_types_create_duplicate_type)
|
||||
self.mock_object(volume_types, 'get_volume_type_by_name',
|
||||
return_volume_types_get_by_name)
|
||||
|
||||
body = {"volume_type": {"name": "vol_type_1",
|
||||
"extra_specs": {"key1": "value1"}}}
|
||||
@ -481,7 +481,7 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
def test_update_db_fail(self, mock_update, mock_get_volume_type):
|
||||
mock_update.side_effect = exception.VolumeTypeUpdateFailed(
|
||||
id=DEFAULT_VOLUME_TYPE)
|
||||
mock_get_volume_type.return_value = stub_volume_type(
|
||||
mock_get_volume_type.return_value = fake_volume_type(
|
||||
DEFAULT_VOLUME_TYPE)
|
||||
|
||||
body = {"volume_type": {"name": "vol_type_1_1",
|
||||
@ -625,8 +625,8 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
|
||||
# delete
|
||||
self.notifier.reset()
|
||||
self.stubs.Set(volume_types, 'destroy',
|
||||
return_volume_types_destroy)
|
||||
self.mock_object(volume_types, 'destroy',
|
||||
return_volume_types_destroy)
|
||||
req = fakes.HTTPRequest.blank('/v2/%s/types/%s' % (
|
||||
fake.PROJECT_ID, UPDATE_NAME_AFTER_DELETE_TYPE))
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
|
@ -34,7 +34,7 @@ UUID = '00000000-0000-0000-0000-000000000001'
|
||||
INVALID_UUID = '00000000-0000-0000-0000-000000000002'
|
||||
|
||||
|
||||
def stub_get(self, context, *args, **kwargs):
|
||||
def fake_get(self, context, *args, **kwargs):
|
||||
vol = {'id': fake.VOLUME_ID,
|
||||
'size': 100,
|
||||
'name': 'fake',
|
||||
@ -64,7 +64,7 @@ def create_snapshot_query_with_metadata(metadata_query_string,
|
||||
class SnapshotApiTest(test.TestCase):
|
||||
def setUp(self):
|
||||
super(SnapshotApiTest, self).setUp()
|
||||
self.stubs.Set(volume.api.API, 'get', stub_get)
|
||||
self.mock_object(volume.api.API, 'get', fake_get)
|
||||
self.controller = snapshots.SnapshotsController()
|
||||
self.ctx = context.RequestContext(fake.USER_ID, fake.PROJECT_ID, True)
|
||||
|
||||
|
@ -84,8 +84,8 @@ class TestNexentaNfsDriver(test.TestCase):
|
||||
self.cfg.nas_host = '1.1.1.1'
|
||||
self.cfg.nas_share_path = 'pool/share'
|
||||
self.nef_mock = mock.Mock()
|
||||
self.stubs.Set(jsonrpc, 'NexentaJSONProxy',
|
||||
lambda *_, **__: self.nef_mock)
|
||||
self.mock_object(jsonrpc, 'NexentaJSONProxy',
|
||||
lambda *_, **__: self.nef_mock)
|
||||
self.drv = nfs.NexentaNfsDriver(configuration=self.cfg)
|
||||
self.drv.db = db
|
||||
self.drv.do_setup(self.ctxt)
|
||||
|
Loading…
Reference in New Issue
Block a user