From 8f07fec3f2ccf510255f1ff2e4dab233be60d0f9 Mon Sep 17 00:00:00 2001 From: Huanxuan Ao Date: Fri, 19 Aug 2016 21:56:24 +0800 Subject: [PATCH] Clean up FakeClient classes in volume fakes Put FakeTransferClient and FakeServiceClient classes into FakeVolumeClient class, I think we need not to create FakeClient classes for every objects, we can use only FakeVolumeClient for all volume objects. This can reduce repetition, unified codes and make codes look cleaner and easier. Change-Id: I2729ef0e80166f4d49ccd9a48b653e2f215e3bfe --- openstackclient/tests/volume/v1/fakes.py | 39 +----------------- .../tests/volume/v1/test_service.py | 2 +- .../tests/volume/v1/test_transfer_request.py | 2 +- openstackclient/tests/volume/v2/fakes.py | 41 ++----------------- .../tests/volume/v2/test_service.py | 2 +- .../tests/volume/v2/test_transfer_request.py | 2 +- 6 files changed, 10 insertions(+), 78 deletions(-) diff --git a/openstackclient/tests/volume/v1/fakes.py b/openstackclient/tests/volume/v1/fakes.py index 2584d4b10d..b96f925dce 100644 --- a/openstackclient/tests/volume/v1/fakes.py +++ b/openstackclient/tests/volume/v1/fakes.py @@ -129,25 +129,6 @@ QOS_WITH_ASSOCIATIONS = { } -class FakeTransferClient(object): - - def __init__(self, **kwargs): - - self.transfers = mock.Mock() - self.transfers.resource_class = fakes.FakeResource(None, {}) - - -class TestTransfer(utils.TestCommand): - - def setUp(self): - super(TestTransfer, self).setUp() - - self.app.client_manager.volume = FakeTransferClient( - endpoint=fakes.AUTH_URL, - token=fakes.AUTH_TOKEN - ) - - class FakeTransfer(object): """Fake one or more Transfer.""" @@ -180,24 +161,6 @@ class FakeTransfer(object): return transfer -class FakeServiceClient(object): - - def __init__(self, **kwargs): - self.services = mock.Mock() - self.services.resource_class = fakes.FakeResource(None, {}) - - -class TestService(utils.TestCommand): - - def setUp(self): - super(TestService, self).setUp() - - self.app.client_manager.volume = FakeServiceClient( - endpoint=fakes.AUTH_URL, - token=fakes.AUTH_TOKEN - ) - - class FakeService(object): """Fake one or more Services.""" @@ -290,6 +253,8 @@ class FakeVolumev1Client(object): self.qos_specs.resource_class = fakes.FakeResource(None, {}) self.volume_types = mock.Mock() self.volume_types.resource_class = fakes.FakeResource(None, {}) + self.transfers = mock.Mock() + self.transfers.resource_class = fakes.FakeResource(None, {}) self.auth_token = kwargs['token'] self.management_url = kwargs['endpoint'] diff --git a/openstackclient/tests/volume/v1/test_service.py b/openstackclient/tests/volume/v1/test_service.py index 7168434496..eb7118a6d4 100644 --- a/openstackclient/tests/volume/v1/test_service.py +++ b/openstackclient/tests/volume/v1/test_service.py @@ -17,7 +17,7 @@ from openstackclient.tests.volume.v1 import fakes as service_fakes from openstackclient.volume.v1 import service -class TestService(service_fakes.TestService): +class TestService(service_fakes.TestVolumev1): def setUp(self): super(TestService, self).setUp() diff --git a/openstackclient/tests/volume/v1/test_transfer_request.py b/openstackclient/tests/volume/v1/test_transfer_request.py index 94e02d62c9..91f5f4b26a 100644 --- a/openstackclient/tests/volume/v1/test_transfer_request.py +++ b/openstackclient/tests/volume/v1/test_transfer_request.py @@ -17,7 +17,7 @@ from openstackclient.tests.volume.v1 import fakes as transfer_fakes from openstackclient.volume.v1 import volume_transfer_request -class TestTransfer(transfer_fakes.TestTransfer): +class TestTransfer(transfer_fakes.TestVolumev1): def setUp(self): super(TestTransfer, self).setUp() diff --git a/openstackclient/tests/volume/v2/fakes.py b/openstackclient/tests/volume/v2/fakes.py index 6809bebd3f..49384bd8ff 100644 --- a/openstackclient/tests/volume/v2/fakes.py +++ b/openstackclient/tests/volume/v2/fakes.py @@ -25,25 +25,6 @@ from openstackclient.tests.image.v2 import fakes as image_fakes from openstackclient.tests import utils -class FakeTransferClient(object): - - def __init__(self, **kwargs): - - self.transfers = mock.Mock() - self.transfers.resource_class = fakes.FakeResource(None, {}) - - -class TestTransfer(utils.TestCommand): - - def setUp(self): - super(TestTransfer, self).setUp() - - self.app.client_manager.volume = FakeTransferClient( - endpoint=fakes.AUTH_URL, - token=fakes.AUTH_TOKEN - ) - - class FakeTransfer(object): """Fake one or more Transfer.""" @@ -108,24 +89,6 @@ class FakeTypeAccess(object): return type_access -class FakeServiceClient(object): - - def __init__(self, **kwargs): - self.services = mock.Mock() - self.services.resource_class = fakes.FakeResource(None, {}) - - -class TestService(utils.TestCommand): - - def setUp(self): - super(TestService, self).setUp() - - self.app.client_manager.volume = FakeServiceClient( - endpoint=fakes.AUTH_URL, - token=fakes.AUTH_TOKEN - ) - - class FakeService(object): """Fake one or more Services.""" @@ -200,6 +163,10 @@ class FakeVolumeClient(object): self.qos_specs.resource_class = fakes.FakeResource(None, {}) self.availability_zones = mock.Mock() self.availability_zones.resource_class = fakes.FakeResource(None, {}) + self.transfers = mock.Mock() + self.transfers.resource_class = fakes.FakeResource(None, {}) + self.services = mock.Mock() + self.services.resource_class = fakes.FakeResource(None, {}) self.auth_token = kwargs['token'] self.management_url = kwargs['endpoint'] diff --git a/openstackclient/tests/volume/v2/test_service.py b/openstackclient/tests/volume/v2/test_service.py index ba2e1b3217..93ddf52879 100644 --- a/openstackclient/tests/volume/v2/test_service.py +++ b/openstackclient/tests/volume/v2/test_service.py @@ -17,7 +17,7 @@ from openstackclient.tests.volume.v2 import fakes as service_fakes from openstackclient.volume.v2 import service -class TestService(service_fakes.TestService): +class TestService(service_fakes.TestVolume): def setUp(self): super(TestService, self).setUp() diff --git a/openstackclient/tests/volume/v2/test_transfer_request.py b/openstackclient/tests/volume/v2/test_transfer_request.py index 945833c939..ea39caa729 100644 --- a/openstackclient/tests/volume/v2/test_transfer_request.py +++ b/openstackclient/tests/volume/v2/test_transfer_request.py @@ -17,7 +17,7 @@ from openstackclient.tests.volume.v2 import fakes as transfer_fakes from openstackclient.volume.v2 import volume_transfer_request -class TestTransfer(transfer_fakes.TestTransfer): +class TestTransfer(transfer_fakes.TestVolume): def setUp(self): super(TestTransfer, self).setUp()