def test_leave(self, crossbar): wamp = AutobahnSync() wamp.run() wamp.session.publish('com.disconnect.ready') wamp.session.leave() with pytest.raises(TransportLost): wamp.session.publish('com.disconnect.no_realm')
def test_no_call(self, crossbar): wamp = AutobahnSync() wamp.run(realm=u'realm_limited') wamp.session.register(lambda: None, u'rpc.no_call.func') with pytest.raises(ApplicationError) as exc: wamp.session.call(u'rpc.no_call.func', None) assert str(exc.value.args[0]) == u"session is not authorized to call procedure 'rpc.no_call.func'"
def test_no_subscribe(self, crossbar): wamp = AutobahnSync() wamp.run(realm=u'realm_limited') with pytest.raises(ApplicationError) as exc: wamp.session.subscribe(lambda: None, 'pubsub.no_subscribe.event') assert str( exc.value.args[0] ) == "session is not authorized to subscribe to topic 'pubsub.no_subscribe.event'"
def test_no_publish(self, crossbar): wamp = AutobahnSync() wamp.run(realm=u'realm_limited') wamp.session.subscribe(lambda: None, 'pubsub.no_publish.event') publish_opt = PublishOptions(acknowledge=True) with pytest.raises(ApplicationError) as exc: res = wamp.session.publish(u'pubsub.no_publish.event', None, options=publish_opt) assert str(exc.value.args[0]) == u"session not authorized to publish to topic 'pubsub.no_publish.event'"
def test_no_register(self, crossbar): wamp = AutobahnSync() wamp.run(realm=u'realm_limited') with pytest.raises(ApplicationError) as exc: wamp.session.register(lambda: None, u'rpc.no_register.func') assert str( exc.value.args[0] ) == u"session is not authorized to register procedure 'rpc.no_register.func'"
def test_bad_authid(self, crossbar): wamp = AutobahnSync() @wamp.on_challenge def on_challenge(challenge): pass with pytest.raises(AbortError) as exc: wamp.run(url=u"ws://localhost:8080/ws_auth", authid="dummy", authmethods=[u"ticket"]) assert str(exc.value.args[0].reason) == "wamp.error.not_authorized"
def test_good_auth(self, crossbar): wamp = AutobahnSync() @wamp.on_challenge def on_challenge(challenge): assert challenge.method == "ticket" return "ticket_secret" wamp.run(realm=u"realm1", url=u"ws://localhost:8080/ws_auth", authid="ticket_user_1", authmethods=[u"ticket"]) # Make sure we are connected wamp.session.subscribe(lambda: None, u"test.challenge.event")
def test_bad_method(self, crossbar): wamp = AutobahnSync() @wamp.on_challenge def on_challenge(challenge): raise Exception("Invalid authmethod %s" % challenge.method) with pytest.raises(AbortError) as exc: wamp.run( realm=u"realm1", url=u"ws://localhost:8080/ws_auth", authid="ticket_user_1", authmethods=[u"ticket"] ) assert str(exc.value.args[0]) == "Invalid authmethod ticket"
def test_no_publish(self, crossbar): wamp = AutobahnSync() wamp.run(realm=u'realm_limited') wamp.session.subscribe(lambda: None, 'pubsub.no_publish.event') publish_opt = PublishOptions(acknowledge=True) with pytest.raises(ApplicationError) as exc: res = wamp.session.publish(u'pubsub.no_publish.event', None, options=publish_opt) assert str( exc.value.args[0] ) == u"session not authorized to publish to topic 'pubsub.no_publish.event'"
def test_stop(self, crossbar): wamp = AutobahnSync() wamp.run() wamp.session.publish('com.disconnect.ready') wamp.session.leave() wamp.stop() sleep(0.1) # Dirty way to wait for stop... with pytest.raises(TransportLost): wamp.session.publish('com.disconnect.no_realm') with pytest.raises(NotRunningError) as exc: wamp.stop() assert str(exc.value.args[0]) == "This AutobahnSync instance is not started"
def test_bad_authid(self, crossbar): wamp = AutobahnSync() @wamp.on_challenge def on_challenge(challenge): pass with pytest.raises(AbortError) as exc: wamp.run(url=u'ws://localhost:8080/ws_auth', authid='dummy', authmethods=[u'ticket']) assert str(exc.value.args[0].reason) == 'wamp.error.not_authorized'
def test_bad_method(self, crossbar): wamp = AutobahnSync() @wamp.on_challenge def on_challenge(challenge): raise Exception("Invalid authmethod %s" % challenge.method) with pytest.raises(AbortError) as exc: wamp.run(realm=u'realm1', url=u'ws://localhost:8080/ws_auth', authid='ticket_user_1', authmethods=[u'ticket']) assert str(exc.value.args[0]) == 'Invalid authmethod ticket'
def test_stop(self, crossbar): wamp = AutobahnSync() wamp.run() wamp.session.publish('com.disconnect.ready') wamp.session.leave() wamp.stop() sleep(0.1) # Dirty way to wait for stop... with pytest.raises(TransportLost): wamp.session.publish('com.disconnect.no_realm') with pytest.raises(NotRunningError) as exc: wamp.stop() assert str( exc.value.args[0]) == "This AutobahnSync instance is not started"
def test_decorate_before_run(self, crossbar): wamp = AutobahnSync() rets = [] counter_func = CounterHelper() @wamp.register('rpc.decorate_before_run.func') def my_func(*args, **kwargs): return counter_func() wamp.run() rets.append(wamp.session.call('rpc.decorate_before_run.func')) rets.append(wamp.session.call('rpc.decorate_before_run.func')) rets.append(wamp.session.call('rpc.decorate_before_run.func')) assert rets == [1, 2, 3]
def test_good_auth(self, crossbar): wamp = AutobahnSync() @wamp.on_challenge def on_challenge(challenge): assert challenge.method == 'ticket' return 'ticket_secret' wamp.run(realm=u'realm1', url=u'ws://localhost:8080/ws_auth', authid='ticket_user_1', authmethods=[u'ticket']) # Make sure we are connected wamp.session.subscribe(lambda: None, u'test.challenge.event')
def test_decorate_before_run(self, crossbar): events = [] wamp = AutobahnSync() @wamp.subscribe(u'pubsub.decorate_before_run.event') def on_event(*args, **kwargs): events.append((args, kwargs)) wamp.run() publish_opt = PublishOptions(exclude_me=False) wamp.session.publish('pubsub.decorate_before_run.event', '1', options=publish_opt) wamp.session.publish('pubsub.decorate_before_run.event', '2', options=publish_opt) wamp.session.publish('pubsub.decorate_before_run.event', opt=True, options=publish_opt) sleep(0.1) # Dirty way to wait for on_event to be called... assert events == [(('1',), {}), (('2',), {}), ((), {'opt': True})]
def test_decorate_before_run(self, crossbar): events = [] wamp = AutobahnSync() @wamp.subscribe(u'pubsub.decorate_before_run.event') def on_event(*args, **kwargs): events.append((args, kwargs)) wamp.run() publish_opt = PublishOptions(exclude_me=False) wamp.session.publish('pubsub.decorate_before_run.event', '1', options=publish_opt) wamp.session.publish('pubsub.decorate_before_run.event', '2', options=publish_opt) wamp.session.publish('pubsub.decorate_before_run.event', opt=True, options=publish_opt) sleep(0.1) # Dirty way to wait for on_event to be called... assert events == [(('1', ), {}), (('2', ), {}), ((), {'opt': True})]
def test_connect(self, crossbar): wamp = AutobahnSync() wamp.run()
def test_no_subscribe(self, crossbar): wamp = AutobahnSync() wamp.run(realm=u'realm_limited') with pytest.raises(ApplicationError) as exc: wamp.session.subscribe(lambda: None, 'pubsub.no_subscribe.event') assert str(exc.value.args[0]) == "session is not authorized to subscribe to topic 'pubsub.no_subscribe.event'"
def test_no_auth_method(self, crossbar): wamp = AutobahnSync() with pytest.raises(AbortError) as exc: wamp.run(url=u"ws://localhost:8080/ws_auth", authmethods=[u"wampcra"]) assert str(exc.value.args[0].reason) == "wamp.error.no_auth_method"
def test_no_auth_method(self, crossbar): wamp = AutobahnSync() with pytest.raises(AbortError) as exc: wamp.run(url=u'ws://localhost:8080/ws_auth', authmethods=[u'wampcra']) assert str(exc.value.args[0].reason) == 'wamp.error.no_auth_method'
def test_already_running(self, crossbar): wamp = AutobahnSync() wamp.run() with pytest.raises(AlreadyRunningError): wamp.run()