當前位置: 首頁>>代碼示例>>Python>>正文


Python PubNubTornado.add_channel_to_channel_group方法代碼示例

本文整理匯總了Python中pubnub.pubnub_tornado.PubNubTornado.add_channel_to_channel_group方法的典型用法代碼示例。如果您正苦於以下問題:Python PubNubTornado.add_channel_to_channel_group方法的具體用法?Python PubNubTornado.add_channel_to_channel_group怎麽用?Python PubNubTornado.add_channel_to_channel_group使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pubnub.pubnub_tornado.PubNubTornado的用法示例。


在下文中一共展示了PubNubTornado.add_channel_to_channel_group方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestChannelGroupSubscription

# 需要導入模塊: from pubnub.pubnub_tornado import PubNubTornado [as 別名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import add_channel_to_channel_group [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,代碼來源:

示例2: TestChannelGroups

# 需要導入模塊: from pubnub.pubnub_tornado import PubNubTornado [as 別名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import add_channel_to_channel_group [as 別名]
class TestChannelGroups(AsyncTestCase):
    def setUp(self):
        super(TestChannelGroups, self).setUp()
        self.pubnub = PubNubTornado(pnconf, custom_ioloop=self.io_loop)

    @use_cassette_and_stub_time_sleep(
        'tests/integrational/fixtures/tornado/groups/add_remove_single_channel.yaml',
        filter_query_parameters=['uuid', 'pnsdk'])
    @tornado.testing.gen_test
    def test_add_remove_single_channel(self):
        ch = "channel-groups-tornado-ch"
        gr = "channel-groups-tornado-cg"

        # add
        env = yield self.pubnub.add_channel_to_channel_group() \
            .channels(ch).channel_group(gr).future()

        assert isinstance(env.result, PNChannelGroupsAddChannelResult)

        yield gen.sleep(1)

        # list
        env = yield self.pubnub.list_channels_in_channel_group().channel_group(gr).future()
        assert isinstance(env.result, PNChannelGroupsListResult)
        assert len(env.result.channels) == 1
        assert env.result.channels[0] == ch

        # remove
        env = yield self.pubnub.remove_channel_from_channel_group() \
            .channels(ch).channel_group(gr).future()

        assert isinstance(env.result, PNChannelGroupsRemoveChannelResult)

        yield gen.sleep(1)

        # list
        env = yield self.pubnub.list_channels_in_channel_group().channel_group(gr).future()
        assert isinstance(env.result, PNChannelGroupsListResult)
        assert len(env.result.channels) == 0

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

    @use_cassette_and_stub_time_sleep(
        'tests/integrational/fixtures/tornado/groups/add_remove_multiple_channel.yaml',
        filter_query_parameters=['uuid', 'pnsdk'])
    @tornado.testing.gen_test
    def test_add_remove_multiple_channels(self):
        ch1 = "channel-groups-tornado-ch1"
        ch2 = "channel-groups-tornado-ch2"
        gr = "channel-groups-tornado-cg"

        # add
        env = yield self.pubnub.add_channel_to_channel_group() \
            .channels([ch1, ch2]).channel_group(gr).future()

        assert isinstance(env.result, PNChannelGroupsAddChannelResult)

        yield gen.sleep(1)

        # list
        env = yield self.pubnub.list_channels_in_channel_group().channel_group(gr).future()
        assert isinstance(env.result, PNChannelGroupsListResult)
        assert len(env.result.channels) == 2
        assert ch1 in env.result.channels
        assert ch2 in env.result.channels

        # remove
        env = yield self.pubnub.remove_channel_from_channel_group() \
            .channels([ch1, ch2]).channel_group(gr).future()

        assert isinstance(env.result, PNChannelGroupsRemoveChannelResult)

        yield gen.sleep(1)

        # list
        env = yield self.pubnub.list_channels_in_channel_group().channel_group(gr).future()
        assert isinstance(env.result, PNChannelGroupsListResult)
        assert len(env.result.channels) == 0

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

    @use_cassette_and_stub_time_sleep(
        'tests/integrational/fixtures/tornado/groups/add_channel_remove_group.yaml',
        filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
    @tornado.testing.gen_test
    def test_add_channel_remove_group(self):
        ch = "channel-groups-tornado-ch"
        gr = "channel-groups-tornado-cg"

        # add
        env = yield self.pubnub.add_channel_to_channel_group() \
            .channels(ch).channel_group(gr).future()

        assert isinstance(env.result, PNChannelGroupsAddChannelResult)

        yield gen.sleep(1)

        # list
#.........這裏部分代碼省略.........
開發者ID:,項目名稱:,代碼行數:103,代碼來源:


注:本文中的pubnub.pubnub_tornado.PubNubTornado.add_channel_to_channel_group方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。