本文整理汇总了Python中pubnub.pubnub_tornado.PubNubTornado.set_state方法的典型用法代码示例。如果您正苦于以下问题:Python PubNubTornado.set_state方法的具体用法?Python PubNubTornado.set_state怎么用?Python PubNubTornado.set_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pubnub.pubnub_tornado.PubNubTornado
的用法示例。
在下文中一共展示了PubNubTornado.set_state方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_super_call
# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import set_state [as 别名]
def test_super_call(self):
ch1 = "state-tornado-ch1"
ch2 = "state-tornado-ch2"
pnconf = pnconf_pam_copy()
pubnub = PubNubTornado(pnconf, custom_ioloop=self.io_loop)
pubnub.config.uuid = 'test-state-tornado-uuid-|.*$'
state = {"name": "Alex", "count": 5}
env = yield pubnub.set_state() \
.channels([ch1, ch2]) \
.state(state) \
.future()
assert env.result.state['name'] == "Alex"
assert env.result.state['count'] == 5
env = yield 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()
self.stop()
示例2: TestPubNubState
# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import set_state [as 别名]
class TestPubNubState(AsyncTestCase):
def setUp(self):
super(TestPubNubState, self).setUp()
self.pubnub = PubNubTornado(pnconf_copy(), custom_ioloop=self.io_loop)
@use_cassette_and_stub_time_sleep(
'tests/integrational/fixtures/tornado/state/single_channel.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'],
match_on=['method', 'host', 'path', 'state_object_in_query'])
@tornado.testing.gen_test
def test_state_single_channel(self):
ch = "state-tornado-ch"
self.pubnub.config.uuid = 'state-tornado-uuid'
state = {"name": "Alex", "count": 5}
env = yield self.pubnub.set_state() \
.channels(ch) \
.state(state) \
.future()
assert env.result.state['name'] == "Alex"
assert env.result.state['count'] == 5
env = yield self.pubnub.get_state() \
.channels(ch) \
.future()
assert env.result.channels[ch]['name'] == "Alex"
assert env.result.channels[ch]['count'] == 5
self.pubnub.stop()
self.stop()
@use_cassette_and_stub_time_sleep(
'tests/integrational/fixtures/tornado/state/multiple_channel.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'],
match_on=['method', 'host', 'path', 'state_object_in_query'])
@tornado.testing.gen_test
def test_multiple_channels(self):
ch1 = "state-tornado-ch1"
ch2 = "state-tornado-ch2"
self.pubnub.config.uuid = 'state-tornado-uuid'
state = {"name": "Alex", "count": 5}
env = yield self.pubnub.set_state() \
.channels([ch1, ch2]) \
.state(state) \
.future()
assert env.result.state['name'] == "Alex"
assert env.result.state['count'] == 5
env = yield self.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
self.pubnub.stop()
self.stop()