def test_get_uuid_endpoint_available(self): config = pnconf_copy() pn = PubNub(config) get_uuid = pn.get_uuid_metadata() assert get_uuid is not None assert isinstance(get_uuid, GetUuid) assert isinstance(get_uuid, Endpoint)
def test_basic(self): ch = "history-native-sync-ch" pubnub = PubNub(pnconf_copy()) pubnub.config.uuid = "history-native-sync-uuid" for i in range(COUNT): envelope = pubnub.publish().channel(ch).message("hey-%s" % i).sync() assert isinstance(envelope.result, PNPublishResult) assert envelope.result.timetoken > 0 time.sleep(5) envelope = pubnub.history().channel(ch).count(COUNT).sync() assert isinstance(envelope.result, PNHistoryResult) assert envelope.result.start_timetoken > 0 assert envelope.result.end_timetoken > 0 assert len(envelope.result.messages) == 5 assert envelope.result.messages[0].entry == 'hey-0' assert envelope.result.messages[1].entry == 'hey-1' assert envelope.result.messages[2].entry == 'hey-2' assert envelope.result.messages[3].entry == 'hey-3' assert envelope.result.messages[4].entry == 'hey-4'
async def test_publish_envelope(event_loop): pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop) envelope = await pubnub.publish().message('hey').channel('blah').future() assert isinstance(envelope, AsyncioEnvelope) assert not envelope.is_error() pubnub.stop()
def _pubnub(): config = pnconf_copy() # use subscribe key that associated with app that has Objects turned on and comment skip annotation config.subscribe_key = "SUBSCRIBE_KEY" config.log_verbosity = True config.enable_subscribe = True return PubNub(config)
def test_multiple_channels(self): ch1 = "state-native-sync-ch-1" ch2 = "state-native-sync-ch-2" pubnub = PubNub(pnconf_copy()) pubnub.config.uuid = "state-native-sync-uuid" state = {"name": "Alex", "count": 5} pubnub.set_state().channels([ch1, ch2]).state(state).async(self.callback) self.event.wait() assert not self.status.is_error() assert isinstance(self.response, PNSetStateResult) assert self.response.state["name"] == "Alex" assert self.response.state["count"] == 5 self.event.clear() pubnub.get_state().channels([ch1, ch2]).async(self.callback) self.event.wait() assert not self.status.is_error() assert isinstance(self.response, PNGetStateResult) assert self.response.channels[ch1]["name"] == "Alex" assert self.response.channels[ch1]["count"] == 5 assert self.response.channels[ch2]["name"] == "Alex" assert self.response.channels[ch2]["count"] == 5
def test_single_channel(self): ch = "state-native-sync-ch" pubnub = PubNub(pnconf_copy()) pubnub.config.uuid = "state-native-sync-uuid" state = {"name": "Alex", "count": 5} pubnub.set_state() \ .channels(ch) \ .state(state) \ .pn_async(self.callback) self.event.wait() assert not self.status.is_error() assert isinstance(self.response, PNSetStateResult) assert self.response.state['name'] == "Alex" assert self.response.state['count'] == 5 self.event.clear() pubnub.get_state() \ .channels(ch) \ .pn_async(self.callback) self.event.wait() assert not self.status.is_error() assert isinstance(self.response, PNGetStateResult) assert self.response.channels[ch]['name'] == "Alex" assert self.response.channels[ch]['count'] == 5
def setUp(self): self.pubnub = MagicMock(spec=PubNub, config=pnconf_copy(), sdk_name=sdk_name) self.pubnub.uuid = "UUID_HeartbeatUnitTest" self.hb = Heartbeat(self.pubnub) self.pubnub.config.set_presence_timeout(20)
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()
def test_remove_uuid_endpoint_available(self): config = pnconf_copy() pn = PubNub(config) remove_uuid = pn.remove_uuid_metadata() assert remove_uuid is not None assert isinstance(remove_uuid, RemoveUuid) assert isinstance(remove_uuid, Endpoint)
def test_multiple_channels(self): ch1 = "state-native-sync-ch-1" ch2 = "state-native-sync-ch-2" pubnub = PubNub(pnconf_copy()) pubnub.config.uuid = "state-native-sync-uuid" state = {"name": "Alex", "count": 5} pubnub.set_state() \ .channels([ch1, ch2]) \ .state(state) \ .pn_async(self.callback) self.event.wait() assert not self.status.is_error() assert isinstance(self.response, PNSetStateResult) assert self.response.state['name'] == "Alex" assert self.response.state['count'] == 5 self.event.clear() pubnub.get_state() \ .channels([ch1, ch2]) \ .pn_async(self.callback) self.event.wait() assert not self.status.is_error() assert isinstance(self.response, PNGetStateResult) assert self.response.channels[ch1]['name'] == "Alex" assert self.response.channels[ch1]['count'] == 5 assert self.response.channels[ch2]['name'] == "Alex" assert self.response.channels[ch2]['count'] == 5
def test_publish_future(event_loop): pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop) result = yield from pubnub.publish().message('hey').channel( 'blah').result() assert isinstance(result, PNPublishResult) pubnub.stop()
def setUp(self): self.pubnub = MagicMock(spec=PubNub, config=pnconf_copy(), sdk_name=sdk_name) self.pubnub.config.uuid = "UUID_WhereNowTest" self.pubnub._telemetry_manager = TelemetryManager() self.where_now = WhereNow(self.pubnub)
def test_fetch_messages_return_max_25_for_multiple_channels(self): ch1 = "fetch-messages-ch-1" ch2 = "fetch-messages-ch-2" pubnub = PubNub(pnconf_copy()) pubnub.config.uuid = "fetch-messages-uuid" for i in range(COUNT): envelope1 = pubnub.publish().channel(ch1).message("hey-%s" % i).sync() assert isinstance(envelope1.result, PNPublishResult) assert envelope1.result.timetoken > 0 envelope2 = pubnub.publish().channel(ch2).message("hey-%s" % i).sync() assert isinstance(envelope2.result, PNPublishResult) assert envelope2.result.timetoken > 0 while True: time.sleep(1) if len(pubnub.history().channel(ch1).count(COUNT).sync().result.messages) >= 100 and \ len(pubnub.history().channel(ch2).count(COUNT).sync().result.messages) >= 100: break envelope = pubnub.fetch_messages().channels([ch1, ch2]).sync() assert isinstance(envelope.result, PNFetchMessagesResult) assert len(envelope.result.channels[ch1]) == 25 assert len(envelope.result.channels[ch2]) == 25
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()
def setUp(self): self.pubnub = MagicMock( spec=PubNub, config=pnconf_copy(), sdk_name=sdk_name ) self.pubnub.config.uuid = "UUID_WhereNowTest" self.where_now = WhereNow(self.pubnub)
async def test_publish_with_meta(event_loop): pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop) await assert_success_await( pubnub.publish().channel(ch).message("hey").meta({ 'a': 2, 'b': 'qwer' })) await pubnub.stop()
async def test_publish_object_via_get(event_loop): pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop) await asyncio.ensure_future( assert_success_publish_get(pubnub, { "name": "Alex", "online": True })) await pubnub.stop()
def setUp(self): self.pubnub = MagicMock(spec=PubNub, config=pnconf_copy(), sdk_name=sdk_name, _get_token=lambda: None) self.pubnub.uuid = "UUID_HeartbeatUnitTest" self.hb = Heartbeat(self.pubnub) self.pubnub._telemetry_manager = TelemetryManager() self.pubnub.config.set_presence_timeout(20)
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()
def setUp(self): self.pubnub = MagicMock( spec=PubNub, config=pnconf_copy(), sdk_name=sdk_name ) self.pubnub.uuid = "UUID_HeartbeatUnitTest" self.hb = Heartbeat(self.pubnub) self.pubnub.config.set_presence_timeout(20)
def test_publish_string_get(self): pnconf = pnconf_copy() pnconf.ssl = True try: env = PubNub(pnconf).publish().channel("ch1").message("hi").sync() assert isinstance(env.result, PNPublishResult) assert env.result.timetoken > 1 except PubNubException as e: self.fail(e)
def test_single_channel(): config = pnconf_copy() pn = PubNub(config) chan = 'unique_sync' envelope = pn.fire().channel(chan).message('bla').sync() assert (isinstance(envelope, Envelope)) assert not envelope.status.is_error() assert isinstance(envelope.result, PNFireResult) assert isinstance(envelope.status, PNStatus)
def test_get_state_passes_user_defined_uuid(self): ch = "state-native-sync-ch" pubnub = PubNub(pnconf_copy()) pubnub.config.uuid = "test_uuid" client_uuid = "state-native-sync-uuid" envelope = pubnub.get_state().channels(ch).uuid(client_uuid).sync() assert isinstance(envelope.result, PNGetStateResult) assert envelope.result.channels[ch]['name'] == "Alex" assert envelope.result.channels[ch]['count'] == 5
def test_remove_uuid_happy_path(self): config = pnconf_copy() pn = PubNub(config) remove_uid_result = pn.remove_uuid_metadata() \ .uuid(TestObjectsV2UUID._some_uuid) \ .sync() assert isinstance(remove_uid_result, Envelope) assert isinstance(remove_uid_result.result, PNRemoveUUIDMetadataResult) assert isinstance(remove_uid_result.status, PNStatus)
async def test_single_channel(event_loop): config = pnconf_copy() config.enable_subscribe = False pn = PubNubAsyncio(config, custom_event_loop=event_loop) chan = 'unique_sync' envelope = await pn.fire().channel(chan).message('bla').future() assert(isinstance(envelope, AsyncioEnvelope)) assert not envelope.status.is_error() assert isinstance(envelope.result, PNFireResult) assert isinstance(envelope.status, PNStatus) await pn.stop()
def test_add_remove_multiple_channels(self): ch1 = "channel-groups-unit-ch1" ch2 = "channel-groups-unit-ch2" gr = "channel-groups-unit-cg" pubnub = PubNub(pnconf_copy()) # add pubnub.add_channel_to_channel_group() \ .channels([ch1, ch2]) \ .channel_group(gr) \ .pn_async(self.callback) self.event.wait() assert not self.status.is_error() assert isinstance(self.response, PNChannelGroupsAddChannelResult) self.event.clear() time.sleep(1) # list pubnub.list_channels_in_channel_group() \ .channel_group(gr) \ .pn_async(self.callback) self.event.wait() assert isinstance(self.response, PNChannelGroupsListResult) assert len(self.response.channels) == 2 assert ch1 in self.response.channels assert ch2 in self.response.channels self.event.clear() # remove pubnub.remove_channel_from_channel_group() \ .channels([ch1, ch2]) \ .channel_group(gr) \ .pn_async(self.callback) self.event.wait() assert isinstance(self.response, PNChannelGroupsRemoveChannelResult) self.event.clear() time.sleep(1) # list pubnub.list_channels_in_channel_group() \ .channel_group(gr) \ .pn_async(self.callback) self.event.wait() assert isinstance(self.response, PNChannelGroupsListResult) assert len(self.response.channels) == 0 self.event.clear()
def test_add_remove_multiple_channels(self): ch1 = "channel-groups-unit-ch1" ch2 = "channel-groups-unit-ch2" gr = "channel-groups-unit-cg" pubnub = PubNub(pnconf_copy()) # add pubnub.add_channel_to_channel_group() \ .channels([ch1, ch2]) \ .channel_group(gr) \ .async(self.callback) self.event.wait() assert not self.status.is_error() assert isinstance(self.response, PNChannelGroupsAddChannelResult) self.event.clear() time.sleep(1) # list pubnub.list_channels_in_channel_group() \ .channel_group(gr) \ .async(self.callback) self.event.wait() assert isinstance(self.response, PNChannelGroupsListResult) assert len(self.response.channels) == 2 assert ch1 in self.response.channels assert ch2 in self.response.channels self.event.clear() # remove pubnub.remove_channel_from_channel_group() \ .channels([ch1, ch2]) \ .channel_group(gr) \ .async(self.callback) self.event.wait() assert isinstance(self.response, PNChannelGroupsRemoveChannelResult) self.event.clear() time.sleep(1) # list pubnub.list_channels_in_channel_group() \ .channel_group(gr) \ .async(self.callback) self.event.wait() assert isinstance(self.response, PNChannelGroupsListResult) assert len(self.response.channels) == 0 self.event.clear()
def test_publish_string_get(self): pnconf = pnconf_copy() pnconf.ssl = True try: env = PubNub(pnconf).publish() \ .channel("ch1") \ .message("hi") \ .sync() assert isinstance(env.result, PNPublishResult) assert env.result.timetoken > 1 except PubNubException as e: self.fail(e)
def test_single_channel(self): ch = "channel-groups-unit-ch" gr = "channel-groups-unit-cg" pubnub = PubNub(pnconf_copy()) # add pubnub.add_channel_to_channel_group() \ .channels(ch) \ .channel_group(gr) \ .async(self.callback) self.event.wait() assert not self.status.is_error() assert isinstance(self.response, PNChannelGroupsAddChannelResult) self.event.clear() time.sleep(1) # list pubnub.list_channels_in_channel_group() \ .channel_group(gr) \ .async(self.callback) self.event.wait() assert isinstance(self.response, PNChannelGroupsListResult) assert len(self.response.channels) == 1 assert self.response.channels[0] == ch self.event.clear() # remove pubnub.remove_channel_from_channel_group() \ .channels(ch) \ .channel_group(gr) \ .async(self.callback) self.event.wait() assert isinstance(self.response, PNChannelGroupsRemoveChannelResult) self.event.clear() time.sleep(1) # list pubnub.list_channels_in_channel_group() \ .channel_group(gr) \ .async(self.callback) self.event.wait() assert isinstance(self.response, PNChannelGroupsListResult) assert len(self.response.channels) == 0 self.event.clear()
def test_add_remove_multiple_channels(self): ch1 = "channel-groups-unit-ch1" ch2 = "channel-groups-unit-ch2" gr = "channel-groups-unit-cg" pubnub = PubNub(pnconf_copy()) # cleanup envelope = pubnub.remove_channel_group() \ .channel_group(gr) \ .sync() assert isinstance(envelope.result, PNChannelGroupsRemoveGroupResult) # add envelope = pubnub.add_channel_to_channel_group() \ .channels([ch1, ch2]) \ .channel_group(gr) \ .sync() assert isinstance(envelope.result, PNChannelGroupsAddChannelResult) time.sleep(1) # list envelope = pubnub.list_channels_in_channel_group() \ .channel_group(gr) \ .sync() assert isinstance(envelope.result, PNChannelGroupsListResult) assert len(envelope.result.channels) == 2 assert ch1 in envelope.result.channels assert ch2 in envelope.result.channels # remove envelope = pubnub.remove_channel_from_channel_group() \ .channels([ch1, ch2]) \ .channel_group(gr) \ .sync() assert isinstance(envelope.result, PNChannelGroupsRemoveChannelResult) time.sleep(1) # list envelope = pubnub.list_channels_in_channel_group() \ .channel_group(gr) \ .sync() assert isinstance(envelope.result, PNChannelGroupsListResult) assert len(envelope.result.channels) == 0
def test_single_channel(self): ch = "channel-groups-unit-ch" gr = "channel-groups-unit-cg" pubnub = PubNub(pnconf_copy()) # add pubnub.add_channel_to_channel_group() \ .channels(ch) \ .channel_group(gr) \ .pn_async(self.callback) self.event.wait() assert not self.status.is_error() assert isinstance(self.response, PNChannelGroupsAddChannelResult) self.event.clear() time.sleep(1) # list pubnub.list_channels_in_channel_group() \ .channel_group(gr) \ .pn_async(self.callback) self.event.wait() assert isinstance(self.response, PNChannelGroupsListResult) assert len(self.response.channels) == 1 assert self.response.channels[0] == ch self.event.clear() # remove pubnub.remove_channel_from_channel_group() \ .channels(ch) \ .channel_group(gr) \ .pn_async(self.callback) self.event.wait() assert isinstance(self.response, PNChannelGroupsRemoveChannelResult) self.event.clear() time.sleep(1) # list pubnub.list_channels_in_channel_group() \ .channel_group(gr) \ .pn_async(self.callback) self.event.wait() assert isinstance(self.response, PNChannelGroupsListResult) assert len(self.response.channels) == 0 self.event.clear()
def test_single_channel(self): ch = "channel-groups-native-ch" gr = "channel-groups-native-cg" pubnub = PubNub(pnconf_copy()) # cleanup envelope = pubnub.remove_channel_group() \ .channel_group(gr) \ .sync() assert isinstance(envelope.result, PNChannelGroupsRemoveGroupResult) # add envelope = pubnub.add_channel_to_channel_group() \ .channels(ch) \ .channel_group(gr) \ .sync() assert isinstance(envelope.result, PNChannelGroupsAddChannelResult) time.sleep(2) # list envelope = pubnub.list_channels_in_channel_group() \ .channel_group(gr) \ .sync() assert isinstance(envelope.result, PNChannelGroupsListResult) assert len(envelope.result.channels) == 1 assert envelope.result.channels[0] == ch # remove envelope = pubnub.remove_channel_from_channel_group() \ .channels(ch) \ .channel_group(gr) \ .sync() assert isinstance(envelope.result, PNChannelGroupsRemoveChannelResult) time.sleep(2) # list envelope = pubnub.list_channels_in_channel_group() \ .channel_group(gr) \ .sync() assert isinstance(envelope.result, PNChannelGroupsListResult) assert len(envelope.result.channels) == 0
def test_single_channelx(event_loop): pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop) ch = "test-state-asyncio-ch" pubnub.config.uuid = "test-state-asyncio-uuid" state = {"name": "Alex", "count": 5} env = yield from pubnub.set_state().channels(ch).state(state).future() assert env.result.state["name"] == "Alex" assert env.result.state["count"] == 5 env = yield from pubnub.get_state().channels(ch).future() assert env.result.channels[ch]["name"] == "Alex" assert env.result.channels[ch]["count"] == 5 pubnub.stop()
def test_fetch_messages_actions_include_message_type(self): ch = "fetch-messages-types" pubnub = PubNub(pnconf_copy()) pubnub.config.uuid = "fetch-message-types" pubnub.publish().channel(ch).message("hey-type").sync() time.sleep(1) envelope = pubnub.fetch_messages().channels( ch).include_message_actions(True).include_message_type( True).sync() assert envelope is not None assert isinstance(envelope.result, PNFetchMessagesResult) history = envelope.result.channels[ch] assert len(history) == 1 assert history[0].message_type == '1'
def test_single_channel(self): ch = "state-native-sync-ch" pubnub = PubNub(pnconf_copy()) pubnub.config.uuid = "state-native-sync-uuid" state = {"name": "Alex", "count": 5} envelope = pubnub.set_state().channels(ch).state(state).sync() assert isinstance(envelope.result, PNSetStateResult) assert envelope.result.state['name'] == "Alex" assert envelope.result.state['count'] == 5 envelope = pubnub.get_state().channels(ch).sync() assert isinstance(envelope.result, PNGetStateResult) assert envelope.result.channels[ch]['name'] == "Alex" assert envelope.result.channels[ch]['count'] == 5
def test_invalid_key(self): self.invalid_key_message = "" pn_fake_key_config = pnconf_copy() pn_fake_key_config.publish_key = "fake" PubNub(pn_fake_key_config).publish() \ .channel("ch1") \ .message("hey") \ .pn_async(self.callback) self.event.wait() assert self.status.is_error() assert self.status.category is PNStatusCategory.PNBadRequestCategory assert self.status.original_response[0] == 0 assert self.status.original_response[1] == 'Invalid Key' assert "HTTP Client Error (400):" in str(self.status.error_data.exception) assert "Invalid Key" in str(self.status.error_data.exception)
def test_get_uuid_happy_path(self): config = pnconf_copy() pn = PubNub(config) get_uuid_result = pn.get_uuid_metadata() \ .include_custom(True) \ .uuid(TestObjectsV2UUID._some_uuid) \ .sync() assert isinstance(get_uuid_result, Envelope) assert isinstance(get_uuid_result.result, PNGetUUIDMetadataResult) assert isinstance(get_uuid_result.status, PNStatus) data = get_uuid_result.result.data assert data['id'] == TestObjectsV2UUID._some_uuid assert data['name'] == TestObjectsV2UUID._some_name assert data['externalId'] == TestObjectsV2UUID._some_external_id assert data['profileUrl'] == TestObjectsV2UUID._some_profile_url assert data['email'] == TestObjectsV2UUID._some_email assert data['custom'] == TestObjectsV2UUID._some_custom
def test_get_all_uuid_happy_path(self): config = pnconf_copy() pn = PubNub(config) get_all_uuid_result = pn.get_all_uuid_metadata() \ .include_custom(True) \ .limit(10) \ .include_total_count(True) \ .sort(PNSortKey.asc(PNSortKeyValue.ID), PNSortKey.desc(PNSortKeyValue.UPDATED)) \ .page(None) \ .sync() assert isinstance(get_all_uuid_result, Envelope) assert isinstance(get_all_uuid_result.result, PNGetAllUUIDMetadataResult) assert isinstance(get_all_uuid_result.status, PNStatus) data = get_all_uuid_result.result.data assert isinstance(data, list) assert get_all_uuid_result.result.total_count != 0 assert get_all_uuid_result.result.next is not None assert get_all_uuid_result.result.prev is None
def test_fetch_messages_actions_include_uuid(self): ch = "fetch-messages-actions-uuid" pubnub = PubNub(pnconf_copy()) uuid1 = "fetch-messages-uuid-1" uuid2 = "fetch-messages-uuid-2" pubnub.config.uuid = uuid1 pubnub.publish().channel(ch).message("hey-uuid-1").sync() pubnub.config.uuid = uuid2 pubnub.publish().channel(ch).message("hey-uuid-2").sync() time.sleep(1) envelope = pubnub.fetch_messages().channels( ch).include_message_actions(True).include_uuid(True).sync() assert envelope is not None assert isinstance(envelope.result, PNFetchMessagesResult) history = envelope.result.channels[ch] assert len(history) == 2 assert history[0].uuid == uuid1 assert history[1].uuid == uuid2
def test_add_remove_single_channel(event_loop, sleeper=asyncio.sleep): pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop) pubnub.config.uuid = 'test-channel-group-asyncio-uuid1' ch = "test-channel-groups-asyncio-ch" gr = "test-channel-groups-asyncio-cg" yield from pubnub.publish().channel(ch).message("hey").future() # add env = yield from pubnub.add_channel_to_channel_group() \ .channels(ch).channel_group(gr).future() assert isinstance(env.result, PNChannelGroupsAddChannelResult) yield from sleeper(1) # list env = yield from pubnub.list_channels_in_channel_group().channel_group(gr).future() assert isinstance(env.result, PNChannelGroupsListResult) assert len(env.result.channels) == 1 assert env.result.channels[0] == ch # remove env = yield from pubnub.remove_channel_from_channel_group() \ .channels(ch).channel_group(gr).future() assert isinstance(env.result, PNChannelGroupsRemoveChannelResult) yield from sleeper(1) # change uuid to let vcr to distinguish list requests pubnub.config.uuid = 'test-channel-group-asyncio-uuid2' # list env = yield from pubnub.list_channels_in_channel_group().channel_group(gr).future() assert isinstance(env.result, PNChannelGroupsListResult) assert len(env.result.channels) == 0 pubnub.stop()
def test_publish_with_meta(event_loop): pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop) yield from assert_success_await(pubnub.publish().channel(ch).message("hey").meta({'a': 2, 'b': 'qwer'})) pubnub.stop()
def setUp(self): super(TestPubNubState, self).setUp() self.pubnub = PubNubTornado(pnconf_copy(), custom_ioloop=self.io_loop)
def test_error_missing_channel(event_loop): pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop) yield from assert_client_side_error(pubnub.publish().channel("").message("hey"), "Channel missing") pubnub.stop()
def test_publish_object_via_post(event_loop): pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop) yield from asyncio.ensure_future(assert_success_publish_post(pubnub, {"name": "Alex", "online": True})) pubnub.stop()
def test_error_missing_message(event_loop): pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop) yield from assert_client_side_error(pubnub.publish().channel(ch).message(None), "Message missing") pubnub.stop()
import logging import pytest import pubnub as pn from pubnub.exceptions import PubNubException from pubnub.models.consumer.pubsub import PNPublishResult from pubnub.pubnub_asyncio import PubNubAsyncio, AsyncioEnvelope, PubNubAsyncioException from tests.helper import pnconf_copy from tests.integrational.vcr_helper import pn_vcr pn.set_stream_logger('pubnub', logging.DEBUG) ch = "asyncio-int-publish" corrupted_keys = pnconf_copy() corrupted_keys.publish_key = "blah" corrupted_keys.subscribe_key = "blah" @pn_vcr.use_cassette('tests/integrational/fixtures/asyncio/invocations/future.yaml', filter_query_parameters=['uuid', 'seqn', 'pnsdk']) @pytest.mark.asyncio def test_publish_future(event_loop): pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop) result = yield from pubnub.publish().message('hey').channel('blah').result() assert isinstance(result, PNPublishResult) pubnub.stop() @pn_vcr.use_cassette('tests/integrational/fixtures/asyncio/invocations/future_raises_pubnub_error.yaml',
def test_publish_do_not_store(event_loop): pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop) yield from assert_success_await(pubnub.publish().channel(ch).message("hey").should_store(False)) pubnub.stop()
def test_publish_future(event_loop): pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop) result = yield from pubnub.publish().message('hey').channel('blah').result() assert isinstance(result, PNPublishResult) pubnub.stop()