Merge Fake OpenStack Clients from two UTs
After moving the 'Fake' test objects to a special module, it is now possible to get rid of the Fake OpenStack clients used previously in the tests.test_osclients module. Blueprint unit-tests-refactoring Change-Id: I80e695d2498d074602cfa22982ea55f3e5a53c37
This commit is contained in:
parent
9b1ee113e8
commit
2e2ac499ac
@ -259,10 +259,16 @@ class FakeVolumeBackupManager(FakeManager):
|
|||||||
return self._cache(backup)
|
return self._cache(backup)
|
||||||
|
|
||||||
|
|
||||||
|
class FakeServiceCatalog(object):
|
||||||
|
def get_endpoints(self):
|
||||||
|
return {'image': [{'publicURL': 'http://fake.to'}]}
|
||||||
|
|
||||||
|
|
||||||
class FakeGlanceClient(object):
|
class FakeGlanceClient(object):
|
||||||
|
|
||||||
def __init__(self, nova_client):
|
def __init__(self, nova_client=None):
|
||||||
self.images = nova_client.images
|
if nova_client:
|
||||||
|
self.images = nova_client.images
|
||||||
|
|
||||||
|
|
||||||
class FakeCinderClient(object):
|
class FakeCinderClient(object):
|
||||||
@ -295,6 +301,11 @@ class FakeKeystoneClient(object):
|
|||||||
self.tenants = FakeTenantsManager()
|
self.tenants = FakeTenantsManager()
|
||||||
self.users = FakeUsersManager()
|
self.users = FakeUsersManager()
|
||||||
self.project_id = 'abc123'
|
self.project_id = 'abc123'
|
||||||
|
self.auth_token = 'fake'
|
||||||
|
self.service_catalog = FakeServiceCatalog()
|
||||||
|
|
||||||
|
def authenticate(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class FakeClients(object):
|
class FakeClients(object):
|
||||||
|
@ -17,32 +17,7 @@ import mock
|
|||||||
|
|
||||||
from rally import osclients
|
from rally import osclients
|
||||||
from rally import test
|
from rally import test
|
||||||
|
from tests import fakes
|
||||||
|
|
||||||
class FakeServiceCatalog(object):
|
|
||||||
def get_endpoints(self):
|
|
||||||
return {'image': [{'publicURL': 'http://fake.to'}]}
|
|
||||||
|
|
||||||
|
|
||||||
class FakeNova(object):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class FakeGlance(object):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class FakeCinder(object):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class FakeKeystone(object):
|
|
||||||
def __init__(self):
|
|
||||||
self.auth_token = 'fake'
|
|
||||||
self.service_catalog = FakeServiceCatalog()
|
|
||||||
|
|
||||||
def authenticate(self):
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class OSClientsTestCase(test.TestCase):
|
class OSClientsTestCase(test.TestCase):
|
||||||
@ -62,7 +37,7 @@ class OSClientsTestCase(test.TestCase):
|
|||||||
|
|
||||||
def test_get_keystone_client(self):
|
def test_get_keystone_client(self):
|
||||||
with mock.patch('rally.osclients.keystone') as mock_keystone:
|
with mock.patch('rally.osclients.keystone') as mock_keystone:
|
||||||
fake_keystone = FakeKeystone()
|
fake_keystone = fakes.FakeKeystoneClient()
|
||||||
mock_keystone.Client = mock.MagicMock(return_value=fake_keystone)
|
mock_keystone.Client = mock.MagicMock(return_value=fake_keystone)
|
||||||
self.assertTrue("keystone" not in self.clients.cache)
|
self.assertTrue("keystone" not in self.clients.cache)
|
||||||
client = self.clients.get_keystone_client()
|
client = self.clients.get_keystone_client()
|
||||||
@ -74,7 +49,7 @@ class OSClientsTestCase(test.TestCase):
|
|||||||
|
|
||||||
def test_get_nova_client(self):
|
def test_get_nova_client(self):
|
||||||
with mock.patch('rally.osclients.nova') as mock_nova:
|
with mock.patch('rally.osclients.nova') as mock_nova:
|
||||||
fake_nova = FakeNova()
|
fake_nova = fakes.FakeNovaClient()
|
||||||
mock_nova.Client = mock.MagicMock(return_value=fake_nova)
|
mock_nova.Client = mock.MagicMock(return_value=fake_nova)
|
||||||
self.assertTrue("nova" not in self.clients.cache)
|
self.assertTrue("nova" not in self.clients.cache)
|
||||||
client = self.clients.get_nova_client()
|
client = self.clients.get_nova_client()
|
||||||
@ -86,9 +61,9 @@ class OSClientsTestCase(test.TestCase):
|
|||||||
|
|
||||||
def test_get_glance_client(self):
|
def test_get_glance_client(self):
|
||||||
with mock.patch('rally.osclients.glance') as mock_glance:
|
with mock.patch('rally.osclients.glance') as mock_glance:
|
||||||
fake_glance = FakeGlance()
|
fake_glance = fakes.FakeGlanceClient()
|
||||||
mock_glance.Client = mock.MagicMock(return_value=fake_glance)
|
mock_glance.Client = mock.MagicMock(return_value=fake_glance)
|
||||||
kc = FakeKeystone()
|
kc = fakes.FakeKeystoneClient()
|
||||||
self.clients.get_keystone_client = mock.MagicMock(return_value=kc)
|
self.clients.get_keystone_client = mock.MagicMock(return_value=kc)
|
||||||
self.assertTrue("glance" not in self.clients.cache)
|
self.assertTrue("glance" not in self.clients.cache)
|
||||||
client = self.clients.get_glance_client()
|
client = self.clients.get_glance_client()
|
||||||
@ -101,7 +76,7 @@ class OSClientsTestCase(test.TestCase):
|
|||||||
|
|
||||||
def test_get_cinder_client(self):
|
def test_get_cinder_client(self):
|
||||||
with mock.patch('rally.osclients.cinder') as mock_cinder:
|
with mock.patch('rally.osclients.cinder') as mock_cinder:
|
||||||
fake_cinder = FakeCinder()
|
fake_cinder = fakes.FakeCinderClient()
|
||||||
mock_cinder.Client = mock.MagicMock(return_value=fake_cinder)
|
mock_cinder.Client = mock.MagicMock(return_value=fake_cinder)
|
||||||
self.assertTrue("cinder" not in self.clients.cache)
|
self.assertTrue("cinder" not in self.clients.cache)
|
||||||
client = self.clients.get_cinder_client()
|
client = self.clients.get_cinder_client()
|
||||||
|
Loading…
Reference in New Issue
Block a user