Merge "Automatically configure mock context clients"
This commit is contained in:
commit
f27eccd9df
@ -148,18 +148,13 @@ class ScenarioTestCase(TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class ContextClientAdapter(object):
|
class ContextClientAdapter(object):
|
||||||
def __init__(self, endpoint, clients):
|
def __init__(self, endpoint, test_case):
|
||||||
self.endpoint = endpoint
|
self.endpoint = endpoint
|
||||||
self._clients = clients
|
self.test_case = test_case
|
||||||
|
|
||||||
def mock_client(self, name, version=None):
|
def mock_client(self, name, version=None):
|
||||||
admin = self.endpoint.startswith("admin")
|
admin = self.endpoint.startswith("admin")
|
||||||
try:
|
client = self.test_case.clients(name, version=version, admin=admin)
|
||||||
client = self._clients[(name, version, admin)]
|
|
||||||
except KeyError:
|
|
||||||
raise ValueError(
|
|
||||||
"Client %s version %s (admin %s) is missing, "
|
|
||||||
"please configure" % (name, version, admin))
|
|
||||||
if not isinstance(client.return_value, mock.Mock):
|
if not isinstance(client.return_value, mock.Mock):
|
||||||
return client.return_value
|
return client.return_value
|
||||||
if client.side_effect is not None:
|
if client.side_effect is not None:
|
||||||
@ -181,10 +176,9 @@ class ContextTestCase(ScenarioTestCase):
|
|||||||
|
|
||||||
self._adapters = {}
|
self._adapters = {}
|
||||||
|
|
||||||
def context_client(self, endpoint):
|
def context_client(self, endpoint, api_info=None):
|
||||||
if endpoint not in self._adapters:
|
if endpoint not in self._adapters:
|
||||||
self._adapters[endpoint] = ContextClientAdapter(
|
self._adapters[endpoint] = ContextClientAdapter(endpoint, self)
|
||||||
endpoint, self._clients)
|
|
||||||
return self._adapters[endpoint]
|
return self._adapters[endpoint]
|
||||||
|
|
||||||
def get_client_mocks(self):
|
def get_client_mocks(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user