本文整理匯總了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()