本文整理汇总了Python中pubnub.pubnub_asyncio.PubNubAsyncio类的典型用法代码示例。如果您正苦于以下问题:Python PubNubAsyncio类的具体用法?Python PubNubAsyncio怎么用?Python PubNubAsyncio使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PubNubAsyncio类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_single_channel_group
def test_single_channel_group(event_loop):
pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop)
pubnub.config.uuid = "test-pam-asyncio-uuid"
cg = "test-pam-asyncio-cg"
env = (yield from pubnub.grant()
.channel_groups(cg)
.write(True)
.read(True)
.future())
assert isinstance(env.result, PNAccessManagerGrantResult)
assert env.result.level == 'channel-group'
assert env.result.groups[cg].read_enabled == 1
assert env.result.groups[cg].write_enabled == 1
assert env.result.groups[cg].manage_enabled == 0
env = (yield from pubnub.audit()
.channel_groups(cg)
.future())
assert isinstance(env.result, PNAccessManagerAuditResult)
assert env.result.level == 'channel-group'
assert env.result.groups[cg].read_enabled == 1
assert env.result.groups[cg].write_enabled == 1
assert env.result.groups[cg].manage_enabled == 0
pubnub.stop()
示例2: test_success
def test_success(event_loop):
pubnub = PubNubAsyncio(pnconf, custom_event_loop=event_loop)
res = yield from pubnub.delete_messages().channel("my-ch").start(123).end(456).future()
if res.status.is_error():
raise AssertionError()
示例3: test_single_channel_with_auth
def test_single_channel_with_auth(event_loop):
pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop)
pubnub.config.uuid = "test-pam-asyncio-uuid"
ch = "test-pam-asyncio-ch"
auth = "test-pam-asyncio-auth"
env = (yield from pubnub.grant()
.channels(ch)
.write(True)
.read(True)
.auth_keys(auth)
.future())
assert isinstance(env.result, PNAccessManagerGrantResult)
assert env.result.channels[ch].auth_keys[auth].read_enabled == 1
assert env.result.channels[ch].auth_keys[auth].write_enabled == 1
assert env.result.channels[ch].auth_keys[auth].manage_enabled == 0
env = (yield from pubnub.audit()
.channels(ch)
.auth_keys(auth)
.future())
assert isinstance(env.result, PNAccessManagerAuditResult)
assert env.result.channels[ch].auth_keys[auth].read_enabled == 1
assert env.result.channels[ch].auth_keys[auth].write_enabled == 1
assert env.result.channels[ch].auth_keys[auth].manage_enabled == 0
pubnub.stop()
示例4: test_multiple_channels
def test_multiple_channels(event_loop):
pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop)
pubnub.config.uuid = "test-pam-asyncio-uuid"
ch1 = "test-pam-asyncio-ch1"
ch2 = "test-pam-asyncio-ch2"
env = (yield from pubnub.grant()
.channels([ch1, ch2])
.write(True)
.read(True)
.future())
assert isinstance(env.result, PNAccessManagerGrantResult)
assert env.result.channels[ch1].read_enabled is True
assert env.result.channels[ch2].read_enabled is True
assert env.result.channels[ch1].write_enabled is True
assert env.result.channels[ch2].write_enabled is True
assert env.result.channels[ch1].manage_enabled is False
assert env.result.channels[ch2].manage_enabled is False
env = (yield from pubnub.audit()
.channels([ch1, ch2])
.future())
assert isinstance(env.result, PNAccessManagerAuditResult)
assert env.result.channels[ch1].read_enabled is True
assert env.result.channels[ch2].read_enabled is True
assert env.result.channels[ch1].write_enabled is True
assert env.result.channels[ch2].write_enabled is True
assert env.result.channels[ch1].manage_enabled is False
assert env.result.channels[ch2].manage_enabled is False
pubnub.stop()
示例5: test_not_permitted
def test_not_permitted(event_loop):
pnconf = pnconf_pam_copy()
pnconf.secret_key = None
pubnub = PubNubAsyncio(pnconf, custom_event_loop=event_loop)
yield from assert_server_side_error_yield(pubnub.publish().channel(ch).message("hey"), "HTTP Client Error (403")
pubnub.stop()
示例6: test_multiple_channels
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()
示例7: test_multiple_channel_groups_with_auth
def test_multiple_channel_groups_with_auth(event_loop):
pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop)
pubnub.config.uuid = "my_uuid"
gr1 = "test-pam-asyncio-cg1"
gr2 = "test-pam-asyncio-cg2"
auth = "test-pam-asyncio-auth"
env = (yield from pubnub.grant()
.channel_groups([gr1, gr2])
.write(True)
.read(True)
.auth_keys(auth)
.future())
assert isinstance(env.result, PNAccessManagerGrantResult)
assert env.result.groups[gr1].auth_keys[auth].read_enabled is True
assert env.result.groups[gr2].auth_keys[auth].read_enabled is True
assert env.result.groups[gr1].auth_keys[auth].write_enabled is True
assert env.result.groups[gr2].auth_keys[auth].write_enabled is True
assert env.result.groups[gr1].auth_keys[auth].manage_enabled is False
assert env.result.groups[gr2].auth_keys[auth].manage_enabled is False
env = (yield from pubnub.audit()
.channel_groups([gr1, gr2])
.future())
assert isinstance(env.result, PNAccessManagerAuditResult)
assert env.result.groups[gr1].auth_keys[auth].read_enabled is True
assert env.result.groups[gr2].auth_keys[auth].read_enabled is True
assert env.result.groups[gr1].auth_keys[auth].write_enabled is True
assert env.result.groups[gr2].auth_keys[auth].write_enabled is True
assert env.result.groups[gr1].auth_keys[auth].manage_enabled is False
assert env.result.groups[gr2].auth_keys[auth].manage_enabled is False
pubnub.stop()
示例8: test_publish_envelope
def test_publish_envelope(event_loop):
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
envelope = yield from pubnub.publish().message('hey').channel('blah').future()
assert isinstance(envelope, AsyncioEnvelope)
assert not envelope.is_error()
pubnub.stop()
示例9: test_error_non_serializable
def test_error_non_serializable(event_loop):
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
def method():
pass
yield from assert_client_side_error(pubnub.publish().channel(ch).message(method), "not JSON serializable")
pubnub.stop()
示例10: test_publish_envelope_raises
def test_publish_envelope_raises(event_loop):
pubnub = PubNubAsyncio(corrupted_keys, custom_event_loop=event_loop)
e = yield from pubnub.publish().message('hey').channel('blah').future()
assert isinstance(e, PubNubAsyncioException)
assert e.is_error()
assert 400 == e.value()._status_code
pubnub.stop()
示例11: test_publish_super_admin_call
def test_publish_super_admin_call(event_loop):
pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop)
yield from pubnub.publish().channel(ch).message("hey").future()
yield from pubnub.publish().channel("foo.bar").message("hey^&#$").should_store(True).meta({
'name': 'alex'
}).future()
pubnub.stop()
示例12: test_publish_mixed_via_post
def test_publish_mixed_via_post(event_loop):
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
yield from asyncio.gather(
asyncio.ensure_future(assert_success_publish_post(pubnub, "hi")),
asyncio.ensure_future(assert_success_publish_post(pubnub, 5)),
asyncio.ensure_future(assert_success_publish_post(pubnub, True)),
asyncio.ensure_future(assert_success_publish_post(pubnub, ["hi", "hi2", "hi3"])))
pubnub.stop()
示例13: test_time
def test_time(event_loop):
pubnub = PubNubAsyncio(pnconf, custom_event_loop=event_loop)
res = yield from pubnub.time().result()
assert int(res) > 0
assert isinstance(res.date_time(), date)
pubnub.stop()
示例14: test_publish_future_raises_pubnub_error
def test_publish_future_raises_pubnub_error(event_loop):
pubnub = PubNubAsyncio(corrupted_keys, custom_event_loop=event_loop)
with pytest.raises(PubNubException) as exinfo:
yield from pubnub.publish().message('hey').channel('blah').result()
assert 'Invalid Subscribe Key' in str(exinfo.value)
assert 400 == exinfo.value._status_code
pubnub.stop()
示例15: test_error_invalid_key
def test_error_invalid_key(event_loop):
conf = PNConfiguration()
conf.publish_key = "fake"
conf.subscribe_key = "demo"
conf.enable_subscribe = False
pubnub = PubNubAsyncio(conf, custom_event_loop=event_loop)
yield from assert_server_side_error_yield(pubnub.publish().channel(ch).message("hey"), "Invalid Key")
pubnub.stop()