コード例 #1
0
 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')
コード例 #2
0
ファイル: test_rpc.py プロジェクト: Scille/autobahn-sync
 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'"
コード例 #3
0
ファイル: test_base.py プロジェクト: dotmobo/autobahn-sync
 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')
コード例 #4
0
 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'"
コード例 #5
0
ファイル: test_pubsub.py プロジェクト: Scille/autobahn-sync
 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'"
コード例 #6
0
 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'"
コード例 #7
0
    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"
コード例 #8
0
    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")
コード例 #9
0
    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"
コード例 #10
0
 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'"
コード例 #11
0
ファイル: test_base.py プロジェクト: dotmobo/autobahn-sync
 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"
コード例 #12
0
    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'
コード例 #13
0
    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'
コード例 #14
0
 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"
コード例 #15
0
    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]
コード例 #16
0
ファイル: test_rpc.py プロジェクト: Scille/autobahn-sync
    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]
コード例 #17
0
    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')
コード例 #18
0
ファイル: test_pubsub.py プロジェクト: Scille/autobahn-sync
    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})]
コード例 #19
0
    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})]
コード例 #20
0
ファイル: test_base.py プロジェクト: dotmobo/autobahn-sync
 def test_connect(self, crossbar):
     wamp = AutobahnSync()
     wamp.run()
コード例 #21
0
ファイル: test_pubsub.py プロジェクト: Scille/autobahn-sync
 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'"
コード例 #22
0
 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"
コード例 #23
0
 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'
コード例 #24
0
 def test_already_running(self, crossbar):
     wamp = AutobahnSync()
     wamp.run()
     with pytest.raises(AlreadyRunningError):
         wamp.run()
コード例 #25
0
 def test_connect(self, crossbar):
     wamp = AutobahnSync()
     wamp.run()
コード例 #26
0
ファイル: test_base.py プロジェクト: dotmobo/autobahn-sync
 def test_already_running(self, crossbar):
     wamp = AutobahnSync()
     wamp.run()
     with pytest.raises(AlreadyRunningError):
         wamp.run()