当前位置: 首页>>代码示例>>Python>>正文


Python PubNubTornado.unsubscribe方法代码示例

本文整理汇总了Python中pubnub.pubnub_tornado.PubNubTornado.unsubscribe方法的典型用法代码示例。如果您正苦于以下问题:Python PubNubTornado.unsubscribe方法的具体用法?Python PubNubTornado.unsubscribe怎么用?Python PubNubTornado.unsubscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pubnub.pubnub_tornado.PubNubTornado的用法示例。


在下文中一共展示了PubNubTornado.unsubscribe方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestChannelSubscription

# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import unsubscribe [as 别名]
class TestChannelSubscription(AsyncTestCase, SubscriptionTest):
    def setUp(self):
        super(TestChannelSubscription, self).setUp()
        self.pubnub = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)
        self.pubnub_listener = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)

    @tornado.testing.gen_test
    async def test_subscribe_publish_unsubscribe(self):
        ch = helper.gen_channel("subscribe-test")
        message = "hey"

        callback_messages = SubscribeListener()
        self.pubnub.add_listener(callback_messages)
        self.pubnub.subscribe().channels(ch).execute()
        await callback_messages.wait_for_connect()

        sub_env, pub_env = await tornado.gen.multi([
            callback_messages.wait_for_message_on(ch),
            self.pubnub.publish().channel(ch).message(message).future()])

        assert pub_env.status.original_response[0] == 1
        assert pub_env.status.original_response[1] == 'Sent'

        assert sub_env.channel == ch
        assert sub_env.subscription is None
        assert sub_env.message == message

        self.pubnub.unsubscribe().channels(ch).execute()
        await callback_messages.wait_for_disconnect()
开发者ID:pubnub,项目名称:python,代码行数:31,代码来源:test_tornado_async_await_syntax.py

示例2: TestChannelSubscription

# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import unsubscribe [as 别名]
class TestChannelSubscription(AsyncTestCase, SubscriptionTest):
    def setUp(self):
        super(TestChannelSubscription, self).setUp()

        messenger_config = pnconf_sub_copy()
        messenger_config.set_presence_timeout(8)
        messenger_config.uuid = "heartbeat-tornado-messenger"

        listener_config = pnconf_sub_copy()
        listener_config.uuid = "heartbeat-tornado-listener"

        self.pubnub = PubNubTornado(messenger_config, custom_ioloop=self.io_loop)
        self.pubnub_listener = PubNubTornado(listener_config, custom_ioloop=self.io_loop)

    @use_cassette_and_stub_time_sleep(
        'tests/integrational/fixtures/tornado/heartbeat/timeout.yaml',
        filter_query_parameters=['uuid', 'pnsdk'],
        match_on=['method', 'scheme', 'host', 'port', 'string_list_in_path', 'query'],
        match_on_kwargs={
            'string_list_in_path': {
                'positions': [4]
            }
        })
    @tornado.testing.gen_test(timeout=20)
    def test_timeout_event_on_broken_heartbeat(self):
        ch = "heartbeat-tornado-ch"

        # - connect to :ch-pnpres
        callback_presence = SubscribeListener()
        self.pubnub_listener.add_listener(callback_presence)
        self.pubnub_listener.subscribe().channels(ch).with_presence().execute()
        yield callback_presence.wait_for_connect()

        envelope = yield callback_presence.wait_for_presence_on(ch)
        assert ch == envelope.channel
        assert 'join' == envelope.event
        assert self.pubnub_listener.uuid == envelope.uuid

        # - connect to :ch
        callback_messages = SubscribeListener()
        self.pubnub.add_listener(callback_messages)
        self.pubnub.subscribe().channels(ch).execute()

        # - assert join event
        useless, prs_envelope = yield [
            callback_messages.wait_for_connect(),
            callback_presence.wait_for_presence_on(ch)]
        assert ch == prs_envelope.channel
        assert 'join' == prs_envelope.event
        assert self.pubnub.uuid == prs_envelope.uuid

        # wait for one heartbeat call
        yield gen.sleep(8)

        # - break messenger heartbeat loop
        self.pubnub._subscription_manager._stop_heartbeat_timer()

        # - assert for timeout
        envelope = yield callback_presence.wait_for_presence_on(ch)
        assert ch == envelope.channel
        assert 'timeout' == envelope.event
        assert self.pubnub.uuid == envelope.uuid

        # - disconnect from :ch-pnpres
        self.pubnub_listener.unsubscribe().channels(ch).execute()
        yield callback_presence.wait_for_disconnect()
开发者ID:pubnub,项目名称:python,代码行数:68,代码来源:test_heartbeat.py

示例3: TestChannelSubscription

# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import unsubscribe [as 别名]
class TestChannelSubscription(AsyncTestCase, SubscriptionTest):
    def setUp(self):
        super(TestChannelSubscription, self).setUp()
        self.pubnub = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)
        self.pubnub_listener = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)

    @use_cassette_and_stub_time_sleep(
        'tests/integrational/fixtures/tornado/subscribe/sub_unsub.yaml',
        filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
    @tornado.testing.gen_test(timeout=300)
    def test_subscribe_unsubscribe(self):
        ch = "subscribe-tornado-ch"

        callback_messages = SubscribeListener()
        self.pubnub.add_listener(callback_messages)

        self.pubnub.subscribe().channels(ch).execute()
        assert ch in self.pubnub.get_subscribed_channels()
        assert len(self.pubnub.get_subscribed_channels()) == 1

        yield callback_messages.wait_for_connect()
        assert ch in self.pubnub.get_subscribed_channels()
        assert len(self.pubnub.get_subscribed_channels()) == 1

        self.pubnub.unsubscribe().channels(ch).execute()
        assert ch not in self.pubnub.get_subscribed_channels()
        assert len(self.pubnub.get_subscribed_channels()) == 0

        yield callback_messages.wait_for_disconnect()
        assert ch not in self.pubnub.get_subscribed_channels()
        assert len(self.pubnub.get_subscribed_channels()) == 0

        self.pubnub.stop()
        self.stop()

    @use_cassette_and_stub_time_sleep(
        'tests/integrational/fixtures/tornado/subscribe/sub_pub_unsub.yaml',
        filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
    @tornado.testing.gen_test(timeout=30)
    def test_subscribe_publish_unsubscribe(self):
        ch = "subscribe-tornado-ch"
        message = "hey"

        callback_messages = SubscribeListener()
        self.pubnub.add_listener(callback_messages)
        self.pubnub.subscribe().channels(ch).execute()
        yield callback_messages.wait_for_connect()

        sub_env, pub_env = yield [
            callback_messages.wait_for_message_on(ch),
            self.pubnub.publish().channel(ch).message(message).future()]

        assert pub_env.status.original_response[0] == 1
        assert pub_env.status.original_response[1] == 'Sent'

        assert sub_env.channel == ch
        assert sub_env.subscription is None
        assert sub_env.message == message

        self.pubnub.unsubscribe().channels(ch).execute()
        yield callback_messages.wait_for_disconnect()

    @use_cassette_and_stub_time_sleep(
        'tests/integrational/fixtures/tornado/subscribe/join_leave.yaml',
        filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
    @tornado.testing.gen_test(timeout=30)
    def test_join_leave(self):
        ch = "subscribe-tornado-ch"

        # HINT: use random generated uuids to test without VCR
        # rnd = gen_string(4)
        # self.pubnub.config.uuid = "subscribe-tornado-messenger-%s" % rnd
        # self.pubnub_listener.config.uuid = "subscribe-tornado-listener-%s" % rnd

        self.pubnub.config.uuid = "subscribe-tornado-messenger-3"
        self.pubnub_listener.config.uuid = "subscribe-tornado-listener-3"

        callback_presence = SubscribeListener()
        self.pubnub_listener.add_listener(callback_presence)
        self.pubnub_listener.subscribe().channels(ch).with_presence().execute()
        yield callback_presence.wait_for_connect()

        envelope = yield callback_presence.wait_for_presence_on(ch)
        assert envelope.channel == ch
        assert envelope.event == 'join'
        assert envelope.uuid == self.pubnub_listener.uuid

        callback_messages = SubscribeListener()
        self.pubnub.add_listener(callback_messages)
        self.pubnub.subscribe().channels(ch).execute()
        yield callback_messages.wait_for_connect()

        envelope = yield callback_presence.wait_for_presence_on(ch)
        assert envelope.channel == ch
        assert envelope.event == 'join'
        assert envelope.uuid == self.pubnub.uuid

        self.pubnub.unsubscribe().channels(ch).execute()
        yield callback_messages.wait_for_disconnect()

#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:

示例4: TestChannelGroupSubscription

# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import unsubscribe [as 别名]
class TestChannelGroupSubscription(AsyncTestCase, SubscriptionTest):
    def setUp(self):
        super(TestChannelGroupSubscription, self).setUp()
        self.pubnub = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)
        self.pubnub_listener = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)

    @use_cassette_and_stub_time_sleep(
        'tests/integrational/fixtures/tornado/subscribe/group_sub_unsub.yaml',
        filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
    @tornado.testing.gen_test(timeout=60)
    def test_group_subscribe_unsubscribe(self):
        ch = "subscribe-unsubscribe-channel"
        gr = "subscribe-unsubscribe-group"

        envelope = yield self.pubnub.add_channel_to_channel_group().channel_group(gr).channels(ch).future()
        assert envelope.status.original_response['status'] == 200

        yield gen.sleep(1)

        callback_messages = SubscribeListener()
        self.pubnub.add_listener(callback_messages)
        self.pubnub.subscribe().channel_groups(gr).execute()
        yield callback_messages.wait_for_connect()

        self.pubnub.unsubscribe().channel_groups(gr).execute()
        yield callback_messages.wait_for_disconnect()

        envelope = yield self.pubnub.remove_channel_from_channel_group().channel_group(gr).channels(ch).future()
        assert envelope.status.original_response['status'] == 200

    @use_cassette_and_stub_time_sleep(
        'tests/integrational/fixtures/tornado/subscribe/group_sub_pub_unsub.yaml',
        filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
    @tornado.testing.gen_test(timeout=60)
    def test_group_subscribe_publish_unsubscribe(self):
        ch = "subscribe-unsubscribe-channel"
        gr = "subscribe-unsubscribe-group"
        message = "hey"

        envelope = yield self.pubnub.add_channel_to_channel_group().channel_group(gr).channels(ch).future()
        assert envelope.status.original_response['status'] == 200

        yield gen.sleep(1)

        callback_messages = SubscribeListener()
        self.pubnub.add_listener(callback_messages)
        self.pubnub.subscribe().channel_groups(gr).execute()
        yield callback_messages.wait_for_connect()

        sub_envelope, pub_envelope = yield [
            callback_messages.wait_for_message_on(ch),
            self.pubnub.publish().channel(ch).message(message).future()]

        assert pub_envelope.status.original_response[0] == 1
        assert pub_envelope.status.original_response[1] == 'Sent'

        assert sub_envelope.channel == ch
        assert sub_envelope.subscription == gr
        assert sub_envelope.message == message

        self.pubnub.unsubscribe().channel_groups(gr).execute()
        yield callback_messages.wait_for_disconnect()

        envelope = yield self.pubnub.remove_channel_from_channel_group().channel_group(gr).channels(ch).future()
        assert envelope.status.original_response['status'] == 200

    @use_cassette_and_stub_time_sleep(
        'tests/integrational/fixtures/tornado/subscribe/group_join_leave.yaml',
        filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
    @tornado.testing.gen_test(timeout=60)
    def test_group_join_leave(self):
        self.pubnub.config.uuid = "test-subscribe-messenger"
        self.pubnub_listener.config.uuid = "test-subscribe-listener"

        ch = "subscribe-test-channel"
        gr = "subscribe-test-group"

        envelope = yield self.pubnub.add_channel_to_channel_group().channel_group(gr).channels(ch).future()
        assert envelope.status.original_response['status'] == 200

        yield gen.sleep(1)

        callback_messages = SubscribeListener()
        callback_presence = SubscribeListener()

        self.pubnub_listener.add_listener(callback_presence)
        self.pubnub_listener.subscribe().channel_groups(gr).with_presence().execute()
        yield callback_presence.wait_for_connect()

        prs_envelope = yield callback_presence.wait_for_presence_on(ch)
        assert prs_envelope.event == 'join'
        assert prs_envelope.uuid == self.pubnub_listener.uuid
        assert prs_envelope.channel == ch
        assert prs_envelope.subscription == gr

        self.pubnub.add_listener(callback_messages)
        self.pubnub.subscribe().channel_groups(gr).execute()

        useless, prs_envelope = yield [
            callback_messages.wait_for_connect(),
#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:


注:本文中的pubnub.pubnub_tornado.PubNubTornado.unsubscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。