Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
seba-aln committed Apr 8, 2024
1 parent 485da9a commit da46d45
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pubnub/event_engine/effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__}')
Expand Down
9 changes: 8 additions & 1 deletion pubnub/event_engine/models/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions tests/integrational/asyncio/test_unsubscribe_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit da46d45

Please sign in to comment.