Merge "tests: Add image v1, v2 FakeClientMixin"

This commit is contained in:
Zuul 2023-09-06 12:29:14 +00:00 committed by Gerrit Code Review
commit 08faf81d0d
8 changed files with 40 additions and 25 deletions

View File

@ -38,6 +38,7 @@ from openstack.compute.v2 import volume_attachment as _volume_attachment
from openstackclient.api import compute_v2
from openstackclient.tests.unit import fakes
from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes
from openstackclient.tests.unit.image.v2 import fakes as image_fakes
from openstackclient.tests.unit.network.v2 import fakes as network_fakes
from openstackclient.tests.unit import utils
from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
@ -147,7 +148,11 @@ class FakeComputev2Client(object):
self.api_version = api_versions.APIVersion('2.1')
class TestComputev2(network_fakes.FakeClientMixin, utils.TestCommand):
class TestComputev2(
network_fakes.FakeClientMixin,
image_fakes.FakeClientMixin,
utils.TestCommand,
):
def setUp(self):
super().setUp()
@ -166,9 +171,6 @@ class TestComputev2(network_fakes.FakeClientMixin, utils.TestCommand):
token=fakes.AUTH_TOKEN,
)
self.app.client_manager.image = mock.Mock()
self.image_client = self.app.client_manager.image
self.app.client_manager.volume = volume_fakes.FakeVolumeClient(
endpoint=fakes.AUTH_URL,
token=fakes.AUTH_TOKEN,

View File

@ -15,6 +15,7 @@
from unittest import mock
import uuid
from openstack.image.v1 import _proxy
from openstack.image.v1 import image
from openstackclient.tests.unit import fakes
@ -22,13 +23,18 @@ from openstackclient.tests.unit import utils
from openstackclient.tests.unit.volume.v1 import fakes as volume_fakes
class TestImagev1(utils.TestCommand):
class FakeClientMixin:
def setUp(self):
super().setUp()
self.app.client_manager.image = mock.Mock()
self.app.client_manager.image = mock.Mock(spec=_proxy.Proxy)
self.image_client = self.app.client_manager.image
class TestImagev1(FakeClientMixin, utils.TestCommand):
def setUp(self):
super().setUp()
self.app.client_manager.volume = volume_fakes.FakeVolumev1Client(
endpoint=fakes.AUTH_URL,
token=fakes.AUTH_TOKEN,

View File

@ -16,6 +16,7 @@ import random
from unittest import mock
import uuid
from openstack.image.v2 import _proxy
from openstack.image.v2 import image
from openstack.image.v2 import member
from openstack.image.v2 import metadef_namespace
@ -28,13 +29,18 @@ from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
from openstackclient.tests.unit import utils
class TestImagev2(utils.TestCommand):
class FakeClientMixin:
def setUp(self):
super().setUp()
self.app.client_manager.image = mock.Mock()
self.app.client_manager.image = mock.Mock(spec=_proxy.Proxy)
self.image_client = self.app.client_manager.image
class TestImagev2(FakeClientMixin, utils.TestCommand):
def setUp(self):
super().setUp()
self.app.client_manager.identity = identity_fakes.FakeIdentityv3Client(
endpoint=fakes.AUTH_URL,
token=fakes.AUTH_TOKEN,

View File

@ -44,11 +44,6 @@ class TestImage(image_fakes.TestImagev2, volume_fakes.TestVolume):
self.volumes_mock.upload_to_image.return_value = (200, fake_body)
self.volumes_mock.reset_mock()
def setup_images_mock(self, count):
images = image_fakes.create_images(count=count)
return images
class TestImageCreate(TestImage):
project = identity_fakes.FakeProject.create_one_project()
@ -502,7 +497,7 @@ class TestImageDelete(TestImage):
self.cmd = _image.DeleteImage(self.app, None)
def test_image_delete_no_options(self):
images = self.setup_images_mock(count=1)
images = image_fakes.create_images(count=1)
arglist = [
images[0].id,
@ -522,7 +517,7 @@ class TestImageDelete(TestImage):
self.assertIsNone(result)
def test_image_delete_from_store(self):
images = self.setup_images_mock(count=1)
images = image_fakes.create_images(count=1)
arglist = [
images[0].id,
@ -542,7 +537,7 @@ class TestImageDelete(TestImage):
self.assertIsNone(result)
def test_image_delete_multi_images(self):
images = self.setup_images_mock(count=3)
images = image_fakes.create_images(count=3)
arglist = [i.id for i in images]
verifylist = [
@ -562,7 +557,7 @@ class TestImageDelete(TestImage):
self.assertIsNone(result)
def test_image_delete_from_store_without_multi_backend(self):
images = self.setup_images_mock(count=1)
images = image_fakes.create_images(count=1)
arglist = [images[0].id, '--store', 'store1']
verifylist = [('images', [images[0].id]), ('store', 'store1')]
@ -1132,7 +1127,7 @@ class TestImageSet(TestImage):
self.assertIsNone(result)
# we'll have called this but not set anything
self.app.client_manager.image.update_image.assert_called_once_with(
self.image_client.update_image.assert_called_once_with(
self._image.id,
)

View File

@ -18,6 +18,8 @@ import random
from unittest import mock
import uuid
from openstack.image.v1 import _proxy as image_v1_proxy
from openstackclient.tests.unit import fakes
from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes
from openstackclient.tests.unit import utils
@ -65,7 +67,10 @@ class TestVolumev1(utils.TestCommand):
token=fakes.AUTH_TOKEN,
)
self.app.client_manager.image = mock.Mock()
# avoid circular imports by defining this manually rather than using
# openstackclient.tests.unit.image.v1.fakes.FakeClientMixin
self.app.client_manager.image = mock.Mock(spec=image_v1_proxy.Proxy)
self.image_client = self.app.client_manager.image
def create_one_transfer(attrs=None):

View File

@ -44,9 +44,6 @@ class TestVolume(volume_fakes.TestVolumev1):
self.users_mock = self.app.client_manager.identity.users
self.users_mock.reset_mock()
self.app.client_manager.image = mock.Mock()
self.image_client = self.app.client_manager.image
def setup_volumes_mock(self, count):
volumes = volume_fakes.create_volumes(count=count)

View File

@ -20,6 +20,7 @@ import uuid
from cinderclient import api_versions
from openstack.block_storage.v3 import backup as _backup
from openstack.block_storage.v3 import volume
from openstack.image.v2 import _proxy as image_v2_proxy
from osc_lib.cli import format_columns
from openstackclient.tests.unit import fakes
@ -93,10 +94,15 @@ class TestVolume(utils.TestCommand):
self.app.client_manager.volume = FakeVolumeClient(
endpoint=fakes.AUTH_URL, token=fakes.AUTH_TOKEN
)
self.app.client_manager.identity = identity_fakes.FakeIdentityv3Client(
endpoint=fakes.AUTH_URL, token=fakes.AUTH_TOKEN
)
self.app.client_manager.image = mock.Mock()
# avoid circular imports by defining this manually rather than using
# openstackclient.tests.unit.image.v2.fakes.FakeClientMixin
self.app.client_manager.image = mock.Mock(spec=image_v2_proxy.Proxy)
self.image_client = self.app.client_manager.image
def create_one_transfer(attrs=None):

View File

@ -55,8 +55,6 @@ class TestVolume(volume_fakes.TestVolume):
)
self.consistencygroups_mock.reset_mock()
self.image_client = self.app.client_manager.image
def setup_volumes_mock(self, count):
volumes = volume_fakes.create_volumes(count=count)