async def test_encrypted_subscribe_publish_unsubscribe(event_loop): pubnub = PubNubAsyncio(pnconf_enc_sub_copy(), custom_event_loop=event_loop) pubnub.config.uuid = 'test-subscribe-asyncio-uuid' with patch("pubnub.crypto.PubNubCryptodome.get_initialization_vector", return_value="knightsofni12345"): callback = VCR599Listener(1) channel = "test-subscribe-asyncio-ch" message = "hey" pubnub.add_listener(callback) pubnub.subscribe().channels(channel).execute() await callback.wait_for_connect() publish_future = asyncio.ensure_future( pubnub.publish().channel(channel).message(message).future()) subscribe_message_future = asyncio.ensure_future( callback.wait_for_message_on(channel)) await asyncio.wait([publish_future, subscribe_message_future]) publish_envelope = publish_future.result() subscribe_envelope = subscribe_message_future.result() assert isinstance(subscribe_envelope, PNMessageResult) assert subscribe_envelope.channel == channel assert subscribe_envelope.subscription is None assert subscribe_envelope.message == message assert subscribe_envelope.timetoken > 0 assert isinstance(publish_envelope, AsyncioEnvelope) assert publish_envelope.result.timetoken > 0 assert publish_envelope.status.original_response[0] == 1 pubnub.unsubscribe().channels(channel).execute() await callback.wait_for_disconnect() await pubnub.stop()
def test_encrypted_subscribe_publish_unsubscribe(event_loop): pubnub = PubNubAsyncio(pnconf_enc_sub_copy(), custom_event_loop=event_loop) pubnub.config.uuid = 'test-subscribe-asyncio-uuid' callback = VCR599Listener(1) channel = "test-subscribe-asyncio-ch" message = "hey" pubnub.add_listener(callback) pubnub.subscribe().channels(channel).execute() yield from callback.wait_for_connect() publish_future = asyncio.ensure_future(pubnub.publish().channel(channel).message(message).future()) subscribe_message_future = asyncio.ensure_future(callback.wait_for_message_on(channel)) yield from asyncio.wait([ publish_future, subscribe_message_future ]) publish_envelope = publish_future.result() subscribe_envelope = subscribe_message_future.result() assert isinstance(subscribe_envelope, PNMessageResult) assert subscribe_envelope.channel == channel assert subscribe_envelope.subscription is None assert subscribe_envelope.message == message assert subscribe_envelope.timetoken > 0 assert isinstance(publish_envelope, AsyncioEnvelope) assert publish_envelope.result.timetoken > 0 assert publish_envelope.status.original_response[0] == 1 pubnub.unsubscribe().channels(channel).execute() yield from callback.wait_for_disconnect() pubnub.stop()
def test_encrypted_subscribe_publish_unsubscribe(event_loop): pubnub = PubNubAsyncio(pnconf_enc_sub_copy(), custom_event_loop=event_loop) pubnub.config.uuid = 'test-subscribe-asyncio-uuid' callback = SubscribeListener() channel = "test-subscribe-asyncio-ch" message = "hey" pubnub.add_listener(callback) pubnub.subscribe().channels(channel).execute() yield from callback.wait_for_connect() publish_future = asyncio.ensure_future(pubnub.publish().channel(channel).message(message).future()) subscribe_message_future = asyncio.ensure_future(callback.wait_for_message_on(channel)) yield from asyncio.wait([ publish_future, subscribe_message_future ]) publish_envelope = publish_future.result() subscribe_envelope = subscribe_message_future.result() assert isinstance(subscribe_envelope, PNMessageResult) assert subscribe_envelope.channel == channel assert subscribe_envelope.subscription is None assert subscribe_envelope.message == message assert subscribe_envelope.timetoken > 0 assert isinstance(publish_envelope, AsyncioEnvelope) assert publish_envelope.result.timetoken > 0 assert publish_envelope.status.original_response[0] == 1 pubnub.unsubscribe().channels(channel).execute() yield from callback.wait_for_disconnect() pubnub.stop()