本文整理汇总了Python中crossbar.router.router.RouterFactory.get方法的典型用法代码示例。如果您正苦于以下问题:Python RouterFactory.get方法的具体用法?Python RouterFactory.get怎么用?Python RouterFactory.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类crossbar.router.router.RouterFactory
的用法示例。
在下文中一共展示了RouterFactory.get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_router
# 需要导入模块: from crossbar.router.router import RouterFactory [as 别名]
# 或者: from crossbar.router.router.RouterFactory import get [as 别名]
def make_router(realm_name=u'default'):
"""
Make a router, and return it and a RawSocket factory.
"""
# create a router factory
router_factory = RouterFactory()
# start a realm
realm = RouterRealm(None, {u'name': realm_name})
router = router_factory.start_realm(realm)
extra = {}
session_config = ComponentConfig(realm_name, extra)
realm.session = RouterServiceSession(session_config, router)
# allow everything
default_permissions = {
u'uri': u'',
u'match': u'prefix',
u'allow': {
u'call': True,
u'register': True,
u'publish': True,
u'subscribe': True
}
}
router = router_factory.get(realm_name)
router.add_role(RouterRoleStaticAuth(router, 'anonymous', default_permissions=default_permissions))
# create a router session factory
session_factory = RouterSessionFactory(router_factory)
session_factory.add(realm.session, authrole=u'trusted')
# Create a new RawSocket factory
server_factory = WampRawSocketServerFactory(session_factory, {})
return router, server_factory
示例2: TestEmbeddedSessions
# 需要导入模块: from crossbar.router.router import RouterFactory [as 别名]
# 或者: from crossbar.router.router.RouterFactory import get [as 别名]
class TestEmbeddedSessions(unittest.TestCase):
"""
Test cases for application session running embedded in router.
"""
def setUp(self):
"""
Setup router and router session factories.
"""
# create a router factory
self.router_factory = RouterFactory(u'mynode')
# start a realm
self.router_factory.start_realm(RouterRealm(None, {u'name': u'realm1'}))
# allow everything
default_permissions = {
u'uri': u'',
u'match': u'prefix',
u'allow': {
u'call': True,
u'register': True,
u'publish': True,
u'subscribe': True
}
}
self.router = self.router_factory.get(u'realm1')
self.router.add_role(RouterRoleStaticAuth(self.router, u'test_role', default_permissions=default_permissions))
self.router.add_role(RouterRoleStaticAuth(self.router, None, default_permissions=default_permissions))
# create a router session factory
self.session_factory = RouterSessionFactory(self.router_factory)
def tearDown(self):
pass
def test_authorize_exception_call(self):
"""
When a dynamic authorizor throws an exception (during processCall)
we log it.
"""
the_exception = RuntimeError("authorizer bug")
def boom(*args, **kw):
raise the_exception
self.router._roles[u'test_role'].authorize = boom
class TestSession(ApplicationSession):
def __init__(self, *args, **kw):
super(TestSession, self).__init__(*args, **kw)
self._authrole = u'test_role'
self._transport = mock.MagicMock()
session0 = TestSession()
self.router._dealer._registration_map.add_observer(session0, u'test.proc')
# okay, we have an authorizer that will always explode and a
# single procedure registered; when we call it, then
# on_authorize_error (in dealer.py) should get called and our
# error logged.
call = message.Call(
request=1234,
procedure=u'test.proc',
args=tuple(),
kwargs=dict(),
)
# this should produce an error -- however processCall doesn't
# itself return the Deferred, so we look for the side-effect
# -- the router should have tried to send a message.Error (and
# we should also have logged the error).
self.router._dealer.processCall(session0, call)
self.assertEqual(1, len(session0._transport.mock_calls))
call = session0._transport.mock_calls[0]
self.assertEqual('send', call[0])
# ensure we logged our error (flushLoggedErrors also causes
# trial to *not* fail the unit-test despite an error logged)
errors = self.flushLoggedErrors()
self.assertTrue(the_exception in [fail.value for fail in errors])
def test_authorize_exception_register(self):
"""
When a dynamic authorizor throws an exception (during processRegister)
we log it.
"""
the_exception = RuntimeError("authorizer bug")
def boom(*args, **kw):
raise the_exception
self.router._roles[u'test_role'].authorize = boom
class TestSession(ApplicationSession):
def __init__(self, *args, **kw):
super(TestSession, self).__init__(*args, **kw)
self._authrole = u'test_role'
self._transport = mock.MagicMock()
session0 = TestSession()
call = message.Register(
#.........这里部分代码省略.........
示例3: TestEmbeddedSessions
# 需要导入模块: from crossbar.router.router import RouterFactory [as 别名]
# 或者: from crossbar.router.router.RouterFactory import get [as 别名]
class TestEmbeddedSessions(unittest.TestCase):
"""
Test cases for application session running embedded in router.
"""
def setUp(self):
"""
Setup router and router session factories.
"""
# create a router factory
self.router_factory = RouterFactory(u'mynode')
# start a realm
self.router_factory.start_realm(RouterRealm(None, {u'name': u'realm1'}))
# allow everything
default_permissions = {
u'uri': u'',
u'match': u'prefix',
u'call': True,
u'register': True,
u'publish': True,
u'subscribe': True
}
router = self.router_factory.get(u'realm1')
router.add_role(RouterRoleStaticAuth(router, None, default_permissions=default_permissions))
# create a router session factory
self.session_factory = RouterSessionFactory(self.router_factory)
def tearDown(self):
pass
def test_add(self):
"""
Create an application session and add it to a router to
run embedded.
"""
d = txaio.create_future()
class TestSession(ApplicationSession):
def onJoin(self, details):
txaio.resolve(d, None)
session = TestSession(types.ComponentConfig(u'realm1'))
self.session_factory.add(session)
return d
def test_application_session_internal_error(self):
"""
simulate an internal error triggering the 'onJoin' error-case from
_RouterApplicationSession's send() method (from the Hello msg)
"""
# setup
the_exception = RuntimeError("sadness")
errors = []
class TestSession(ApplicationSession):
def onJoin(self, *args, **kw):
raise the_exception
def onUserError(self, *args, **kw):
errors.append((args, kw))
session = TestSession(types.ComponentConfig(u'realm1'))
# in this test, we are just looking for onUserError to get
# called so we don't need to patch the logger. this should
# call onJoin, triggering our error
self.session_factory.add(session)
# check we got the right log.failure() call
self.assertTrue(len(errors) > 0, "expected onUserError call")
fail = errors[0][0][0]
self.assertTrue(fail.value == the_exception)
def test_router_session_internal_error_onHello(self):
"""
similar to above, but during _RouterSession's onMessage handling,
where it calls self.onHello
"""
# setup
transport = mock.MagicMock()
transport.get_channel_id = mock.MagicMock(return_value=b'deadbeef')
the_exception = RuntimeError("kerblam")
def boom(*args, **kw):
raise the_exception
session = self.session_factory() # __call__ on the _RouterSessionFactory
session.onHello = boom
session.onOpen(transport)
msg = message.Hello(u'realm1', dict(caller=role.RoleCallerFeatures()))
# XXX think: why isn't this using _RouterSession.log?
from crossbar.router.session import RouterSession
with mock.patch.object(RouterSession, 'log') as logger:
#.........这里部分代码省略.........
示例4: CallerTestCase
# 需要导入模块: from crossbar.router.router import RouterFactory [as 别名]
# 或者: from crossbar.router.router.RouterFactory import get [as 别名]
class CallerTestCase(TestCase):
"""
Unit tests for L{CallerResource}.
"""
def setUp(self):
# create a router factory
self.router_factory = RouterFactory(None, None)
# start a realm
self.realm = RouterRealm(None, {u'name': u'realm1'})
self.router_factory.start_realm(self.realm)
# allow everything
self.router = self.router_factory.get(u'realm1')
self.router.add_role(
RouterRoleStaticAuth(
self.router,
u'test_role',
default_permissions={
u'uri': u'com.myapp.',
u'match': u'prefix',
u'allow': {
u'call': True,
u'register': True,
u'publish': True,
u'subscribe': True,
}
}
)
)
# create a router session factory
self.session_factory = RouterSessionFactory(self.router_factory)
@inlineCallbacks
def test_add2(self):
"""
Test a very basic call where you square root a number. This has one
arg, no kwargs, and no authorisation.
"""
session = TestSession(types.ComponentConfig(u'realm1'))
self.session_factory.add(session, authrole=u"test_role")
session2 = ApplicationSession(types.ComponentConfig(u'realm1'))
self.session_factory.add(session2, authrole=u"test_role")
resource = CallerResource({}, session2)
with LogCapturer() as l:
request = yield renderResource(
resource, b"/",
method=b"POST",
headers={b"Content-Type": [b"application/json"]},
body=b'{"procedure": "com.myapp.sqrt", "args": [2]}')
self.assertEqual(request.code, 200)
self.assertEqual(json.loads(native_string(request.get_written_data())),
{"args": [1.4142135623730951]})
logs = l.get_category("AR202")
self.assertEqual(len(logs), 1)
self.assertEqual(logs[0]["code"], 200)
@inlineCallbacks
def test_failure(self):
"""
A failed call returns the error to the client.
"""
session = TestSession(types.ComponentConfig(u'realm1'))
self.session_factory.add(session, authrole=u"test_role")
session2 = ApplicationSession(types.ComponentConfig(u'realm1'))
self.session_factory.add(session2, authrole=u"test_role")
resource = CallerResource({}, session2)
tests = [
(u"com.myapp.sqrt", (0,),
{u"error": u"wamp.error.runtime_error", u"args": [u"don't ask foolish questions ;)"], u"kwargs": {}}),
(u"com.myapp.checkname", ("foo",),
{u"error": u"com.myapp.error.reserved", u"args": [], u"kwargs": {}}),
(u"com.myapp.checkname", ("*",),
{u"error": u"com.myapp.error.invalid_length", u"args": [], u"kwargs": {"min": 3, "max": 10}}),
(u"com.myapp.checkname", ("hello",),
{u"error": u"com.myapp.error.mixed_case", u"args": ["hello", "HELLO"], u"kwargs": {}}),
(u"com.myapp.compare", (1, 10),
{u"error": u"com.myapp.error1", u"args": [9], u"kwargs": {}}),
]
for procedure, args, err in tests:
with LogCapturer() as l:
request = yield renderResource(
resource, b"/",
method=b"POST",
headers={b"Content-Type": [b"application/json"]},
body=dump_json({"procedure": procedure, "args": args}).encode('utf8'))
self.assertEqual(request.code, 200)
self.assertEqual(json.loads(native_string(request.get_written_data())),
err)
#.........这里部分代码省略.........
示例5: TestDealer
# 需要导入模块: from crossbar.router.router import RouterFactory [as 别名]
# 或者: from crossbar.router.router.RouterFactory import get [as 别名]
class TestDealer(unittest.TestCase):
"""
"""
def setUp(self):
"""
Setup router and router session factories.
"""
# create a router factory
self.router_factory = RouterFactory(None, None)
# start a realm
self.realm = RouterRealm(u'realm-001', {u'name': u'realm1'})
self.router_factory.start_realm(self.realm)
# allow everything
self.router = self.router_factory.get(u'realm1')
self.router.add_role(
RouterRoleStaticAuth(
self.router,
u'test_role',
default_permissions={
u'uri': u'com.example.',
u'match': u'prefix',
u'allow': {
u'call': True,
u'register': True,
u'publish': True,
u'subscribe': True,
}
}
)
)
# create a router session factory
self.session_factory = RouterSessionFactory(self.router_factory)
def tearDown(self):
pass
@defer.inlineCallbacks
def test_outstanding_invoke(self):
"""
When a call is pending and the callee goes away, it cancels the
in-flight call
"""
session = mock.Mock()
session._realm = u'realm1'
self.router.authorize = mock.Mock(
return_value=defer.succeed({u'allow': True, u'disclose': True})
)
rap = RouterApplicationSession(session, self.router_factory)
rap.send(message.Hello(u"realm1", {u'caller': role.RoleCallerFeatures()}))
rap.send(message.Register(1, u'foo'))
# we can retrieve the Registration via
# session.mock_calls[-1][1][0] if req'd
# re-set the authorize, as the Deferred from above is already
# used-up and it gets called again to authorize the Call
self.router.authorize = mock.Mock(
return_value=defer.succeed({u'allow': True, u'disclose': True})
)
rap.send(message.Call(42, u'foo'))
orig = rap.send
d = defer.Deferred()
rap.send(message.Goodbye())
def wrapper(*args, **kw):
d.callback(args[0])
return orig(*args, **kw)
rap.send = wrapper
# we can do this *after* the call to send() the Goodbye
# (above) because it takes a reactor-turn to actually
# process the cancel/errors etc -- hence the Deferred and
# yield in this test...
msg = yield d
self.assertEqual(42, msg.request)
self.assertEqual(u'wamp.error.canceled', msg.error)
def test_outstanding_invoke_but_caller_gone(self):
session = mock.Mock()
outstanding = mock.Mock()
outstanding.call.request = 1
dealer = self.router._dealer
dealer.attach(session)
dealer._callee_to_invocations[session] = [outstanding]
# pretend we've disconnected already
outstanding.caller._transport = None
#.........这里部分代码省略.........
示例6: TestBrokerPublish
# 需要导入模块: from crossbar.router.router import RouterFactory [as 别名]
# 或者: from crossbar.router.router.RouterFactory import get [as 别名]
class TestBrokerPublish(unittest.TestCase):
"""
Tests for crossbar.router.broker.Broker
"""
def setUp(self):
"""
Setup router and router session factories.
"""
# create a router factory
self.router_factory = RouterFactory(u'mynode')
# start a realm
self.realm = RouterRealm(None, {u'name': u'realm1'})
self.router_factory.start_realm(self.realm)
# allow everything
self.router = self.router_factory.get(u'realm1')
self.router.add_role(
RouterRoleStaticAuth(
self.router,
u'test_role',
default_permissions={
u'uri': u'com.example.',
u'match': u'prefix',
u'allow': {
u'call': True,
u'register': True,
u'publish': True,
u'subscribe': True,
}
}
)
)
# create a router session factory
self.session_factory = RouterSessionFactory(self.router_factory)
def tearDown(self):
pass
def test_add(self):
"""
Create an application session and add it to a router to
run embedded.
"""
d = txaio.create_future()
class TestSession(ApplicationSession):
def onJoin(self, details):
txaio.resolve(d, None)
session = TestSession(types.ComponentConfig(u'realm1'))
self.session_factory.add(session)
return d
def test_application_session_internal_error(self):
"""
simulate an internal error triggering the 'onJoin' error-case from
RouterApplicationSession's send() method (from the Hello msg)
"""
# setup
the_exception = RuntimeError("sadness")
errors = []
class TestSession(ApplicationSession):
def onJoin(self, *args, **kw):
raise the_exception
def onUserError(self, fail, msg):
errors.append((fail, msg))
session = TestSession(types.ComponentConfig(u'realm1'))
from crossbar.router.session import RouterApplicationSession
# Note to self: original code was logging directly in
# RouterApplicationSession -- which *may* actually be better?
# or not...
with mock.patch.object(RouterApplicationSession, 'log') as logger:
# this should call onJoin, triggering our error
self.session_factory.add(session)
if True:
self.assertEqual(1, len(errors), "Didn't see our error")
self.assertEqual(the_exception, errors[0][0].value)
else:
# check we got the right log.failure() call
self.assertTrue(len(logger.method_calls) > 0)
call = logger.method_calls[0]
# for a MagicMock call-object, 0th thing is the method-name, 1st
# thing is the arg-tuple, 2nd thing is the kwargs.
self.assertEqual(call[0], 'failure')
self.assertEqual(call[1][0].value, the_exception)
def test_router_session_internal_error_onHello(self):
#.........这里部分代码省略.........
示例7: TestDealer
# 需要导入模块: from crossbar.router.router import RouterFactory [as 别名]
# 或者: from crossbar.router.router.RouterFactory import get [as 别名]
class TestDealer(unittest.TestCase):
"""
"""
def setUp(self):
"""
Setup router and router session factories.
"""
# create a router factory
self.router_factory = RouterFactory()
# start a realm
self.realm = RouterRealm(u'realm-001', {u'name': u'realm1'})
self.router_factory.start_realm(self.realm)
# allow everything
self.router = self.router_factory.get(u'realm1')
self.router.add_role(
RouterRoleStaticAuth(
self.router,
u'test_role',
default_permissions={
u'uri': u'com.example.',
u'match': u'prefix',
u'allow': {
u'call': True,
u'register': True,
u'publish': True,
u'subscribe': True,
}
}
)
)
# create a router session factory
self.session_factory = RouterSessionFactory(self.router_factory)
def tearDown(self):
pass
@defer.inlineCallbacks
def test_outstanding_invoke(self):
"""
When a call is pending and the callee goes away, it cancels the
in-flight call
"""
session = mock.Mock()
session._realm = u'realm1'
self.router.authorize = mock.Mock(
return_value=defer.succeed({u'allow': True, u'disclose': True})
)
rap = RouterApplicationSession(session, self.router_factory)
rap.send(message.Hello(u"realm1", {u'caller': role.RoleCallerFeatures()}))
rap.send(message.Register(1, u'foo'))
# we can retrieve the Registration via
# session.mock_calls[-1][1][0] if req'd
# re-set the authorize, as the Deferred from above is already
# used-up and it gets called again to authorize the Call
self.router.authorize = mock.Mock(
return_value=defer.succeed({u'allow': True, u'disclose': True})
)
rap.send(message.Call(42, u'foo'))
orig = rap.send
d = defer.Deferred()
rap.send(message.Goodbye())
def wrapper(*args, **kw):
d.callback(args[0])
return orig(*args, **kw)
rap.send = wrapper
# we can do this *after* the call to send() the Goodbye
# (above) because it takes a reactor-turn to actually
# process the cancel/errors etc -- hence the Deferred and
# yield in this test...
msg = yield d
self.assertEqual(42, msg.request)
self.assertEqual(u'wamp.error.canceled', msg.error)
示例8: TestBrokerPublish
# 需要导入模块: from crossbar.router.router import RouterFactory [as 别名]
# 或者: from crossbar.router.router.RouterFactory import get [as 别名]
class TestBrokerPublish(unittest.TestCase):
"""
Tests for crossbar.router.broker.Broker
"""
def setUp(self):
"""
Setup router and router session factories.
"""
# create a router factory
self.router_factory = RouterFactory(None, None)
# start a realm
self.realm = RouterRealm(None, {u'name': u'realm1'})
self.router_factory.start_realm(self.realm)
# allow everything
self.router = self.router_factory.get(u'realm1')
self.router.add_role(
RouterRoleStaticAuth(
self.router,
u'test_role',
default_permissions={
u'uri': u'com.example.',
u'match': u'prefix',
u'allow': {
u'call': True,
u'register': True,
u'publish': True,
u'subscribe': True,
}
}
)
)
# create a router session factory
self.session_factory = RouterSessionFactory(self.router_factory)
def tearDown(self):
pass
def test_add(self):
"""
Create an application session and add it to a router to
run embedded.
"""
d = txaio.create_future()
class TestSession(ApplicationSession):
def onJoin(self, details):
txaio.resolve(d, None)
session = TestSession(types.ComponentConfig(u'realm1'))
self.session_factory.add(session)
return d
def test_application_session_internal_error(self):
"""
simulate an internal error triggering the 'onJoin' error-case from
RouterApplicationSession's send() method (from the Hello msg)
"""
# setup
the_exception = RuntimeError("sadness")
errors = []
class TestSession(ApplicationSession):
def onJoin(self, *args, **kw):
raise the_exception
def onUserError(self, fail, msg):
errors.append((fail, msg))
session = TestSession(types.ComponentConfig(u'realm1'))
from crossbar.router.session import RouterApplicationSession
# Note to self: original code was logging directly in
# RouterApplicationSession -- which *may* actually be better?
# or not...
with mock.patch.object(RouterApplicationSession, 'log') as logger:
# this should call onJoin, triggering our error
self.session_factory.add(session)
if True:
self.assertEqual(1, len(errors), "Didn't see our error")
self.assertEqual(the_exception, errors[0][0].value)
else:
# check we got the right log.failure() call
self.assertTrue(len(logger.method_calls) > 0)
call = logger.method_calls[0]
# for a MagicMock call-object, 0th thing is the method-name, 1st
# thing is the arg-tuple, 2nd thing is the kwargs.
self.assertEqual(call[0], 'failure')
self.assertEqual(call[1][0].value, the_exception)
def test_router_session_internal_error_onHello(self):
#.........这里部分代码省略.........
示例9: TestEmbeddedSessions
# 需要导入模块: from crossbar.router.router import RouterFactory [as 别名]
# 或者: from crossbar.router.router.RouterFactory import get [as 别名]
class TestEmbeddedSessions(unittest.TestCase):
"""
Test cases for application session running embedded in router.
"""
def setUp(self):
"""
Setup router and router session factories.
"""
# create a router factory
self.router_factory = RouterFactory()
# start a realm
self.router_factory.start_realm(RouterRealm(None, {u'name': u'realm1'}))
# allow everything
permissions = RouterPermissions('', True, True, True, True, True)
router = self.router_factory.get(u'realm1')
router.add_role(RouterRoleStaticAuth(router, None, default_permissions=permissions))
# create a router session factory
self.session_factory = RouterSessionFactory(self.router_factory)
def tearDown(self):
pass
def test_add(self):
"""
Create an application session and add it to a router to
run embedded.
"""
d = txaio.create_future()
class TestSession(ApplicationSession):
def onJoin(self, details):
txaio.resolve(d, None)
session = TestSession(types.ComponentConfig(u'realm1'))
self.session_factory.add(session)
return d
def test_add_and_subscribe(self):
"""
Create an application session that subscribes to some
topic and add it to a router to run embedded.
"""
d = txaio.create_future()
class TestSession(ApplicationSession):
def onJoin(self, details):
# noinspection PyUnusedLocal
def on_event(*arg, **kwargs):
pass
d2 = self.subscribe(on_event, u'com.example.topic1')
def ok(_):
txaio.resolve(d, None)
def error(err):
txaio.reject(d, err)
txaio.add_callbacks(d2, ok, error)
session = TestSession(types.ComponentConfig(u'realm1'))
self.session_factory.add(session)
return d
示例10: TestEmbeddedSessions
# 需要导入模块: from crossbar.router.router import RouterFactory [as 别名]
# 或者: from crossbar.router.router.RouterFactory import get [as 别名]
class TestEmbeddedSessions(unittest.TestCase):
"""
Test cases for application session running embedded in router.
"""
def setUp(self):
"""
Setup router and router session factories.
"""
# create a router factory
self.router_factory = RouterFactory()
# start a realm
self.router_factory.start_realm(RouterRealm(None, {u"name": u"realm1"}))
# allow everything
permissions = RouterPermissions("", True, True, True, True, True)
router = self.router_factory.get(u"realm1")
router.add_role(RouterRoleStaticAuth(router, None, default_permissions=permissions))
# create a router session factory
self.session_factory = RouterSessionFactory(self.router_factory)
def tearDown(self):
pass
def test_add(self):
"""
Create an application session and add it to a router to
run embedded.
"""
d = txaio.create_future()
class TestSession(ApplicationSession):
def onJoin(self, details):
txaio.resolve(d, None)
session = TestSession(types.ComponentConfig(u"realm1"))
self.session_factory.add(session)
return d
def test_application_session_internal_error(self):
"""
simulate an internal error triggering the 'onJoin' error-case from
_RouterApplicationSession's send() method (from the Hello msg)
"""
# setup
the_exception = RuntimeError("sadness")
class TestSession(ApplicationSession):
def onJoin(self, *args, **kw):
raise the_exception
session = TestSession(types.ComponentConfig(u"realm1"))
from crossbar.router.session import _RouterApplicationSession
# execute, first patching-out the logger so we can see that
# log.failure() was called when our exception triggers.
with mock.patch.object(_RouterApplicationSession, "log") as logger:
# this should call onJoin, triggering our error
self.session_factory.add(session)
# check we got the right log.failure() call
self.assertTrue(len(logger.method_calls) > 0)
call = logger.method_calls[0]
# for a MagicMock call-object, 0th thing is the method-name, 1st
# thing is the arg-tuple, 2nd thing is the kwargs.
self.assertEqual(call[0], "failure")
self.assertTrue("failure" in call[2])
self.assertEqual(call[2]["failure"].value, the_exception)
def test_router_session_internal_error_onHello(self):
"""
similar to above, but during _RouterSession's onMessage handling,
where it calls self.onHello
"""
# setup
transport = mock.MagicMock()
the_exception = RuntimeError("kerblam")
def boom(*args, **kw):
raise the_exception
session = self.session_factory() # __call__ on the _RouterSessionFactory
session.onHello = boom
session.onOpen(transport)
msg = message.Hello(u"realm1", dict(caller=role.RoleCallerFeatures()))
# XXX think: why isn't this using _RouterSession.log?
from crossbar.router.session import RouterSession
with mock.patch.object(RouterSession, "log") as logger:
# do the test; should call onHello which is now "boom", above
session.onMessage(msg)
# check we got the right log.failure() call
#.........这里部分代码省略.........