Merge "Replace mox with mock"

This commit is contained in:
Jenkins 2016-12-17 18:42:26 +00:00 committed by Gerrit Code Review
commit d16e4883fe
4 changed files with 179 additions and 129 deletions

76
oslo_messaging/tests/notify/test_notifier.py Normal file → Executable file
View File

@ -39,6 +39,14 @@ from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios load_tests = testscenarios.load_tests_apply_scenarios
class JsonMessageMatcher(object):
def __init__(self, message):
self.message = message
def __eq__(self, other):
return self.message == jsonutils.loads(other)
class _FakeTransport(object): class _FakeTransport(object):
def __init__(self, conf): def __init__(self, conf):
@ -176,11 +184,10 @@ class TestMessagingNotifier(test_utils.BaseTestCase):
if prepare_kwds: if prepare_kwds:
notifier = notifier.prepare(**prepare_kwds) notifier = notifier.prepare(**prepare_kwds)
self.mox.StubOutWithMock(transport, '_send_notification') transport._send_notification = mock.Mock()
message_id = uuid.uuid4() message_id = uuid.uuid4()
self.mox.StubOutWithMock(uuid, 'uuid4') uuid.uuid4 = mock.Mock(return_value=message_id)
uuid.uuid4().AndReturn(message_id)
mock_utcnow.return_value = datetime.datetime.utcnow() mock_utcnow.return_value = datetime.datetime.utcnow()
@ -199,6 +206,7 @@ class TestMessagingNotifier(test_utils.BaseTestCase):
if self.v2: if self.v2:
sends.append(dict(version=2.0)) sends.append(dict(version=2.0))
calls = []
for send_kwargs in sends: for send_kwargs in sends:
for topic in self.topics: for topic in self.topics:
if hasattr(self, 'retry'): if hasattr(self, 'retry'):
@ -207,14 +215,16 @@ class TestMessagingNotifier(test_utils.BaseTestCase):
send_kwargs['retry'] = None send_kwargs['retry'] = None
target = oslo_messaging.Target(topic='%s.%s' % (topic, target = oslo_messaging.Target(topic='%s.%s' % (topic,
self.priority)) self.priority))
transport._send_notification(target, self.ctxt, message, calls.append(mock.call(target,
**send_kwargs).InAnyOrder() self.ctxt,
message,
self.mox.ReplayAll() **send_kwargs))
method = getattr(notifier, self.priority) method = getattr(notifier, self.priority)
method(self.ctxt, 'test.notify', self.payload) method(self.ctxt, 'test.notify', self.payload)
uuid.uuid4.assert_called_once_with()
transport._send_notification.assert_has_calls(calls, any_order=True)
TestMessagingNotifier.generate_scenarios() TestMessagingNotifier.generate_scenarios()
@ -238,18 +248,15 @@ class TestSerializer(test_utils.BaseTestCase):
serializer=serializer) serializer=serializer)
message_id = uuid.uuid4() message_id = uuid.uuid4()
self.mox.StubOutWithMock(uuid, 'uuid4') uuid.uuid4 = mock.Mock(return_value=message_id)
uuid.uuid4().AndReturn(message_id)
mock_utcnow.return_value = datetime.datetime.utcnow() mock_utcnow.return_value = datetime.datetime.utcnow()
self.mox.StubOutWithMock(serializer, 'serialize_context') serializer.serialize_context = mock.Mock()
self.mox.StubOutWithMock(serializer, 'serialize_entity') serializer.serialize_context.return_value = dict(user='alice')
serializer.serialize_context(dict(user='bob')).\
AndReturn(dict(user='alice'))
serializer.serialize_entity(dict(user='bob'), 'bar').AndReturn('sbar')
self.mox.ReplayAll() serializer.serialize_entity = mock.Mock()
serializer.serialize_entity.return_value = 'sbar'
notifier.info(dict(user='bob'), 'test.notify', 'bar') notifier.info(dict(user='bob'), 'test.notify', 'bar')
@ -265,6 +272,11 @@ class TestSerializer(test_utils.BaseTestCase):
self.assertEqual([(dict(user='alice'), message, 'INFO', None)], self.assertEqual([(dict(user='alice'), message, 'INFO', None)],
_impl_test.NOTIFICATIONS) _impl_test.NOTIFICATIONS)
uuid.uuid4.assert_called_once_with()
serializer.serialize_context.assert_called_once_with(dict(user='bob'))
serializer.serialize_entity.assert_called_once_with(dict(user='bob'),
'bar')
class TestNotifierTopics(test_utils.BaseTestCase): class TestNotifierTopics(test_utils.BaseTestCase):
@ -303,8 +315,8 @@ class TestLogNotifier(test_utils.BaseTestCase):
notifier = oslo_messaging.Notifier(transport, 'test.localhost') notifier = oslo_messaging.Notifier(transport, 'test.localhost')
message_id = uuid.uuid4() message_id = uuid.uuid4()
self.mox.StubOutWithMock(uuid, 'uuid4') uuid.uuid4 = mock.Mock()
uuid.uuid4().AndReturn(message_id) uuid.uuid4.return_value = message_id
mock_utcnow.return_value = datetime.datetime.utcnow() mock_utcnow.return_value = datetime.datetime.utcnow()
@ -317,34 +329,34 @@ class TestLogNotifier(test_utils.BaseTestCase):
'timestamp': str(timeutils.utcnow()), 'timestamp': str(timeutils.utcnow()),
} }
logger = self.mox.CreateMockAnything() logger = mock.Mock()
logging.getLogger = mock.Mock()
self.mox.StubOutWithMock(logging, 'getLogger') logging.getLogger.return_value = logger
logging.getLogger('oslo.messaging.notification.test.notify').\
AndReturn(logger)
logger.info(jsonutils.dumps(message))
self.mox.ReplayAll()
notifier.info({}, 'test.notify', 'bar') notifier.info({}, 'test.notify', 'bar')
uuid.uuid4.assert_called_once_with()
logging.getLogger.assert_called_once_with('oslo.messaging.'
'notification.test.notify')
logger.info.assert_called_once_with(JsonMessageMatcher(message))
def test_sample_priority(self): def test_sample_priority(self):
# Ensure logger drops sample-level notifications. # Ensure logger drops sample-level notifications.
driver = _impl_log.LogDriver(None, None, None) driver = _impl_log.LogDriver(None, None, None)
logger = self.mox.CreateMock( logger = mock.Mock(spec=logging.getLogger('oslo.messaging.'
logging.getLogger('oslo.messaging.notification.foo')) 'notification.foo'))
logger.sample = None logger.sample = None
self.mox.StubOutWithMock(logging, 'getLogger')
logging.getLogger('oslo.messaging.notification.foo').\
AndReturn(logger)
self.mox.ReplayAll() logging.getLogger = mock.Mock()
logging.getLogger.return_value = logger
msg = {'event_type': 'foo'} msg = {'event_type': 'foo'}
driver.notify(None, msg, "sample", None) driver.notify(None, msg, "sample", None)
logging.getLogger.assert_called_once_with('oslo.messaging.'
'notification.foo')
def test_mask_passwords(self): def test_mask_passwords(self):
# Ensure that passwords are masked with notifications # Ensure that passwords are masked with notifications
driver = _impl_log.LogDriver(None, None, None) driver = _impl_log.LogDriver(None, None, None)

87
oslo_messaging/tests/rpc/test_client.py Normal file → Executable file
View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import mock
from oslo_config import cfg from oslo_config import cfg
import testscenarios import testscenarios
@ -54,7 +56,7 @@ class TestCastCall(test_utils.BaseTestCase):
transport = _FakeTransport(self.conf) transport = _FakeTransport(self.conf)
client = oslo_messaging.RPCClient(transport, oslo_messaging.Target()) client = oslo_messaging.RPCClient(transport, oslo_messaging.Target())
self.mox.StubOutWithMock(transport, '_send') transport._send = mock.Mock()
msg = dict(method='foo', args=self.args) msg = dict(method='foo', args=self.args)
kwargs = {'retry': None} kwargs = {'retry': None}
@ -62,12 +64,14 @@ class TestCastCall(test_utils.BaseTestCase):
kwargs['wait_for_reply'] = True kwargs['wait_for_reply'] = True
kwargs['timeout'] = None kwargs['timeout'] = None
transport._send(oslo_messaging.Target(), self.ctxt, msg, **kwargs)
self.mox.ReplayAll()
method = client.call if self.call else client.cast method = client.call if self.call else client.cast
method(self.ctxt, 'foo', **self.args) method(self.ctxt, 'foo', **self.args)
transport._send.assert_called_once_with(oslo_messaging.Target(),
self.ctxt,
msg,
**kwargs)
class TestCastToTarget(test_utils.BaseTestCase): class TestCastToTarget(test_utils.BaseTestCase):
@ -191,16 +195,13 @@ class TestCastToTarget(test_utils.BaseTestCase):
transport = _FakeTransport(self.conf) transport = _FakeTransport(self.conf)
client = oslo_messaging.RPCClient(transport, target) client = oslo_messaging.RPCClient(transport, target)
self.mox.StubOutWithMock(transport, '_send') transport._send = mock.Mock()
msg = dict(method='foo', args={}) msg = dict(method='foo', args={})
if 'namespace' in self.expect: if 'namespace' in self.expect:
msg['namespace'] = self.expect['namespace'] msg['namespace'] = self.expect['namespace']
if 'version' in self.expect: if 'version' in self.expect:
msg['version'] = self.expect['version'] msg['version'] = self.expect['version']
transport._send(expect_target, {}, msg, retry=None)
self.mox.ReplayAll()
if self.prepare: if self.prepare:
client = client.prepare(**self.prepare) client = client.prepare(**self.prepare)
@ -208,6 +209,11 @@ class TestCastToTarget(test_utils.BaseTestCase):
client = client.prepare(**self.prepare) client = client.prepare(**self.prepare)
client.cast({}, 'foo') client.cast({}, 'foo')
transport._send.assert_called_once_with(expect_target,
{},
msg,
retry=None)
TestCastToTarget.generate_scenarios() TestCastToTarget.generate_scenarios()
@ -241,18 +247,20 @@ class TestCallTimeout(test_utils.BaseTestCase):
client = oslo_messaging.RPCClient(transport, oslo_messaging.Target(), client = oslo_messaging.RPCClient(transport, oslo_messaging.Target(),
timeout=self.ctor) timeout=self.ctor)
self.mox.StubOutWithMock(transport, '_send') transport._send = mock.Mock()
msg = dict(method='foo', args={}) msg = dict(method='foo', args={})
kwargs = dict(wait_for_reply=True, timeout=self.expect, retry=None) kwargs = dict(wait_for_reply=True, timeout=self.expect, retry=None)
transport._send(oslo_messaging.Target(), {}, msg, **kwargs)
self.mox.ReplayAll()
if self.prepare is not _notset: if self.prepare is not _notset:
client = client.prepare(timeout=self.prepare) client = client.prepare(timeout=self.prepare)
client.call({}, 'foo') client.call({}, 'foo')
transport._send.assert_called_once_with(oslo_messaging.Target(),
{},
msg,
**kwargs)
class TestCallRetry(test_utils.BaseTestCase): class TestCallRetry(test_utils.BaseTestCase):
@ -270,19 +278,21 @@ class TestCallRetry(test_utils.BaseTestCase):
client = oslo_messaging.RPCClient(transport, oslo_messaging.Target(), client = oslo_messaging.RPCClient(transport, oslo_messaging.Target(),
retry=self.ctor) retry=self.ctor)
self.mox.StubOutWithMock(transport, '_send') transport._send = mock.Mock()
msg = dict(method='foo', args={}) msg = dict(method='foo', args={})
kwargs = dict(wait_for_reply=True, timeout=60, kwargs = dict(wait_for_reply=True, timeout=60,
retry=self.expect) retry=self.expect)
transport._send(oslo_messaging.Target(), {}, msg, **kwargs)
self.mox.ReplayAll()
if self.prepare is not _notset: if self.prepare is not _notset:
client = client.prepare(retry=self.prepare) client = client.prepare(retry=self.prepare)
client.call({}, 'foo') client.call({}, 'foo')
transport._send.assert_called_once_with(oslo_messaging.Target(),
{},
msg,
**kwargs)
class TestCallFanout(test_utils.BaseTestCase): class TestCallFanout(test_utils.BaseTestCase):
@ -328,37 +338,46 @@ class TestSerializer(test_utils.BaseTestCase):
client = oslo_messaging.RPCClient(transport, oslo_messaging.Target(), client = oslo_messaging.RPCClient(transport, oslo_messaging.Target(),
serializer=serializer) serializer=serializer)
self.mox.StubOutWithMock(transport, '_send') transport._send = mock.Mock()
msg = dict(method='foo', msg = dict(method='foo',
args=dict([(k, 's' + v) for k, v in self.args.items()])) args=dict([(k, 's' + v) for k, v in self.args.items()]))
kwargs = dict(wait_for_reply=True, timeout=None) if self.call else {} kwargs = dict(wait_for_reply=True, timeout=None) if self.call else {}
kwargs['retry'] = None kwargs['retry'] = None
transport._send(oslo_messaging.Target(),
dict(user='alice'),
msg,
**kwargs).AndReturn(self.retval)
self.mox.StubOutWithMock(serializer, 'serialize_entity') transport._send.return_value = self.retval
self.mox.StubOutWithMock(serializer, 'deserialize_entity')
self.mox.StubOutWithMock(serializer, 'serialize_context')
serializer.serialize_entity = mock.Mock()
serializer.deserialize_entity = mock.Mock()
serializer.serialize_context = mock.Mock()
expected_side_effect = []
for arg in self.args: for arg in self.args:
serializer.serialize_entity(self.ctxt, arg).AndReturn('s' + arg) expected_side_effect.append('s' + arg)
serializer.serialize_entity.side_effect = expected_side_effect
if self.call: if self.call:
serializer.deserialize_entity(self.ctxt, self.retval).\ serializer.deserialize_entity.return_value = 'd' + self.retval
AndReturn('d' + self.retval)
serializer.serialize_context(self.ctxt).AndReturn(dict(user='alice')) serializer.serialize_context.return_value = dict(user='alice')
self.mox.ReplayAll()
method = client.call if self.call else client.cast method = client.call if self.call else client.cast
retval = method(self.ctxt, 'foo', **self.args) retval = method(self.ctxt, 'foo', **self.args)
if self.retval is not None: if self.retval is not None:
self.assertEqual('d' + self.retval, retval) self.assertEqual('d' + self.retval, retval)
transport._send.assert_called_once_with(oslo_messaging.Target(),
dict(user='alice'),
msg,
**kwargs)
expected_calls = [mock.call(self.ctxt, arg) for arg in self.args]
self.assertEqual(expected_calls,
serializer.serialize_entity.mock_calls)
if self.call:
serializer.deserialize_entity.assert_called_once_with(self.ctxt,
self.retval)
serializer.serialize_context.assert_called_once_with(self.ctxt)
class TestVersionCap(test_utils.BaseTestCase): class TestVersionCap(test_utils.BaseTestCase):
@ -418,7 +437,7 @@ class TestVersionCap(test_utils.BaseTestCase):
version_cap=self.cap) version_cap=self.cap)
if self.success: if self.success:
self.mox.StubOutWithMock(transport, '_send') transport._send = mock.Mock()
if self.prepare_version is not _notset: if self.prepare_version is not _notset:
target = target(version=self.prepare_version) target = target(version=self.prepare_version)
@ -432,10 +451,6 @@ class TestVersionCap(test_utils.BaseTestCase):
kwargs['wait_for_reply'] = True kwargs['wait_for_reply'] = True
kwargs['timeout'] = None kwargs['timeout'] = None
transport._send(target, {}, msg, **kwargs)
self.mox.ReplayAll()
prep_kwargs = {} prep_kwargs = {}
if self.prepare_cap is not _notset: if self.prepare_cap is not _notset:
prep_kwargs['version_cap'] = self.prepare_cap prep_kwargs['version_cap'] = self.prepare_cap
@ -452,7 +467,7 @@ class TestVersionCap(test_utils.BaseTestCase):
self.assertFalse(self.success) self.assertFalse(self.success)
else: else:
self.assertTrue(self.success) self.assertTrue(self.success)
transport._send.assert_called_once_with(target, {}, msg, **kwargs)
TestVersionCap.generate_scenarios() TestVersionCap.generate_scenarios()

34
oslo_messaging/tests/rpc/test_dispatcher.py Normal file → Executable file
View File

@ -231,23 +231,23 @@ class TestSerializer(test_utils.BaseTestCase):
serializer = msg_serializer.NoOpSerializer() serializer = msg_serializer.NoOpSerializer()
dispatcher = oslo_messaging.RPCDispatcher([endpoint], serializer) dispatcher = oslo_messaging.RPCDispatcher([endpoint], serializer)
self.mox.StubOutWithMock(endpoint, 'foo') endpoint.foo = mock.Mock()
args = dict([(k, 'd' + v) for k, v in self.args.items()]) args = dict([(k, 'd' + v) for k, v in self.args.items()])
endpoint.foo(self.dctxt, **args).AndReturn(self.retval) endpoint.foo.return_value = self.retval
self.mox.StubOutWithMock(serializer, 'serialize_entity') serializer.serialize_entity = mock.Mock()
self.mox.StubOutWithMock(serializer, 'deserialize_entity') serializer.deserialize_entity = mock.Mock()
self.mox.StubOutWithMock(serializer, 'deserialize_context') serializer.deserialize_context = mock.Mock()
serializer.deserialize_context(self.ctxt).AndReturn(self.dctxt) serializer.deserialize_context.return_value = self.dctxt
for arg in self.args: expected_side_effect = ['d' + arg for arg in self.args]
serializer.deserialize_entity(self.dctxt, arg).AndReturn('d' + arg) serializer.deserialize_entity.side_effect = expected_side_effect
serializer.serialize_entity(self.dctxt, self.retval). \ serializer.serialize_entity.return_value = None
AndReturn('s' + self.retval if self.retval else None) if self.retval:
serializer.serialize_entity.return_value = 's' + self.retval
self.mox.ReplayAll()
incoming = mock.Mock() incoming = mock.Mock()
incoming.ctxt = self.ctxt incoming.ctxt = self.ctxt
@ -255,3 +255,13 @@ class TestSerializer(test_utils.BaseTestCase):
retval = dispatcher.dispatch(incoming) retval = dispatcher.dispatch(incoming)
if self.retval is not None: if self.retval is not None:
self.assertEqual('s' + self.retval, retval) self.assertEqual('s' + self.retval, retval)
endpoint.foo.assert_called_once_with(self.dctxt, **args)
serializer.deserialize_context.assert_called_once_with(self.ctxt)
expected_calls = [mock.call(self.dctxt, arg) for arg in self.args]
self.assertEqual(expected_calls,
serializer.deserialize_entity.mock_calls)
serializer.serialize_entity.assert_called_once_with(self.dctxt,
self.retval)

111
oslo_messaging/tests/test_transport.py Normal file → Executable file
View File

@ -15,7 +15,6 @@
import fixtures import fixtures
import mock import mock
from mox3 import mox
from oslo_config import cfg from oslo_config import cfg
import six import six
from stevedore import driver from stevedore import driver
@ -119,7 +118,7 @@ class GetTransportTestCase(test_utils.BaseTestCase):
control_exchange=self.control_exchange, control_exchange=self.control_exchange,
transport_url=self.transport_url) transport_url=self.transport_url)
self.mox.StubOutWithMock(driver, 'DriverManager') driver.DriverManager = mock.Mock()
invoke_args = [self.conf, invoke_args = [self.conf,
oslo_messaging.TransportURL.parse(self.conf, oslo_messaging.TransportURL.parse(self.conf,
@ -128,14 +127,8 @@ class GetTransportTestCase(test_utils.BaseTestCase):
allowed_remote_exmods=self.expect['allowed']) allowed_remote_exmods=self.expect['allowed'])
drvr = _FakeDriver(self.conf) drvr = _FakeDriver(self.conf)
driver.DriverManager('oslo.messaging.drivers',
self.expect['backend'],
invoke_on_load=True,
invoke_args=invoke_args,
invoke_kwds=invoke_kwds).\
AndReturn(_FakeManager(drvr))
self.mox.ReplayAll() driver.DriverManager.return_value = _FakeManager(drvr)
kwargs = dict(url=self.url) kwargs = dict(url=self.url)
if self.allowed is not None: if self.allowed is not None:
@ -156,6 +149,12 @@ class GetTransportTestCase(test_utils.BaseTestCase):
self.assertIs(transport_.conf, self.conf) self.assertIs(transport_.conf, self.conf)
self.assertIs(transport_._driver, drvr) self.assertIs(transport_._driver, drvr)
driver.DriverManager.assert_called_once_with('oslo.messaging.drivers',
self.expect['backend'],
invoke_on_load=True,
invoke_args=invoke_args,
invoke_kwds=invoke_kwds)
class GetTransportSadPathTestCase(test_utils.BaseTestCase): class GetTransportSadPathTestCase(test_utils.BaseTestCase):
@ -182,7 +181,7 @@ class GetTransportSadPathTestCase(test_utils.BaseTestCase):
transport_url=self.transport_url) transport_url=self.transport_url)
if self.rpc_backend: if self.rpc_backend:
self.mox.StubOutWithMock(driver, 'DriverManager') driver.DriverManager = mock.Mock()
invoke_args = [self.conf, invoke_args = [self.conf,
oslo_messaging.TransportURL.parse(self.conf, oslo_messaging.TransportURL.parse(self.conf,
@ -190,18 +189,17 @@ class GetTransportSadPathTestCase(test_utils.BaseTestCase):
invoke_kwds = dict(default_exchange='openstack', invoke_kwds = dict(default_exchange='openstack',
allowed_remote_exmods=[]) allowed_remote_exmods=[])
driver.DriverManager('oslo.messaging.drivers', driver.DriverManager.side_effect = RuntimeError()
self.rpc_backend,
invoke_on_load=True,
invoke_args=invoke_args,
invoke_kwds=invoke_kwds).\
AndRaise(RuntimeError())
self.mox.ReplayAll()
try: try:
oslo_messaging.get_transport(self.conf, url=self.url) oslo_messaging.get_transport(self.conf, url=self.url)
self.assertFalse(True) self.assertFalse(True)
driver.DriverManager.\
assert_called_once_with('oslo.messaging.drivers',
self.rpc_backend,
invoke_on_load=True,
invoke_args=invoke_args,
invoke_kwds=invoke_kwds)
except Exception as ex: except Exception as ex:
ex_cls = self.ex.pop('cls') ex_cls = self.ex.pop('cls')
ex_msg_contains = self.ex.pop('msg_contains') ex_msg_contains = self.ex.pop('msg_contains')
@ -258,18 +256,20 @@ class TestSetDefaults(test_utils.BaseTestCase):
def test_set_default_control_exchange(self): def test_set_default_control_exchange(self):
oslo_messaging.set_transport_defaults(control_exchange='foo') oslo_messaging.set_transport_defaults(control_exchange='foo')
self.mox.StubOutWithMock(driver, 'DriverManager') driver.DriverManager = mock.Mock()
invoke_kwds = mox.ContainsKeyValue('default_exchange', 'foo') invoke_kwds = dict(default_exchange='foo', allowed_remote_exmods=[])
driver.DriverManager(mox.IgnoreArg(),
mox.IgnoreArg(), driver.DriverManager.return_value = \
invoke_on_load=mox.IgnoreArg(), _FakeManager(_FakeDriver(self.conf))
invoke_args=mox.IgnoreArg(),
invoke_kwds=invoke_kwds).\
AndReturn(_FakeManager(_FakeDriver(self.conf)))
self.mox.ReplayAll()
oslo_messaging.get_transport(self.conf) oslo_messaging.get_transport(self.conf)
driver.DriverManager.assert_called_once_with(mock.ANY,
mock.ANY,
invoke_on_load=mock.ANY,
invoke_args=mock.ANY,
invoke_kwds=invoke_kwds)
class TestTransportMethodArgs(test_utils.BaseTestCase): class TestTransportMethodArgs(test_utils.BaseTestCase):
@ -278,57 +278,70 @@ class TestTransportMethodArgs(test_utils.BaseTestCase):
def test_send_defaults(self): def test_send_defaults(self):
t = transport.Transport(_FakeDriver(cfg.CONF)) t = transport.Transport(_FakeDriver(cfg.CONF))
self.mox.StubOutWithMock(t._driver, 'send') t._driver.send = mock.Mock()
t._driver.send(self._target, 'ctxt', 'message',
wait_for_reply=None,
timeout=None, retry=None)
self.mox.ReplayAll()
t._send(self._target, 'ctxt', 'message') t._send(self._target, 'ctxt', 'message')
t._driver.send.assert_called_once_with(self._target,
'ctxt',
'message',
wait_for_reply=None,
timeout=None,
retry=None)
def test_send_all_args(self): def test_send_all_args(self):
t = transport.Transport(_FakeDriver(cfg.CONF)) t = transport.Transport(_FakeDriver(cfg.CONF))
self.mox.StubOutWithMock(t._driver, 'send') t._driver.send = mock.Mock()
t._driver.send(self._target, 'ctxt', 'message',
wait_for_reply='wait_for_reply',
timeout='timeout', retry='retry')
self.mox.ReplayAll()
t._send(self._target, 'ctxt', 'message', t._send(self._target, 'ctxt', 'message',
wait_for_reply='wait_for_reply', wait_for_reply='wait_for_reply',
timeout='timeout', retry='retry') timeout='timeout', retry='retry')
t._driver.send.\
assert_called_once_with(self._target,
'ctxt',
'message',
wait_for_reply='wait_for_reply',
timeout='timeout',
retry='retry')
def test_send_notification(self): def test_send_notification(self):
t = transport.Transport(_FakeDriver(cfg.CONF)) t = transport.Transport(_FakeDriver(cfg.CONF))
self.mox.StubOutWithMock(t._driver, 'send_notification') t._driver.send_notification = mock.Mock()
t._driver.send_notification(self._target, 'ctxt', 'message', 1.0,
retry=None)
self.mox.ReplayAll()
t._send_notification(self._target, 'ctxt', 'message', version=1.0) t._send_notification(self._target, 'ctxt', 'message', version=1.0)
t._driver.send_notification.assert_called_once_with(self._target,
'ctxt',
'message',
1.0,
retry=None)
def test_send_notification_all_args(self): def test_send_notification_all_args(self):
t = transport.Transport(_FakeDriver(cfg.CONF)) t = transport.Transport(_FakeDriver(cfg.CONF))
self.mox.StubOutWithMock(t._driver, 'send_notification') t._driver.send_notification = mock.Mock()
t._driver.send_notification(self._target, 'ctxt', 'message', 1.0,
retry=5)
self.mox.ReplayAll()
t._send_notification(self._target, 'ctxt', 'message', version=1.0, t._send_notification(self._target, 'ctxt', 'message', version=1.0,
retry=5) retry=5)
t._driver.send_notification.assert_called_once_with(self._target,
'ctxt',
'message',
1.0,
retry=5)
def test_listen(self): def test_listen(self):
t = transport.Transport(_FakeDriver(cfg.CONF)) t = transport.Transport(_FakeDriver(cfg.CONF))
self.mox.StubOutWithMock(t._driver, 'listen') t._driver.listen = mock.Mock()
t._driver.listen(self._target, 1, None)
self.mox.ReplayAll()
t._listen(self._target, 1, None) t._listen(self._target, 1, None)
t._driver.listen.assert_called_once_with(self._target, 1, None)
class TestTransportUrlCustomisation(test_utils.BaseTestCase): class TestTransportUrlCustomisation(test_utils.BaseTestCase):
def setUp(self): def setUp(self):