本文整理汇总了Python中pubnub.pubnub_asyncio.PubNubAsyncio.set_state方法的典型用法代码示例。如果您正苦于以下问题:Python PubNubAsyncio.set_state方法的具体用法?Python PubNubAsyncio.set_state怎么用?Python PubNubAsyncio.set_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pubnub.pubnub_asyncio.PubNubAsyncio
的用法示例。
在下文中一共展示了PubNubAsyncio.set_state方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_single_channel_with_subscription
# 需要导入模块: from pubnub.pubnub_asyncio import PubNubAsyncio [as 别名]
# 或者: from pubnub.pubnub_asyncio.PubNubAsyncio import set_state [as 别名]
def test_single_channel_with_subscription(event_loop, sleeper=asyncio.sleep):
pnconf = pnconf_sub_copy()
pnconf.set_presence_timeout(12)
pubnub = PubNubAsyncio(pnconf, custom_event_loop=event_loop)
ch = "test-state-asyncio-ch"
pubnub.config.uuid = "test-state-asyncio-uuid"
state = {"name": "Alex", "count": 5}
callback = VCR599Listener(1)
pubnub.add_listener(callback)
pubnub.subscribe().channels(ch).execute()
yield from callback.wait_for_connect()
yield from sleeper(20)
env = yield from pubnub.set_state().channels(ch).state(state).future()
assert env.result.state["name"] == "Alex"
assert env.result.state["count"] == 5
env = yield from pubnub.get_state().channels(ch).future()
assert env.result.channels[ch]["name"] == "Alex"
assert env.result.channels[ch]["count"] == 5
pubnub.unsubscribe().channels(ch).execute()
yield from callback.wait_for_disconnect()
pubnub.stop()
示例2: test_multiple_channels
# 需要导入模块: from pubnub.pubnub_asyncio import PubNubAsyncio [as 别名]
# 或者: from pubnub.pubnub_asyncio.PubNubAsyncio import set_state [as 别名]
def test_multiple_channels(event_loop):
pubnub = PubNubAsyncio(pnconf, custom_event_loop=event_loop)
ch1 = 'test-state-asyncio-ch1'
ch2 = 'test-state-asyncio-ch2'
pubnub.config.uuid = 'test-state-asyncio-uuid'
state = {"name": "Alex", "count": 5}
env = yield from pubnub.set_state() \
.channels([ch1, ch2]) \
.state(state) \
.future()
assert env.result.state['name'] == "Alex"
assert env.result.state['count'] == 5
env = yield from pubnub.get_state() \
.channels([ch1, ch2]) \
.future()
assert env.result.channels[ch1]['name'] == "Alex"
assert env.result.channels[ch2]['name'] == "Alex"
assert env.result.channels[ch1]['count'] == 5
assert env.result.channels[ch2]['count'] == 5
pubnub.stop()
示例3: test_state_super_admin_call
# 需要导入模块: from pubnub.pubnub_asyncio import PubNubAsyncio [as 别名]
# 或者: from pubnub.pubnub_asyncio.PubNubAsyncio import set_state [as 别名]
def test_state_super_admin_call(event_loop):
pnconf = pnconf_pam_copy()
pubnub = PubNubAsyncio(pnconf, custom_event_loop=event_loop)
ch1 = "test-state-asyncio-ch1"
ch2 = "test-state-asyncio-ch2"
pubnub.config.uuid = "test-state-asyncio-uuid"
state = {"name": "Alex", "count": 5}
env = yield from pubnub.set_state().channels([ch1, ch2]).state(state).future()
assert isinstance(env.result, PNSetStateResult)
env = yield from pubnub.get_state().channels([ch1, ch2]).future()
assert isinstance(env.result, PNGetStateResult)
pubnub.stop()
示例4: test_single_channelx
# 需要导入模块: from pubnub.pubnub_asyncio import PubNubAsyncio [as 别名]
# 或者: from pubnub.pubnub_asyncio.PubNubAsyncio import set_state [as 别名]
def test_single_channelx(event_loop):
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
ch = "test-state-asyncio-ch"
pubnub.config.uuid = "test-state-asyncio-uuid"
state = {"name": "Alex", "count": 5}
env = yield from pubnub.set_state().channels(ch).state(state).future()
assert env.result.state["name"] == "Alex"
assert env.result.state["count"] == 5
env = yield from pubnub.get_state().channels(ch).future()
assert env.result.channels[ch]["name"] == "Alex"
assert env.result.channels[ch]["count"] == 5
pubnub.stop()