本文整理汇总了Python中pubnub.pubnub_tornado.PubNubTornado.publish方法的典型用法代码示例。如果您正苦于以下问题:Python PubNubTornado.publish方法的具体用法?Python PubNubTornado.publish怎么用?Python PubNubTornado.publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pubnub.pubnub_tornado.PubNubTornado
的用法示例。
在下文中一共展示了PubNubTornado.publish方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestChannelSubscription
# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import publish [as 别名]
class TestChannelSubscription(AsyncTestCase, SubscriptionTest):
def setUp(self):
super(TestChannelSubscription, self).setUp()
self.pubnub = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)
self.pubnub_listener = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)
@tornado.testing.gen_test
async def test_subscribe_publish_unsubscribe(self):
ch = helper.gen_channel("subscribe-test")
message = "hey"
callback_messages = SubscribeListener()
self.pubnub.add_listener(callback_messages)
self.pubnub.subscribe().channels(ch).execute()
await callback_messages.wait_for_connect()
sub_env, pub_env = await tornado.gen.multi([
callback_messages.wait_for_message_on(ch),
self.pubnub.publish().channel(ch).message(message).future()])
assert pub_env.status.original_response[0] == 1
assert pub_env.status.original_response[1] == 'Sent'
assert sub_env.channel == ch
assert sub_env.subscription is None
assert sub_env.message == message
self.pubnub.unsubscribe().channels(ch).execute()
await callback_messages.wait_for_disconnect()
示例2: test_publish_futurex
# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import publish [as 别名]
def test_publish_futurex(self):
pubnub = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)
envelope = yield pubnub.publish().message('hey').channel('blah').future()
assert isinstance(envelope, TornadoEnvelope)
assert not envelope.is_error()
pubnub.stop()
示例3: test_publish_future_raises
# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import publish [as 别名]
def test_publish_future_raises(self):
pubnub = PubNubTornado(corrupted_keys, custom_ioloop=self.io_loop)
e = yield pubnub.publish().message('hey').channel('blah').future()
assert isinstance(e, PubNubTornadoException)
assert e.is_error()
assert 400 == e.value()._status_code
pubnub.stop()
示例4: test_publish_result_raises_pubnub_error
# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import publish [as 别名]
def test_publish_result_raises_pubnub_error(self):
pubnub = PubNubTornado(corrupted_keys, custom_ioloop=self.io_loop)
with pytest.raises(PubNubException) as exinfo:
yield pubnub.publish().message('hey').channel('blah').result()
assert 'Invalid Subscribe Key' in str(exinfo.value)
assert 400 == exinfo.value._status_code
pubnub.stop()
示例5: TestMessageCount
# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import publish [as 别名]
class TestMessageCount(AsyncTestCase):
def setUp(self):
AsyncTestCase.setUp(self)
config = pnconf_mc_copy()
config.enable_subscribe = False
self.pn = PubNubTornado(config, custom_ioloop=self.io_loop)
@pn_vcr.use_cassette('tests/integrational/fixtures/tornado/message_count/single.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_cg', 'l_pub'])
@tornado.testing.gen_test
def test_single_channel(self):
chan = 'unique_tornado'
envelope = yield self.pn.publish().channel(chan).message('bla').future()
time = envelope.result.timetoken - 10
envelope = yield self.pn.message_counts().channel(chan).channel_timetokens([time]).future()
assert(isinstance(envelope, TornadoEnvelope))
assert not envelope.status.is_error()
assert envelope.result.channels[chan] == 1
assert isinstance(envelope.result, PNMessageCountResult)
assert isinstance(envelope.status, PNStatus)
self.pn.stop()
@pn_vcr.use_cassette('tests/integrational/fixtures/tornado/message_count/multi.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_cg', 'l_pub'])
@tornado.testing.gen_test
def test_multiple_channels(self):
chan_1 = 'unique_asyncio_1'
chan_2 = 'unique_asyncio_2'
chans = ','.join([chan_1, chan_2])
envelope = yield self.pn.publish().channel(chan_1).message('something').future()
time = envelope.result.timetoken - 10
envelope = yield self.pn.message_counts().channel(chans).channel_timetokens([time, time]).future()
assert(isinstance(envelope, TornadoEnvelope))
assert not envelope.status.is_error()
assert envelope.result.channels[chan_1] == 1
assert envelope.result.channels[chan_2] == 0
assert isinstance(envelope.result, PNMessageCountResult)
assert isinstance(envelope.status, PNStatus)
self.pn.stop()
示例6: xtest_publish_future_raises_lower_level_error
# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import publish [as 别名]
def xtest_publish_future_raises_lower_level_error(self):
pubnub = PubNubTornado(corrupted_keys, custom_ioloop=self.io_loop)
pubnub.http.close()
e = yield pubnub.publish().message('hey').channel('blah').future()
assert isinstance(e, PubNubTornadoException)
assert str(e) == "fetch() called on closed AsyncHTTPClient"
pubnub.stop()
示例7: xtest_publish_result_raises_lower_level_error
# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import publish [as 别名]
def xtest_publish_result_raises_lower_level_error(self):
pubnub = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)
# TODO: find a better way ot emulate broken connection
pubnub.http.close()
with self.assertRaises(Exception) as context:
yield pubnub.publish().message('hey').channel('blah').result()
assert 'fetch() called on closed AsyncHTTPClient' in str(context.exception.message)
pubnub.stop()
示例8: test_publish_ssl
# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import publish [as 别名]
def test_publish_ssl(self):
print(sys.version_info)
pubnub = PubNubTornado(pnconf_ssl_copy(), custom_ioloop=self.io_loop)
msg = "hey"
pub = pubnub.publish().channel(ch).message(msg)
envelope = yield pub.future()
assert isinstance(envelope, TornadoEnvelope)
assert isinstance(envelope.result, PNPublishResult)
assert isinstance(envelope.status, PNStatus)
assert envelope.result.timetoken > 0
assert len(envelope.status.original_response) > 0
pubnub.stop()
示例9: TestPubNubAsyncPublish
# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import publish [as 别名]
class TestPubNubAsyncPublish(AsyncTestCase):
def setUp(self):
AsyncTestCase.setUp(self)
self.env = None
def callback(self, tornado_res):
self.env = tornado_res.result()
self.pubnub.stop()
self.stop()
def assert_success(self, pub):
pub.future().add_done_callback(self.callback)
self.pubnub.start()
self.wait()
assert isinstance(self.env, TornadoEnvelope)
assert isinstance(self.env.result, PNPublishResult)
assert isinstance(self.env.status, PNStatus)
assert self.env.result.timetoken > 0
assert len(self.env.status.original_response) > 0
@tornado.testing.gen_test
def assert_success_yield(self, pub):
envelope = yield pub.future()
assert isinstance(envelope, TornadoEnvelope)
assert isinstance(envelope.result, PNPublishResult)
assert isinstance(envelope.status, PNStatus)
assert envelope.result.timetoken > 0
assert len(envelope.status.original_response) > 0
def assert_success_publish_get(self, msg):
self.pubnub = PubNubTornado(pnconf, custom_ioloop=self.io_loop)
self.assert_success(self.pubnub.publish().channel(ch).message(msg))
self.assert_success_yield(self.pubnub.publish().channel(ch).message(msg))
def assert_success_publish_post(self, msg):
self.pubnub = PubNubTornado(pnconf, custom_ioloop=self.io_loop)
self.assert_success(self.pubnub.publish().channel(ch).message(msg).use_post(True))
self.assert_success_yield(self.pubnub.publish().channel(ch).message(msg).use_post(True))
def assert_success_publish_get_encrypted(self, msg):
self.pubnub = PubNubTornado(pnconf_enc, custom_ioloop=self.io_loop)
self.assert_success(self.pubnub.publish().channel(ch).message(msg))
self.assert_success_yield(self.pubnub.publish().channel(ch).message(msg))
def assert_success_publish_post_encrypted(self, msg):
self.pubnub = PubNubTornado(pnconf_enc, custom_ioloop=self.io_loop)
self.assert_success(self.pubnub.publish().channel(ch).message(msg).use_post(True))
self.assert_success_yield(self.pubnub.publish().channel(ch).message(msg).use_post(True))
def assert_client_side_error(self, pub, expected_err_msg):
try:
yield pub.future()
self.pubnub.start()
self.wait()
except PubNubException as e:
assert expected_err_msg in str(e)
self.pubnub.stop()
self.stop()
@pn_vcr.use_cassette(
'tests/integrational/fixtures/tornado/publish/mixed_via_get.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub'])
def test_publish_mixed_via_get(self):
self.assert_success_publish_get("hi")
self.assert_success_publish_get(5)
self.assert_success_publish_get(True)
self.assert_success_publish_get(["hi", "hi2", "hi3"])
@pn_vcr.use_cassette(
'tests/integrational/fixtures/tornado/publish/object_via_get.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub'],
match_on=['method', 'scheme', 'host', 'port', 'object_in_path', 'query'])
def test_publish_object_via_get(self):
self.assert_success_publish_get({"name": "Alex", "online": True})
@pn_vcr.use_cassette(
'tests/integrational/fixtures/tornado/publish/mixed_via_post.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub'],
match_on=['method', 'scheme', 'host', 'port', 'path', 'query'])
def test_publish_mixed_via_post(self):
self.assert_success_publish_post("hi")
self.assert_success_publish_post(5)
self.assert_success_publish_post(True)
self.assert_success_publish_post(["hi", "hi2", "hi3"])
@pn_vcr.use_cassette(
'tests/integrational/fixtures/tornado/publish/object_via_post.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub'],
match_on=['host', 'method', 'path', 'query', 'object_in_body'])
def test_publish_object_via_post(self):
self.assert_success_publish_post({"name": "Alex", "online": True})
@pn_vcr.use_cassette(
'tests/integrational/fixtures/tornado/publish/mixed_via_get_encrypted.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub'])
#.........这里部分代码省略.........
示例10: TestChannelSubscription
# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import publish [as 别名]
class TestChannelSubscription(AsyncTestCase, SubscriptionTest):
def setUp(self):
super(TestChannelSubscription, self).setUp()
self.pubnub = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)
self.pubnub_listener = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)
@use_cassette_and_stub_time_sleep(
'tests/integrational/fixtures/tornado/subscribe/sub_unsub.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
@tornado.testing.gen_test(timeout=300)
def test_subscribe_unsubscribe(self):
ch = "subscribe-tornado-ch"
callback_messages = SubscribeListener()
self.pubnub.add_listener(callback_messages)
self.pubnub.subscribe().channels(ch).execute()
assert ch in self.pubnub.get_subscribed_channels()
assert len(self.pubnub.get_subscribed_channels()) == 1
yield callback_messages.wait_for_connect()
assert ch in self.pubnub.get_subscribed_channels()
assert len(self.pubnub.get_subscribed_channels()) == 1
self.pubnub.unsubscribe().channels(ch).execute()
assert ch not in self.pubnub.get_subscribed_channels()
assert len(self.pubnub.get_subscribed_channels()) == 0
yield callback_messages.wait_for_disconnect()
assert ch not in self.pubnub.get_subscribed_channels()
assert len(self.pubnub.get_subscribed_channels()) == 0
self.pubnub.stop()
self.stop()
@use_cassette_and_stub_time_sleep(
'tests/integrational/fixtures/tornado/subscribe/sub_pub_unsub.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
@tornado.testing.gen_test(timeout=30)
def test_subscribe_publish_unsubscribe(self):
ch = "subscribe-tornado-ch"
message = "hey"
callback_messages = SubscribeListener()
self.pubnub.add_listener(callback_messages)
self.pubnub.subscribe().channels(ch).execute()
yield callback_messages.wait_for_connect()
sub_env, pub_env = yield [
callback_messages.wait_for_message_on(ch),
self.pubnub.publish().channel(ch).message(message).future()]
assert pub_env.status.original_response[0] == 1
assert pub_env.status.original_response[1] == 'Sent'
assert sub_env.channel == ch
assert sub_env.subscription is None
assert sub_env.message == message
self.pubnub.unsubscribe().channels(ch).execute()
yield callback_messages.wait_for_disconnect()
@use_cassette_and_stub_time_sleep(
'tests/integrational/fixtures/tornado/subscribe/join_leave.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
@tornado.testing.gen_test(timeout=30)
def test_join_leave(self):
ch = "subscribe-tornado-ch"
# HINT: use random generated uuids to test without VCR
# rnd = gen_string(4)
# self.pubnub.config.uuid = "subscribe-tornado-messenger-%s" % rnd
# self.pubnub_listener.config.uuid = "subscribe-tornado-listener-%s" % rnd
self.pubnub.config.uuid = "subscribe-tornado-messenger-3"
self.pubnub_listener.config.uuid = "subscribe-tornado-listener-3"
callback_presence = SubscribeListener()
self.pubnub_listener.add_listener(callback_presence)
self.pubnub_listener.subscribe().channels(ch).with_presence().execute()
yield callback_presence.wait_for_connect()
envelope = yield callback_presence.wait_for_presence_on(ch)
assert envelope.channel == ch
assert envelope.event == 'join'
assert envelope.uuid == self.pubnub_listener.uuid
callback_messages = SubscribeListener()
self.pubnub.add_listener(callback_messages)
self.pubnub.subscribe().channels(ch).execute()
yield callback_messages.wait_for_connect()
envelope = yield callback_presence.wait_for_presence_on(ch)
assert envelope.channel == ch
assert envelope.event == 'join'
assert envelope.uuid == self.pubnub.uuid
self.pubnub.unsubscribe().channels(ch).execute()
yield callback_messages.wait_for_disconnect()
#.........这里部分代码省略.........
示例11: TestChannelGroupSubscription
# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import publish [as 别名]
class TestChannelGroupSubscription(AsyncTestCase, SubscriptionTest):
def setUp(self):
super(TestChannelGroupSubscription, self).setUp()
self.pubnub = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)
self.pubnub_listener = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)
@use_cassette_and_stub_time_sleep(
'tests/integrational/fixtures/tornado/subscribe/group_sub_unsub.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
@tornado.testing.gen_test(timeout=60)
def test_group_subscribe_unsubscribe(self):
ch = "subscribe-unsubscribe-channel"
gr = "subscribe-unsubscribe-group"
envelope = yield self.pubnub.add_channel_to_channel_group().channel_group(gr).channels(ch).future()
assert envelope.status.original_response['status'] == 200
yield gen.sleep(1)
callback_messages = SubscribeListener()
self.pubnub.add_listener(callback_messages)
self.pubnub.subscribe().channel_groups(gr).execute()
yield callback_messages.wait_for_connect()
self.pubnub.unsubscribe().channel_groups(gr).execute()
yield callback_messages.wait_for_disconnect()
envelope = yield self.pubnub.remove_channel_from_channel_group().channel_group(gr).channels(ch).future()
assert envelope.status.original_response['status'] == 200
@use_cassette_and_stub_time_sleep(
'tests/integrational/fixtures/tornado/subscribe/group_sub_pub_unsub.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
@tornado.testing.gen_test(timeout=60)
def test_group_subscribe_publish_unsubscribe(self):
ch = "subscribe-unsubscribe-channel"
gr = "subscribe-unsubscribe-group"
message = "hey"
envelope = yield self.pubnub.add_channel_to_channel_group().channel_group(gr).channels(ch).future()
assert envelope.status.original_response['status'] == 200
yield gen.sleep(1)
callback_messages = SubscribeListener()
self.pubnub.add_listener(callback_messages)
self.pubnub.subscribe().channel_groups(gr).execute()
yield callback_messages.wait_for_connect()
sub_envelope, pub_envelope = yield [
callback_messages.wait_for_message_on(ch),
self.pubnub.publish().channel(ch).message(message).future()]
assert pub_envelope.status.original_response[0] == 1
assert pub_envelope.status.original_response[1] == 'Sent'
assert sub_envelope.channel == ch
assert sub_envelope.subscription == gr
assert sub_envelope.message == message
self.pubnub.unsubscribe().channel_groups(gr).execute()
yield callback_messages.wait_for_disconnect()
envelope = yield self.pubnub.remove_channel_from_channel_group().channel_group(gr).channels(ch).future()
assert envelope.status.original_response['status'] == 200
@use_cassette_and_stub_time_sleep(
'tests/integrational/fixtures/tornado/subscribe/group_join_leave.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
@tornado.testing.gen_test(timeout=60)
def test_group_join_leave(self):
self.pubnub.config.uuid = "test-subscribe-messenger"
self.pubnub_listener.config.uuid = "test-subscribe-listener"
ch = "subscribe-test-channel"
gr = "subscribe-test-group"
envelope = yield self.pubnub.add_channel_to_channel_group().channel_group(gr).channels(ch).future()
assert envelope.status.original_response['status'] == 200
yield gen.sleep(1)
callback_messages = SubscribeListener()
callback_presence = SubscribeListener()
self.pubnub_listener.add_listener(callback_presence)
self.pubnub_listener.subscribe().channel_groups(gr).with_presence().execute()
yield callback_presence.wait_for_connect()
prs_envelope = yield callback_presence.wait_for_presence_on(ch)
assert prs_envelope.event == 'join'
assert prs_envelope.uuid == self.pubnub_listener.uuid
assert prs_envelope.channel == ch
assert prs_envelope.subscription == gr
self.pubnub.add_listener(callback_messages)
self.pubnub.subscribe().channel_groups(gr).execute()
useless, prs_envelope = yield [
callback_messages.wait_for_connect(),
#.........这里部分代码省略.........
示例12: test_publish_resultx
# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import publish [as 别名]
def test_publish_resultx(self):
pubnub = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)
result = yield pubnub.publish().message('hey').channel('blah').result()
assert isinstance(result, PNPublishResult)
pubnub.stop()