本文整理汇总了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(),
#.........这里部分代码省略.........
示例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
#.........这里部分代码省略.........