Using fixtures instead of deprecated mockpatch module

This module mockpatch of oslotest[1] is deprecated since version 1.13
and may be removed in version 2.0. Use fixtures.Mock* classes instead[2]

[1]OpenStack Testing Framework and Utilities
[2]https://docs.openstack.org/developer/oslotest/api/oslotest.mockpatch.html#module-oslotest.mockpatch

Change-Id: Ia0ae1fd162b048e431d202633244c14706436e31
This commit is contained in:
Ngo Quoc Cuong 2017-05-11 14:17:17 +07:00
parent 72d54b6877
commit 33710b3c2d
9 changed files with 111 additions and 104 deletions

View File

@ -12,9 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import fixtures
import mock
from oslo_serialization import jsonutils as json
from oslotest import mockpatch
from tempest.cmd import verify_tempest_config
from tempest import config
@ -73,12 +73,12 @@ class TestDiscovery(base.TestCase):
fake_config.FakePrivate)
def test_get_keystone_api_versions(self):
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, '_get_unversioned_endpoint',
return_value='http://fake_endpoint:5000'))
fake_resp = {'versions': {'values': [{'id': 'v2.0'}, {'id': 'v3.0'}]}}
fake_resp = json.dumps(fake_resp)
self.useFixture(mockpatch.Patch(
self.useFixture(fixtures.MockPatch(
'tempest.lib.common.http.ClosingHttp.request',
return_value=(None, fake_resp)))
fake_os = mock.MagicMock()
@ -87,12 +87,12 @@ class TestDiscovery(base.TestCase):
self.assertIn('v3.0', versions)
def test_get_cinder_api_versions(self):
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, '_get_unversioned_endpoint',
return_value='http://fake_endpoint:5000'))
fake_resp = {'versions': [{'id': 'v1.0'}, {'id': 'v2.0'}]}
fake_resp = json.dumps(fake_resp)
self.useFixture(mockpatch.Patch(
self.useFixture(fixtures.MockPatch(
'tempest.lib.common.http.ClosingHttp.request',
return_value=(None, fake_resp)))
fake_os = mock.MagicMock()
@ -101,12 +101,12 @@ class TestDiscovery(base.TestCase):
self.assertIn('v2.0', versions)
def test_get_nova_versions(self):
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, '_get_unversioned_endpoint',
return_value='http://fake_endpoint:5000'))
fake_resp = {'versions': [{'id': 'v2.0'}, {'id': 'v3.0'}]}
fake_resp = json.dumps(fake_resp)
self.useFixture(mockpatch.Patch(
self.useFixture(fixtures.MockPatch(
'tempest.lib.common.http.ClosingHttp.request',
return_value=(None, fake_resp)))
fake_os = mock.MagicMock()
@ -117,17 +117,17 @@ class TestDiscovery(base.TestCase):
def test_get_versions_invalid_response(self):
# When the response doesn't contain a JSON response, an error is
# logged.
mock_log_error = self.useFixture(mockpatch.PatchObject(
mock_log_error = self.useFixture(fixtures.MockPatchObject(
verify_tempest_config.LOG, 'error')).mock
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, '_get_unversioned_endpoint'))
# Simulated response is not JSON.
sample_body = (
'<html><head>Sample Response</head><body>This is the sample page '
'for the web server. Why are you requesting it?</body></html>')
self.useFixture(mockpatch.Patch(
self.useFixture(fixtures.MockPatch(
'tempest.lib.common.http.ClosingHttp.request',
return_value=(None, sample_body)))
@ -157,7 +157,7 @@ class TestDiscovery(base.TestCase):
@mock.patch('tempest.lib.common.http.ClosingHttp.request')
def test_verify_keystone_api_versions_no_v3(self, mock_request):
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, '_get_unversioned_endpoint',
return_value='http://fake_endpoint:5000'))
fake_resp = {'versions': {'values': [{'id': 'v2.0'}]}}
@ -173,7 +173,7 @@ class TestDiscovery(base.TestCase):
@mock.patch('tempest.lib.common.http.ClosingHttp.request')
def test_verify_keystone_api_versions_no_v2(self, mock_request):
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, '_get_unversioned_endpoint',
return_value='http://fake_endpoint:5000'))
fake_resp = {'versions': {'values': [{'id': 'v3.0'}]}}
@ -189,7 +189,7 @@ class TestDiscovery(base.TestCase):
@mock.patch('tempest.lib.common.http.ClosingHttp.request')
def test_verify_cinder_api_versions_no_v3(self, mock_request):
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, '_get_unversioned_endpoint',
return_value='http://fake_endpoint:5000'))
fake_resp = {'versions': [{'id': 'v2.0'}]}
@ -203,7 +203,7 @@ class TestDiscovery(base.TestCase):
@mock.patch('tempest.lib.common.http.ClosingHttp.request')
def test_verify_cinder_api_versions_no_v2(self, mock_request):
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, '_get_unversioned_endpoint',
return_value='http://fake_endpoint:5000'))
fake_resp = {'versions': [{'id': 'v3.0'}]}
@ -221,7 +221,7 @@ class TestDiscovery(base.TestCase):
@mock.patch('tempest.lib.common.http.ClosingHttp.request')
def test_verify_cinder_api_versions_no_v1(self, mock_request):
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, '_get_unversioned_endpoint',
return_value='http://fake_endpoint:5000'))
fake_resp = {'versions': [{'id': 'v2.0'}, {'id': 'v3.0'}]}
@ -276,7 +276,7 @@ class TestDiscovery(base.TestCase):
fake_os = mock.MagicMock()
fake_os.network_extensions_client.list_extensions = (
fake_list_extensions)
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, 'get_enabled_extensions',
return_value=(['fake1', 'fake2', 'fake3'])))
results = verify_tempest_config.verify_extensions(fake_os,
@ -299,7 +299,7 @@ class TestDiscovery(base.TestCase):
fake_os = mock.MagicMock()
fake_os.network_extensions_client.list_extensions = (
fake_list_extensions)
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, 'get_enabled_extensions',
return_value=(['all'])))
results = verify_tempest_config.verify_extensions(fake_os,
@ -319,7 +319,7 @@ class TestDiscovery(base.TestCase):
fake_os.volumes_extension_client.list_extensions = fake_list_extensions
fake_os.volumes_v2_extension_client.list_extensions = (
fake_list_extensions)
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, 'get_enabled_extensions',
return_value=(['fake1', 'fake2', 'fake3'])))
results = verify_tempest_config.verify_extensions(fake_os,
@ -344,7 +344,7 @@ class TestDiscovery(base.TestCase):
fake_os.volumes_extension_client.list_extensions = fake_list_extensions
fake_os.volumes_v2_extension_client.list_extensions = (
fake_list_extensions)
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, 'get_enabled_extensions',
return_value=(['all'])))
results = verify_tempest_config.verify_extensions(fake_os,
@ -360,7 +360,7 @@ class TestDiscovery(base.TestCase):
{'alias': 'not_fake'}])
fake_os = mock.MagicMock()
fake_os.extensions_client.list_extensions = fake_list_extensions
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, 'get_enabled_extensions',
return_value=(['fake1', 'fake2', 'fake3'])))
results = verify_tempest_config.verify_extensions(fake_os,
@ -382,7 +382,7 @@ class TestDiscovery(base.TestCase):
{'alias': 'not_fake'}]})
fake_os = mock.MagicMock()
fake_os.extensions_client.list_extensions = fake_list_extensions
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, 'get_enabled_extensions',
return_value=(['all'])))
results = verify_tempest_config.verify_extensions(fake_os,
@ -400,7 +400,7 @@ class TestDiscovery(base.TestCase):
'swift': 'metadata'})
fake_os = mock.MagicMock()
fake_os.capabilities_client.list_capabilities = fake_list_extensions
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, 'get_enabled_extensions',
return_value=(['fake1', 'fake2', 'fake3'])))
results = verify_tempest_config.verify_extensions(fake_os, 'swift', {})
@ -422,7 +422,7 @@ class TestDiscovery(base.TestCase):
'swift': 'metadata'})
fake_os = mock.MagicMock()
fake_os.capabilities_client.list_capabilities = fake_list_extensions
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
verify_tempest_config, 'get_enabled_extensions',
return_value=(['all'])))
results = verify_tempest_config.verify_extensions(fake_os,

View File

@ -12,8 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import fixtures
from oslo_config import cfg
from oslotest import mockpatch
from tempest.common import credentials_factory as credentials
from tempest import config
@ -52,16 +52,16 @@ class TestAdminAvailable(base.TestCase):
'project_name': 'admin',
'password': 'p',
'types': ['admin']})
self.useFixture(mockpatch.Patch(
self.useFixture(fixtures.MockPatch(
'tempest.common.preprov_creds.read_accounts_yaml',
return_value=accounts))
cfg.CONF.set_default('test_accounts_file',
use_accounts_file, group='auth')
self.useFixture(mockpatch.Patch('os.path.isfile',
return_value=True))
self.useFixture(fixtures.MockPatch('os.path.isfile',
return_value=True))
else:
self.useFixture(mockpatch.Patch('os.path.isfile',
return_value=False))
self.useFixture(fixtures.MockPatch('os.path.isfile',
return_value=False))
if admin_creds:
username = 'u'
project = 't'

View File

@ -12,8 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import fixtures
from oslo_config import cfg
from oslotest import mockpatch
from tempest.common import credentials_factory as credentials
from tempest import config
@ -39,16 +39,16 @@ class TestAltAvailable(base.TestCase):
accounts = [dict(username="u%s" % ii,
project_name="t%s" % ii,
password="p") for ii in creds]
self.useFixture(mockpatch.Patch(
self.useFixture(fixtures.MockPatch(
'tempest.common.preprov_creds.read_accounts_yaml',
return_value=accounts))
cfg.CONF.set_default('test_accounts_file',
use_accounts_file, group='auth')
self.useFixture(mockpatch.Patch('os.path.isfile',
return_value=True))
self.useFixture(fixtures.MockPatch('os.path.isfile',
return_value=True))
else:
self.useFixture(mockpatch.Patch('os.path.isfile',
return_value=False))
self.useFixture(fixtures.MockPatch('os.path.isfile',
return_value=False))
expected = len(set(creds)) > 1 or dynamic_creds
observed = credentials.is_alt_available(
identity_version=self.identity_version)

View File

@ -12,9 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import fixtures
import mock
from oslo_config import cfg
from oslotest import mockpatch
from tempest.common import credentials_factory as credentials
from tempest.common import dynamic_creds
@ -84,7 +84,7 @@ class TestDynamicCredentialProvider(base.TestCase):
tenant_name='fake_tenant')
def _mock_user_create(self, id, name):
user_fix = self.useFixture(mockpatch.PatchObject(
user_fix = self.useFixture(fixtures.MockPatchObject(
self.users_client.UsersClient,
'create_user',
return_value=(rest_client.ResponseBody
@ -92,7 +92,7 @@ class TestDynamicCredentialProvider(base.TestCase):
return user_fix
def _mock_tenant_create(self, id, name):
tenant_fix = self.useFixture(mockpatch.PatchObject(
tenant_fix = self.useFixture(fixtures.MockPatchObject(
self.tenants_client.TenantsClient,
'create_tenant',
return_value=(rest_client.ResponseBody
@ -100,7 +100,7 @@ class TestDynamicCredentialProvider(base.TestCase):
return tenant_fix
def _mock_list_roles(self, id, name):
roles_fix = self.useFixture(mockpatch.PatchObject(
roles_fix = self.useFixture(fixtures.MockPatchObject(
self.roles_client.RolesClient,
'list_roles',
return_value=(rest_client.ResponseBody
@ -111,7 +111,7 @@ class TestDynamicCredentialProvider(base.TestCase):
return roles_fix
def _mock_list_2_roles(self):
roles_fix = self.useFixture(mockpatch.PatchObject(
roles_fix = self.useFixture(fixtures.MockPatchObject(
self.roles_client.RolesClient,
'list_roles',
return_value=(rest_client.ResponseBody
@ -122,7 +122,7 @@ class TestDynamicCredentialProvider(base.TestCase):
return roles_fix
def _mock_assign_user_role(self):
tenant_fix = self.useFixture(mockpatch.PatchObject(
tenant_fix = self.useFixture(fixtures.MockPatchObject(
self.roles_client.RolesClient,
'create_user_role_on_project',
return_value=(rest_client.ResponseBody
@ -130,7 +130,7 @@ class TestDynamicCredentialProvider(base.TestCase):
return tenant_fix
def _mock_list_role(self):
roles_fix = self.useFixture(mockpatch.PatchObject(
roles_fix = self.useFixture(fixtures.MockPatchObject(
self.roles_client.RolesClient,
'list_roles',
return_value=(rest_client.ResponseBody
@ -140,7 +140,7 @@ class TestDynamicCredentialProvider(base.TestCase):
return roles_fix
def _mock_list_ec2_credentials(self, user_id, tenant_id):
ec2_creds_fix = self.useFixture(mockpatch.PatchObject(
ec2_creds_fix = self.useFixture(fixtures.MockPatchObject(
self.users_client.UsersClient,
'list_user_ec2_credentials',
return_value=(rest_client.ResponseBody
@ -153,21 +153,21 @@ class TestDynamicCredentialProvider(base.TestCase):
return ec2_creds_fix
def _mock_network_create(self, iso_creds, id, name):
net_fix = self.useFixture(mockpatch.PatchObject(
net_fix = self.useFixture(fixtures.MockPatchObject(
iso_creds.networks_admin_client,
'create_network',
return_value={'network': {'id': id, 'name': name}}))
return net_fix
def _mock_subnet_create(self, iso_creds, id, name):
subnet_fix = self.useFixture(mockpatch.PatchObject(
subnet_fix = self.useFixture(fixtures.MockPatchObject(
iso_creds.subnets_admin_client,
'create_subnet',
return_value={'subnet': {'id': id, 'name': name}}))
return subnet_fix
def _mock_router_create(self, id, name):
router_fix = self.useFixture(mockpatch.PatchObject(
router_fix = self.useFixture(fixtures.MockPatchObject(
routers_client.RoutersClient,
'create_router',
return_value={'router': {'id': id, 'name': name}}))
@ -634,7 +634,7 @@ class TestDynamicCredentialProviderV3(TestDynamicCredentialProvider):
def setUp(self):
super(TestDynamicCredentialProviderV3, self).setUp()
self.useFixture(fake_config.ConfigFixture())
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
domains_client.DomainsClient, 'list_domains',
return_value=dict(domains=[dict(id='default',
name='Default')])))
@ -645,7 +645,7 @@ class TestDynamicCredentialProviderV3(TestDynamicCredentialProvider):
pass
def _mock_tenant_create(self, id, name):
project_fix = self.useFixture(mockpatch.PatchObject(
project_fix = self.useFixture(fixtures.MockPatchObject(
self.tenants_client.ProjectsClient,
'create_project',
return_value=(rest_client.ResponseBody

View File

@ -20,9 +20,9 @@ import mock
import six
import testtools
import fixtures
from oslo_concurrency.fixture import lockutils as lockutils_fixtures
from oslo_config import cfg
from oslotest import mockpatch
from tempest.common import preprov_creds
from tempest import config
@ -86,10 +86,11 @@ class TestPreProvisionedCredentials(base.TestCase):
self.patch(self.token_client, side_effect=self.identity_response)
self.useFixture(lockutils_fixtures.ExternalLockFixture())
self.test_accounts = self._fake_accounts(cfg.CONF.identity.admin_role)
self.accounts_mock = self.useFixture(mockpatch.Patch(
self.accounts_mock = self.useFixture(fixtures.MockPatch(
'tempest.common.preprov_creds.read_accounts_yaml',
return_value=self.test_accounts))
self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
self.useFixture(fixtures.MockPatch(
'os.path.isfile', return_value=True))
def tearDown(self):
super(TestPreProvisionedCredentials, self).tearDown()
@ -138,7 +139,8 @@ class TestPreProvisionedCredentials(base.TestCase):
def test_create_hash_file_previous_file(self):
# Emulate the lock existing on the filesystem
self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
self.useFixture(fixtures.MockPatch(
'os.path.isfile', return_value=True))
with mock.patch('six.moves.builtins.open', mock.mock_open(),
create=True):
test_account_class = (
@ -150,7 +152,8 @@ class TestPreProvisionedCredentials(base.TestCase):
def test_create_hash_file_no_previous_file(self):
# Emulate the lock not existing on the filesystem
self.useFixture(mockpatch.Patch('os.path.isfile', return_value=False))
self.useFixture(fixtures.MockPatch(
'os.path.isfile', return_value=False))
with mock.patch('six.moves.builtins.open', mock.mock_open(),
create=True):
test_account_class = (
@ -163,10 +166,12 @@ class TestPreProvisionedCredentials(base.TestCase):
@mock.patch('oslo_concurrency.lockutils.lock')
def test_get_free_hash_no_previous_accounts(self, lock_mock):
# Emulate no pre-existing lock
self.useFixture(mockpatch.Patch('os.path.isdir', return_value=False))
self.useFixture(fixtures.MockPatch(
'os.path.isdir', return_value=False))
hash_list = self._get_hash_list(self.test_accounts)
mkdir_mock = self.useFixture(mockpatch.Patch('os.mkdir'))
self.useFixture(mockpatch.Patch('os.path.isfile', return_value=False))
mkdir_mock = self.useFixture(fixtures.MockPatch('os.mkdir'))
self.useFixture(fixtures.MockPatch(
'os.path.isfile', return_value=False))
test_account_class = preprov_creds.PreProvisionedCredentialProvider(
**self.fixed_params)
with mock.patch('six.moves.builtins.open', mock.mock_open(),
@ -182,9 +187,10 @@ class TestPreProvisionedCredentials(base.TestCase):
def test_get_free_hash_no_free_accounts(self, lock_mock):
hash_list = self._get_hash_list(self.test_accounts)
# Emulate pre-existing lock dir
self.useFixture(mockpatch.Patch('os.path.isdir', return_value=True))
# Emulate all lcoks in list are in use
self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
self.useFixture(fixtures.MockPatch('os.path.isdir', return_value=True))
# Emulate all locks in list are in use
self.useFixture(fixtures.MockPatch(
'os.path.isfile', return_value=True))
test_account_class = preprov_creds.PreProvisionedCredentialProvider(
**self.fixed_params)
with mock.patch('six.moves.builtins.open', mock.mock_open(),
@ -195,7 +201,7 @@ class TestPreProvisionedCredentials(base.TestCase):
@mock.patch('oslo_concurrency.lockutils.lock')
def test_get_free_hash_some_in_use_accounts(self, lock_mock):
# Emulate no pre-existing lock
self.useFixture(mockpatch.Patch('os.path.isdir', return_value=True))
self.useFixture(fixtures.MockPatch('os.path.isdir', return_value=True))
hash_list = self._get_hash_list(self.test_accounts)
test_account_class = preprov_creds.PreProvisionedCredentialProvider(
**self.fixed_params)
@ -219,13 +225,14 @@ class TestPreProvisionedCredentials(base.TestCase):
def test_remove_hash_last_account(self, lock_mock):
hash_list = self._get_hash_list(self.test_accounts)
# Pretend the pseudo-lock is there
self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
self.useFixture(
fixtures.MockPatch('os.path.isfile', return_value=True))
# Pretend the lock dir is empty
self.useFixture(mockpatch.Patch('os.listdir', return_value=[]))
self.useFixture(fixtures.MockPatch('os.listdir', return_value=[]))
test_account_class = preprov_creds.PreProvisionedCredentialProvider(
**self.fixed_params)
remove_mock = self.useFixture(mockpatch.Patch('os.remove'))
rmdir_mock = self.useFixture(mockpatch.Patch('os.rmdir'))
remove_mock = self.useFixture(fixtures.MockPatch('os.remove'))
rmdir_mock = self.useFixture(fixtures.MockPatch('os.rmdir'))
test_account_class.remove_hash(hash_list[2])
hash_path = os.path.join(self.fixed_params['accounts_lock_dir'],
hash_list[2])
@ -237,14 +244,15 @@ class TestPreProvisionedCredentials(base.TestCase):
def test_remove_hash_not_last_account(self, lock_mock):
hash_list = self._get_hash_list(self.test_accounts)
# Pretend the pseudo-lock is there
self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
self.useFixture(fixtures.MockPatch(
'os.path.isfile', return_value=True))
# Pretend the lock dir is empty
self.useFixture(mockpatch.Patch('os.listdir', return_value=[
self.useFixture(fixtures.MockPatch('os.listdir', return_value=[
hash_list[1], hash_list[4]]))
test_account_class = preprov_creds.PreProvisionedCredentialProvider(
**self.fixed_params)
remove_mock = self.useFixture(mockpatch.Patch('os.remove'))
rmdir_mock = self.useFixture(mockpatch.Patch('os.rmdir'))
remove_mock = self.useFixture(fixtures.MockPatch('os.remove'))
rmdir_mock = self.useFixture(fixtures.MockPatch('os.rmdir'))
test_account_class.remove_hash(hash_list[2])
hash_path = os.path.join(self.fixed_params['accounts_lock_dir'],
hash_list[2])
@ -258,7 +266,7 @@ class TestPreProvisionedCredentials(base.TestCase):
def test_is_not_multi_user(self):
self.test_accounts = [self.test_accounts[0]]
self.useFixture(mockpatch.Patch(
self.useFixture(fixtures.MockPatch(
'tempest.common.preprov_creds.read_accounts_yaml',
return_value=self.test_accounts))
test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
@ -270,7 +278,7 @@ class TestPreProvisionedCredentials(base.TestCase):
**self.fixed_params)
hashes = test_accounts_class.hash_dict['roles']['role4']
temp_hash = hashes[0]
get_free_hash_mock = self.useFixture(mockpatch.PatchObject(
get_free_hash_mock = self.useFixture(fixtures.MockPatchObject(
test_accounts_class, '_get_free_hash', return_value=temp_hash))
# Test a single role returns all matching roles
test_accounts_class._get_creds(roles=['role4'])
@ -287,7 +295,7 @@ class TestPreProvisionedCredentials(base.TestCase):
hashes2 = test_accounts_class.hash_dict['roles']['role2']
hashes = list(set(hashes) & set(hashes2))
temp_hash = hashes[0]
get_free_hash_mock = self.useFixture(mockpatch.PatchObject(
get_free_hash_mock = self.useFixture(fixtures.MockPatchObject(
test_accounts_class, '_get_free_hash', return_value=temp_hash))
# Test an intersection of multiple roles
test_accounts_class._get_creds(roles=['role2', 'role4'])
@ -304,7 +312,7 @@ class TestPreProvisionedCredentials(base.TestCase):
admin_hashes = test_accounts_class.hash_dict['roles'][
cfg.CONF.identity.admin_role]
temp_hash = hashes[0]
get_free_hash_mock = self.useFixture(mockpatch.PatchObject(
get_free_hash_mock = self.useFixture(fixtures.MockPatchObject(
test_accounts_class, '_get_free_hash', return_value=temp_hash))
# Test an intersection of multiple roles
test_accounts_class._get_creds()
@ -322,7 +330,7 @@ class TestPreProvisionedCredentials(base.TestCase):
{'username': 'test_user14', 'tenant_name': 'test_tenant14',
'password': 'p', 'roles': ['role-7', 'role-11'],
'resources': {'network': 'network-2'}}]
self.useFixture(mockpatch.Patch(
self.useFixture(fixtures.MockPatch(
'tempest.common.preprov_creds.read_accounts_yaml',
return_value=test_accounts))
test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
@ -350,7 +358,7 @@ class TestPreProvisionedCredentials(base.TestCase):
def test_get_primary_creds_none_available(self):
admin_accounts = [x for x in self.test_accounts if 'test_admin'
in x['username']]
self.useFixture(mockpatch.Patch(
self.useFixture(fixtures.MockPatch(
'tempest.common.preprov_creds.read_accounts_yaml',
return_value=admin_accounts))
test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
@ -368,7 +376,7 @@ class TestPreProvisionedCredentials(base.TestCase):
def test_get_alt_creds_none_available(self):
admin_accounts = [x for x in self.test_accounts if 'test_admin'
in x['username']]
self.useFixture(mockpatch.Patch(
self.useFixture(fixtures.MockPatch(
'tempest.common.preprov_creds.read_accounts_yaml',
return_value=admin_accounts))
test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
@ -389,7 +397,7 @@ class TestPreProvisionedCredentials(base.TestCase):
'password': 'p', 'roles': ['role1', 'role2', 'role3', 'role4']},
{'username': 'test_admin1', 'tenant_name': 'test_tenant11',
'password': 'p', 'types': ['admin']}]
self.useFixture(mockpatch.Patch(
self.useFixture(fixtures.MockPatch(
'tempest.common.preprov_creds.read_accounts_yaml',
return_value=test_accounts))
test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
@ -403,7 +411,7 @@ class TestPreProvisionedCredentials(base.TestCase):
'password': 'p', 'roles': ['role1', 'role2', 'role3', 'role4']},
{'username': 'test_admin1', 'tenant_name': 'test_tenant11',
'password': 'p', 'roles': [cfg.CONF.identity.admin_role]}]
self.useFixture(mockpatch.Patch(
self.useFixture(fixtures.MockPatch(
'tempest.common.preprov_creds.read_accounts_yaml',
return_value=test_accounts))
test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
@ -414,7 +422,7 @@ class TestPreProvisionedCredentials(base.TestCase):
def test_get_admin_creds_none_available(self):
non_admin_accounts = [x for x in self.test_accounts if 'test_admin'
not in x['username']]
self.useFixture(mockpatch.Patch(
self.useFixture(fixtures.MockPatch(
'tempest.common.preprov_creds.read_accounts_yaml',
return_value=non_admin_accounts))
test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(

View File

@ -16,7 +16,6 @@ import time
import fixtures
from oslo_config import cfg
from oslotest import mockpatch
from tempest.common.utils.linux import remote_client
from tempest import config
@ -64,8 +63,8 @@ class TestRemoteClient(base.TestCase):
cfg.CONF.set_default('connect_timeout', 1, group='validation')
self.conn = remote_client.RemoteClient('127.0.0.1', 'user', 'pass')
self.ssh_mock = self.useFixture(mockpatch.PatchObject(self.conn,
'ssh_client'))
self.ssh_mock = self.useFixture(fixtures.MockPatchObject(self.conn,
'ssh_client'))
def test_write_to_console_regular_str(self):
self.conn.write_to_console('test')
@ -111,7 +110,7 @@ sdb 8:16 0 1000204886016 0 disk"""
booted_at = 10000
uptime_sec = 5000.02
self.ssh_mock.mock.exec_command.return_value = uptime_sec
self.useFixture(mockpatch.PatchObject(
self.useFixture(fixtures.MockPatchObject(
time, 'time', return_value=booted_at + uptime_sec))
self.assertEqual(self.conn.get_boot_time(),
time.localtime(booted_at))

View File

@ -16,7 +16,7 @@
import copy
import datetime
from oslotest import mockpatch
import fixtures
import testtools
from tempest.lib import auth
@ -82,9 +82,9 @@ class TestBaseAuthProvider(BaseAuthTestsSetUp):
def test_auth_data_property_when_cache_exists(self):
self.auth_provider.cache = 'foo'
self.useFixture(mockpatch.PatchObject(self.auth_provider,
'is_expired',
return_value=False))
self.useFixture(fixtures.MockPatchObject(self.auth_provider,
'is_expired',
return_value=False))
self.assertEqual('foo', getattr(self.auth_provider, 'auth_data'))
def test_delete_auth_data_property_through_deleter(self):

View File

@ -15,8 +15,8 @@
import copy
import json
import fixtures
import jsonschema
from oslotest import mockpatch
import six
from tempest.lib.common import http
@ -38,16 +38,16 @@ class BaseRestClientTestClass(base.TestCase):
self.rest_client = rest_client.RestClient(
self.fake_auth_provider, None, None)
self.patchobject(http.ClosingHttp, 'request', self.fake_http.request)
self.useFixture(mockpatch.PatchObject(self.rest_client,
'_log_request'))
self.useFixture(fixtures.MockPatchObject(self.rest_client,
'_log_request'))
class TestRestClientHTTPMethods(BaseRestClientTestClass):
def setUp(self):
self.fake_http = fake_http.fake_httplib2()
super(TestRestClientHTTPMethods, self).setUp()
self.useFixture(mockpatch.PatchObject(self.rest_client,
'_error_checker'))
self.useFixture(fixtures.MockPatchObject(self.rest_client,
'_error_checker'))
def test_post(self):
__, return_dict = self.rest_client.post(self.url, {}, {})
@ -70,8 +70,8 @@ class TestRestClientHTTPMethods(BaseRestClientTestClass):
self.assertEqual('PUT', return_dict['method'])
def test_head(self):
self.useFixture(mockpatch.PatchObject(self.rest_client,
'response_checker'))
self.useFixture(fixtures.MockPatchObject(self.rest_client,
'response_checker'))
__, return_dict = self.rest_client.head(self.url)
self.assertEqual('HEAD', return_dict['method'])
@ -122,8 +122,8 @@ class TestRestClientHeadersJSON(TestRestClientHTTPMethods):
self._verify_headers(resp)
def test_head(self):
self.useFixture(mockpatch.PatchObject(self.rest_client,
'response_checker'))
self.useFixture(fixtures.MockPatchObject(self.rest_client,
'response_checker'))
resp, __ = self.rest_client.head(self.url)
self._verify_headers(resp)
@ -136,8 +136,8 @@ class TestRestClientUpdateHeaders(BaseRestClientTestClass):
def setUp(self):
self.fake_http = fake_http.fake_httplib2()
super(TestRestClientUpdateHeaders, self).setUp()
self.useFixture(mockpatch.PatchObject(self.rest_client,
'_error_checker'))
self.useFixture(fixtures.MockPatchObject(self.rest_client,
'_error_checker'))
self.headers = {'X-Configuration-Session': 'session_id'}
def test_post_update_headers(self):
@ -201,8 +201,8 @@ class TestRestClientUpdateHeaders(BaseRestClientTestClass):
)
def test_head_update_headers(self):
self.useFixture(mockpatch.PatchObject(self.rest_client,
'response_checker'))
self.useFixture(fixtures.MockPatchObject(self.rest_client,
'response_checker'))
__, return_dict = self.rest_client.head(self.url,
extra_headers=True,
@ -1145,8 +1145,8 @@ class TestRestClientJSONSchemaValidatorVersion(TestJSONSchemaValidationBase):
}
def test_current_json_schema_validator_version(self):
with mockpatch.PatchObject(jsonschema.Draft4Validator,
"check_schema") as chk_schema:
with fixtures.MockPatchObject(jsonschema.Draft4Validator,
"check_schema") as chk_schema:
body = {'foo': 'test'}
self._test_validate_pass(self.schema, body)
chk_schema.mock.assert_called_once_with(

View File

@ -12,8 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import fixtures
from oslo_config import cfg
from oslotest import mockpatch
import testtools
from tempest import config
@ -95,8 +95,8 @@ class TestServicesDecorator(BaseDecoratorsTest):
'bad_service')
def test_services_decorator_with_service_valid_and_unavailable(self):
self.useFixture(mockpatch.PatchObject(test.CONF.service_available,
'cinder', False))
self.useFixture(fixtures.MockPatchObject(test.CONF.service_available,
'cinder', False))
self.assertRaises(testtools.TestCase.skipException,
self._test_services_helper, 'compute',
'volume')