Update and test nova_client function

- Use a tuple of Client classes to verify client instances
- Add unit test for nova_client function.

Change-Id: Iecd3c59fb4120b4126752c9790a3f68d3e016aa8
This commit is contained in:
Federico Ressi 2019-07-25 09:47:32 +02:00
parent 3a6569200c
commit 5e813615b0
3 changed files with 29 additions and 5 deletions

View File

@ -18,3 +18,4 @@ from tobiko.openstack.nova import _client
nova_client = _client.nova_client
get_nova_client = _client.get_nova_client
NovaClientFixture = _client.NovaClientFixture
CLIENT_CLASSES = _client.CLIENT_CLASSES

View File

@ -14,11 +14,15 @@
from __future__ import absolute_import
from novaclient import client as novaclient
from novaclient.v2 import client as client_v2
import tobiko
from tobiko.openstack import _client
CLIENT_CLASSES = (client_v2.Client,)
class NovaClientFixture(_client.OpenstackClientFixture):
def init_client(self, session):
@ -38,7 +42,7 @@ def nova_client(obj):
if not obj:
return get_nova_client()
if isinstance(obj, novaclient.Client):
if isinstance(obj, CLIENT_CLASSES):
return obj
fixture = tobiko.setup_fixture(obj)

View File

@ -13,8 +13,6 @@
# under the License.
from __future__ import absolute_import
from novaclient.v2 import client as novaclient
from tobiko.openstack import keystone
from tobiko.openstack import nova
from tobiko.tests.unit import openstack
@ -36,8 +34,8 @@ class GetNovaClientTest(openstack.OpenstackTest):
self.assertIs(client1, client2)
else:
self.assertIsNot(client1, client2)
self.assertIsInstance(client1, novaclient.Client)
self.assertIsInstance(client2, novaclient.Client)
self.assertIsInstance(client1, nova.CLIENT_CLASSES)
self.assertIsInstance(client2, nova.CLIENT_CLASSES)
def test_get_nova_client_with_not_shared(self):
self.test_get_nova_client(shared=False)
@ -45,3 +43,24 @@ class GetNovaClientTest(openstack.OpenstackTest):
def test_get_nova_client_with_session(self):
session = keystone.get_keystone_session()
self.test_get_nova_client(session=session)
class NeutronClientTest(openstack.OpenstackTest):
def test_neutron_client_with_none(self):
default_client = nova.get_nova_client()
client = nova.nova_client(None)
self.assertIsInstance(client, nova.CLIENT_CLASSES)
self.assertIs(default_client, client)
def test_neutron_client_with_client(self):
default_client = nova.get_nova_client()
client = nova.nova_client(default_client)
self.assertIsInstance(client, nova.CLIENT_CLASSES)
self.assertIs(default_client, client)
def test_neutron_client_with_fixture(self):
fixture = nova.NovaClientFixture()
client = nova.nova_client(fixture)
self.assertIsInstance(client, nova.CLIENT_CLASSES)
self.assertIs(client, fixture.client)