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: I916b9fd3ccd50b2f61850fcce2056f3b5833ba24
This commit is contained in:
@@ -12,8 +12,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import fixtures
|
||||
from oslo_serialization import jsonutils as json
|
||||
from oslotest import mockpatch
|
||||
|
||||
from tempest.tests import base
|
||||
from tempest.tests.lib import fake_http
|
||||
@@ -33,7 +33,7 @@ class BaseServiceTest(base.TestCase):
|
||||
body, to_utf=False, status=200,
|
||||
headers=None, **kwargs):
|
||||
mocked_response = self.create_response(body, to_utf, status, headers)
|
||||
self.useFixture(mockpatch.Patch(
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
function2mock, return_value=mocked_response))
|
||||
if kwargs:
|
||||
resp = function(**kwargs)
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
|
||||
import copy
|
||||
|
||||
import fixtures
|
||||
from oslo_serialization import jsonutils as json
|
||||
from oslotest import mockpatch
|
||||
|
||||
from tempest.lib.services.compute import flavors_client
|
||||
from tempest.tests.lib import fake_auth_provider
|
||||
@@ -118,7 +118,7 @@ class TestFlavorsClient(base.BaseServiceTest):
|
||||
if bytes_body:
|
||||
body = body.encode('utf-8')
|
||||
response = fake_http.fake_http_response({}, status=200), body
|
||||
self.useFixture(mockpatch.Patch(
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
'tempest.lib.common.rest_client.RestClient.get',
|
||||
return_value=response))
|
||||
self.assertEqual(is_deleted,
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslotest import mockpatch
|
||||
import fixtures
|
||||
|
||||
from tempest.lib import exceptions as lib_exc
|
||||
from tempest.lib.services.compute import floating_ips_client
|
||||
@@ -99,14 +99,14 @@ class TestFloatingIpsClient(base.BaseServiceTest):
|
||||
server_id='c782b7a9-33cd-45f0-b795-7f87f456408b')
|
||||
|
||||
def test_is_resource_deleted_true(self):
|
||||
self.useFixture(mockpatch.Patch(
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
'tempest.lib.services.compute.floating_ips_client.'
|
||||
'FloatingIPsClient.show_floating_ip',
|
||||
side_effect=lib_exc.NotFound()))
|
||||
self.assertTrue(self.client.is_resource_deleted('fake-id'))
|
||||
|
||||
def test_is_resource_deleted_false(self):
|
||||
self.useFixture(mockpatch.Patch(
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
'tempest.lib.services.compute.floating_ips_client.'
|
||||
'FloatingIPsClient.show_floating_ip',
|
||||
return_value={"floating_ip": TestFloatingIpsClient.floating_ip}))
|
||||
|
||||
@@ -14,8 +14,7 @@
|
||||
|
||||
import copy
|
||||
|
||||
from oslotest import mockpatch
|
||||
|
||||
import fixtures
|
||||
from tempest.lib import exceptions as lib_exc
|
||||
from tempest.lib.services.compute import images_client
|
||||
from tempest.tests.lib import fake_auth_provider
|
||||
@@ -187,15 +186,15 @@ class TestImagesClient(base.BaseServiceTest):
|
||||
def _test_resource_deleted(self, bytes_body=False):
|
||||
params = {"id": self.FAKE_IMAGE_ID}
|
||||
expected_op = self.FAKE_IMAGE_DATA['show']
|
||||
self.useFixture(mockpatch.Patch('tempest.lib.services.compute'
|
||||
self.useFixture(fixtures.MockPatch('tempest.lib.services.compute'
|
||||
'.images_client.ImagesClient.show_image',
|
||||
side_effect=lib_exc.NotFound))
|
||||
side_effect=lib_exc.NotFound))
|
||||
self.assertEqual(True, self.client.is_resource_deleted(**params))
|
||||
tempdata = copy.deepcopy(self.FAKE_IMAGE_DATA['show'])
|
||||
tempdata['image']['id'] = None
|
||||
self.useFixture(mockpatch.Patch('tempest.lib.services.compute'
|
||||
self.useFixture(fixtures.MockPatch('tempest.lib.services.compute'
|
||||
'.images_client.ImagesClient.show_image',
|
||||
return_value=expected_op))
|
||||
return_value=expected_op))
|
||||
self.assertEqual(False, self.client.is_resource_deleted(**params))
|
||||
|
||||
def test_list_images_with_str_body(self):
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslotest import mockpatch
|
||||
import fixtures
|
||||
|
||||
from tempest.lib import exceptions as lib_exc
|
||||
from tempest.lib.services.compute import security_groups_client
|
||||
@@ -103,11 +103,11 @@ class TestSecurityGroupsClient(base.BaseServiceTest):
|
||||
def test_is_resource_deleted_true(self):
|
||||
mod = ('tempest.lib.services.compute.security_groups_client.'
|
||||
'SecurityGroupsClient.show_security_group')
|
||||
self.useFixture(mockpatch.Patch(mod, side_effect=lib_exc.NotFound))
|
||||
self.useFixture(fixtures.MockPatch(mod, side_effect=lib_exc.NotFound))
|
||||
self.assertTrue(self.client.is_resource_deleted('fake-id'))
|
||||
|
||||
def test_is_resource_deleted_false(self):
|
||||
mod = ('tempest.lib.services.compute.security_groups_client.'
|
||||
'SecurityGroupsClient.show_security_group')
|
||||
self.useFixture(mockpatch.Patch(mod, return_value='success'))
|
||||
self.useFixture(fixtures.MockPatch(mod, return_value='success'))
|
||||
self.assertFalse(self.client.is_resource_deleted('fake-id'))
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslotest import mockpatch
|
||||
import fixtures
|
||||
from tempest.tests.lib import fake_auth_provider
|
||||
|
||||
from tempest.lib.services.compute import server_groups_client
|
||||
@@ -50,7 +50,7 @@ class TestServerGroupsClient(base.BaseServiceTest):
|
||||
|
||||
def test_delete_server_group(self):
|
||||
response = fake_http.fake_http_response({}, status=204), ''
|
||||
self.useFixture(mockpatch.Patch(
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
'tempest.lib.common.rest_client.RestClient.delete',
|
||||
return_value=response))
|
||||
self.client.delete_server_group('fake-group')
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslotest import mockpatch
|
||||
import fixtures
|
||||
|
||||
from tempest.lib import exceptions as lib_exc
|
||||
from tempest.lib.services.compute import snapshots_client
|
||||
@@ -91,13 +91,13 @@ class TestSnapshotsClient(base.BaseServiceTest):
|
||||
def test_is_resource_deleted_true(self):
|
||||
module = ('tempest.lib.services.compute.snapshots_client.'
|
||||
'SnapshotsClient.show_snapshot')
|
||||
self.useFixture(mockpatch.Patch(
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
module, side_effect=lib_exc.NotFound))
|
||||
self.assertTrue(self.client.is_resource_deleted('fake-id'))
|
||||
|
||||
def test_is_resource_deleted_false(self):
|
||||
module = ('tempest.lib.services.compute.snapshots_client.'
|
||||
'SnapshotsClient.show_snapshot')
|
||||
self.useFixture(mockpatch.Patch(
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
module, return_value={}))
|
||||
self.assertFalse(self.client.is_resource_deleted('fake-id'))
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
import copy
|
||||
|
||||
from oslotest import mockpatch
|
||||
import fixtures
|
||||
|
||||
from tempest.lib.services.compute import versions_client
|
||||
from tempest.tests.lib import fake_auth_provider
|
||||
@@ -73,7 +73,7 @@ class TestVersionsClient(base.BaseServiceTest):
|
||||
200)
|
||||
|
||||
def _test_get_version_by_url(self, bytes_body=False):
|
||||
self.useFixture(mockpatch.Patch(
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
"tempest.lib.common.rest_client.RestClient.token",
|
||||
return_value="Dummy Token"))
|
||||
params = {"version_url": self.versions_client._get_base_version_url()}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
import copy
|
||||
|
||||
from oslotest import mockpatch
|
||||
import fixtures
|
||||
|
||||
from tempest.lib import exceptions as lib_exc
|
||||
from tempest.lib.services.compute import volumes_client
|
||||
@@ -102,13 +102,13 @@ class TestVolumesClient(base.BaseServiceTest):
|
||||
def test_is_resource_deleted_true(self):
|
||||
module = ('tempest.lib.services.compute.volumes_client.'
|
||||
'VolumesClient.show_volume')
|
||||
self.useFixture(mockpatch.Patch(
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
module, side_effect=lib_exc.NotFound))
|
||||
self.assertTrue(self.client.is_resource_deleted('fake-id'))
|
||||
|
||||
def test_is_resource_deleted_false(self):
|
||||
module = ('tempest.lib.services.compute.volumes_client.'
|
||||
'VolumesClient.show_volume')
|
||||
self.useFixture(mockpatch.Patch(
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
module, return_value={}))
|
||||
self.assertFalse(self.client.is_resource_deleted('fake-id'))
|
||||
|
||||
Reference in New Issue
Block a user