From da46d45e44ad3a72b03ea3157a68b43a962289c6 Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Mon, 8 Apr 2024 21:03:13 +0200 Subject: [PATCH] Fix --- pubnub/event_engine/effects.py | 4 ++-- pubnub/event_engine/models/states.py | 9 ++++++++- .../asyncio/test_unsubscribe_status.py | 16 ++++++++-------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/pubnub/event_engine/effects.py b/pubnub/event_engine/effects.py index 8d57f58a..d81fa5ff 100644 --- a/pubnub/event_engine/effects.py +++ b/pubnub/event_engine/effects.py @@ -88,9 +88,9 @@ async def handshake_async(self, channels, groups, stop_event, timetoken: int = 0 request.timetoken(0) response = await request.future() - if isinstance(response, PubNubException): + if isinstance(response, Exception): self.logger.warning(f'Handshake failed: {str(response)}') - handshake_failure = events.HandshakeFailureEvent(str(response), 1, timetoken=timetoken) + handshake_failure = events.HandshakeFailureEvent(response, 1, timetoken=timetoken) self.event_engine.trigger(handshake_failure) elif response.status.error: self.logger.warning(f'Handshake failed: {response.status.error_data.__dict__}') diff --git a/pubnub/event_engine/models/states.py b/pubnub/event_engine/models/states.py index 920166e4..f1438aa3 100644 --- a/pubnub/event_engine/models/states.py +++ b/pubnub/event_engine/models/states.py @@ -247,11 +247,18 @@ def give_up(self, event: events.HandshakeReconnectGiveupEvent, context: PNContex self._context.update(context) self._context.attempt = event.attempt self._context.reason = event.reason + status_invocation = None + + if event.reason.status: + status_invocation = invocations.EmitStatusInvocation(status=event.reason.status.category, + operation=PNOperationType.PNUnsubscribeOperation) + else: + status_invocation = invocations.EmitStatusInvocation(PNStatusCategory.PNDisconnectedCategory) return PNTransition( state=HandshakeFailedState, context=self._context, - invocation=invocations.EmitStatusInvocation(PNStatusCategory.PNDisconnectedCategory) + invocation=status_invocation ) def subscription_restored(self, event: events.SubscriptionRestoredEvent, context: PNContext) -> PNTransition: diff --git a/tests/integrational/asyncio/test_unsubscribe_status.py b/tests/integrational/asyncio/test_unsubscribe_status.py index 1ca0fa86..fe4123c5 100644 --- a/tests/integrational/asyncio/test_unsubscribe_status.py +++ b/tests/integrational/asyncio/test_unsubscribe_status.py @@ -10,7 +10,7 @@ from pubnub.pubnub_asyncio import PubNubAsyncio from tests.helper import pnconf_pam_copy -from tests.integrational.vcr_helper import pn_vcr +# from tests.integrational.vcr_helper import pn_vcr pn.set_stream_logger('pubnub', logging.DEBUG) @@ -47,19 +47,19 @@ def status(self, pubnub, status): self.reconnected_event.set() -@pn_vcr.use_cassette( - 'tests/integrational/fixtures/asyncio/subscription/access_denied_unsubscribe_operation.yaml', - filter_query_parameters=['pnsdk', 'l_cg', 'l_pres'], - match_on=['method', 'scheme', 'host', 'port', 'string_list_in_path', 'string_list_in_query'], -) +# @pn_vcr.use_cassette( +# 'tests/integrational/fixtures/asyncio/subscription/access_denied_unsubscribe_operation.yaml', +# filter_query_parameters=['pnsdk', 'l_cg', 'l_pres'], +# match_on=['method', 'scheme', 'host', 'port', 'string_list_in_path', 'string_list_in_query'], +# ) @pytest.mark.asyncio -async def test_access_denied_unsubscribe_operation(event_loop): +async def test_access_denied_unsubscribe_operation(): channel = "not-permitted-channel" pnconf = pnconf_pam_copy() pnconf.secret_key = None pnconf.enable_subscribe = True - pubnub = PubNubAsyncio(pnconf, custom_event_loop=event_loop) + pubnub = PubNubAsyncio(pnconf) callback = AccessDeniedListener() pubnub.add_listener(callback)