当前位置: 首页>>代码示例>>Python>>正文


Python PubNubTornado.set_state方法代码示例

本文整理汇总了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()
开发者ID:pubnub,项目名称:python,代码行数:29,代码来源:test_state.py

示例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()
开发者ID:,项目名称:,代码行数:65,代码来源:


注:本文中的pubnub.pubnub_tornado.PubNubTornado.set_state方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。