Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:

pip3 install --user --ignore-installed -r requirements-dev.txt
behave --junit tests/acceptance/pam
behave --junit tests/acceptance/encryption/cryptor-module.feature -t=~na=python -k
behave --junit tests/acceptance/encryption/cryptor-module.feature -t=~na=python
behave --junit tests/acceptance/subscribe
- name: Expose acceptance tests reports
uses: actions/upload-artifact@v4
Expand Down
4 changes: 2 additions & 2 deletions pubnub/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ class PNReconnectionPolicy(object):

class PNPushType(object):
APNS = 1
MPNS = 2
GCM = 3
GCM = 3 # Deprecated: Use FCM instead. GCM has been replaced by FCM (Firebase Cloud Messaging)
APNS2 = 4
FCM = 5


class PNResourceType(object):
Expand Down
2 changes: 1 addition & 1 deletion pubnub/event_engine/models/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def reconnect_failure(self, event: events.ReceiveReconnectFailureEvent, context:
return PNTransition(
state=ReceiveReconnectingState,
context=self._context,
invocation=invocations.EmitStatusInvocation(PNStatusCategory.UnexpectedDisconnectCategory,
invocation=invocations.EmitStatusInvocation(PNStatusCategory.PNUnexpectedDisconnectCategory,
operation=PNOperationType.PNSubscribeOperation,
context=self._context)
)
Expand Down
4 changes: 2 additions & 2 deletions pubnub/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ def push_type_to_string(push_type):
return "apns"
elif push_type == PNPushType.GCM:
return "gcm"
elif push_type == PNPushType.MPNS:
return "mpns"
elif push_type == PNPushType.FCM:
return "fcm"
else:
return ""

Expand Down
76 changes: 76 additions & 0 deletions tests/acceptance/pam/steps/then_steps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from behave import then

from pubnub.exceptions import PubNubException


Expand All @@ -19,6 +20,12 @@ def step_impl(context, channel):
assert context.token_resource


@then("token {data_type} permission {permission}")
def step_impl(context, data_type, permission):
assert context.token_resource
assert context.token_resource[permission.lower()]


@then("the token contains the authorized UUID {test_uuid}")
def step_impl(context, test_uuid):
assert context.parsed_token.get("authorized_uuid") == test_uuid.strip('"')
Expand Down Expand Up @@ -80,6 +87,75 @@ def step_impl(context):
context.pam_call_error = json.loads(context.pam_call_result._errormsg)


@then("the error status code is {error_code}")
def step_impl(context, error_code):
assert context.pam_call_error['status'] == int(error_code)


@then("the auth error message is '{error_message}'")
@then("the error message is '{error_message}'")
def step_impl(context, error_message):
if 'message' in context.pam_call_error:
assert context.pam_call_error['message'] == error_message
elif 'error' in context.pam_call_error and 'message' in context.pam_call_error['error']:
assert context.pam_call_error['error']['message'] == error_message
else:
raise AssertionError("Unexpected payload: {}".format(context.pam_call_error))


@then("the error detail message is not empty")
def step_impl(context):
if 'error' in context.pam_call_error and 'details' in context.pam_call_error['error']:
assert len(context.pam_call_error['error']['details']) > 0
assert 'message' in context.pam_call_error['error']['details'][0]
assert len(context.pam_call_error['error']['details'][0]['message']) > 0
else:
raise AssertionError("Unexpected payload: {}".format(context.pam_call_error))


@then("the error detail message is '{details_message}'")
def step_impl(context, details_message):
if 'error' in context.pam_call_error and 'details' in context.pam_call_error['error']:
assert len(context.pam_call_error['error']['details']) > 0
assert 'message' in context.pam_call_error['error']['details'][0]
assert context.pam_call_error['error']['details'][0]['message'] == details_message
else:
raise AssertionError("Unexpected payload: {}".format(context.pam_call_error))


@then("the error detail location is '{details_location}'")
def step_impl(context, details_location):
if 'error' in context.pam_call_error and 'details' in context.pam_call_error['error']:
assert len(context.pam_call_error['error']['details']) > 0
assert 'location' in context.pam_call_error['error']['details'][0]
assert context.pam_call_error['error']['details'][0]['location'] == details_location
else:
raise AssertionError("Unexpected payload: {}".format(context.pam_call_error))


@then("the error detail location type is '{details_location_type}'")
def step_impl(context, details_location_type):
if 'error' in context.pam_call_error and 'details' in context.pam_call_error['error']:
assert len(context.pam_call_error['error']['details']) > 0
assert 'locationType' in context.pam_call_error['error']['details'][0]
assert context.pam_call_error['error']['details'][0]['locationType'] == details_location_type
else:
raise AssertionError("Unexpected payload: {}".format(context.pam_call_error))


@then("the error service is '{error_service}'")
def step_impl(context, error_service):
assert context.pam_call_error['service'] == error_service


@then("the error source is '{error_source}'")
def step_impl(context, error_source):
if 'error' in context.pam_call_error and 'source' in context.pam_call_error['error']:
assert context.pam_call_error['error']['source'] == error_source
else:
raise AssertionError("Unexpected payload: {}".format(context.pam_call_error))


@then("the result is successful")
def step_impl(context):
assert context.publish_result.result.timetoken
4 changes: 2 additions & 2 deletions tests/acceptance/subscribe/steps/then_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def step_impl(ctx: PNContext):
await ctx.pubnub.stop()


@then("I observe the following")
@then("I observe the following:")
@async_run_until_complete
async def step_impl(ctx):
def parse_log_line(line: str):
Expand Down Expand Up @@ -74,7 +74,7 @@ async def step_impl(ctx: PNContext, wait_time: str):
await asyncio.sleep(int(wait_time))


@then(u'I observe the following Events and Invocations of the Presence EE')
@then(u'I observe the following Events and Invocations of the Presence EE:')
@async_run_until_complete
async def step_impl(ctx):
def parse_log_line(line: str):
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/push/test_add_channels_to_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,30 @@ def test_push_add_single_channel(self):
self.assertEqual(self.add_channels._channels, ['ch'])

def test_push_add_multiple_channels(self):
self.add_channels.channels(['ch1', 'ch2']).push_type(pubnub.enums.PNPushType.MPNS).device_id("coolDevice")
self.add_channels.channels(['ch1', 'ch2']).push_type(pubnub.enums.PNPushType.APNS).device_id("coolDevice")

params = (pnconf.subscribe_key, "coolDevice")
self.assertEqual(self.add_channels.build_path(), AddChannelsToPush.ADD_PATH % params)

self.assertEqual(self.add_channels.build_params_callback()({}), {
'pnsdk': sdk_name,
'uuid': self.pubnub.uuid,
'type': 'mpns',
'type': 'apns',
'add': 'ch1,ch2'
})

self.assertEqual(self.add_channels._channels, ['ch1', 'ch2'])

def test_push_add_google(self):
self.add_channels.channels(['ch1', 'ch2', 'ch3']).push_type(pubnub.enums.PNPushType.GCM).device_id("coolDevice")
self.add_channels.channels(['ch1', 'ch2', 'ch3']).push_type(pubnub.enums.PNPushType.FCM).device_id("coolDevice")

params = (pnconf.subscribe_key, "coolDevice")
self.assertEqual(self.add_channels.build_path(), AddChannelsToPush.ADD_PATH % params)

self.assertEqual(self.add_channels.build_params_callback()({}), {
'pnsdk': sdk_name,
'uuid': self.pubnub.uuid,
'type': 'gcm',
'type': 'fcm',
'add': 'ch1,ch2,ch3'
})

Expand Down
13 changes: 0 additions & 13 deletions tests/functional/push/test_list_push_provisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,6 @@ def test_list_channel_group_gcm(self):
'type': 'gcm'
})

def test_list_channel_group_mpns(self):
self.list_push.push_type(PNPushType.MPNS).device_id('coolDevice')

self.assertEqual(self.list_push.build_path(),
ListPushProvisions.LIST_PATH % (
pnconf.subscribe_key, "coolDevice"))

self.assertEqual(self.list_push.build_params_callback()({}), {
'pnsdk': sdk_name,
'uuid': self.pubnub.uuid,
'type': 'mpns'
})

def test_list_channel_group_apns2(self):
self.list_push.push_type(PNPushType.APNS2).device_id('coolDevice')\
.environment(pubnub.enums.PNPushEnvironment.PRODUCTION).topic("testTopic")
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/push/test_remove_channels_from_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ def test_push_remove_single_channel(self):
self.assertEqual(self.remove_channels._channels, ['ch'])

def test_push_remove_multiple_channels(self):
self.remove_channels.channels(['ch1', 'ch2']).push_type(pubnub.enums.PNPushType.MPNS).device_id("coolDevice")
self.remove_channels.channels(['ch1', 'ch2']).push_type(pubnub.enums.PNPushType.APNS).device_id("coolDevice")

params = (pnconf.subscribe_key, "coolDevice")
self.assertEqual(self.remove_channels.build_path(), RemoveChannelsFromPush.REMOVE_PATH % params)

self.assertEqual(self.remove_channels.build_params_callback()({}), {
'pnsdk': sdk_name,
'uuid': self.pubnub.uuid,
'type': 'mpns',
'type': 'apns',
'remove': 'ch1,ch2'
})

self.assertEqual(self.remove_channels._channels, ['ch1', 'ch2'])

def test_push_remove_google(self):
self.remove_channels.channels(['ch1', 'ch2', 'ch3']).push_type(pubnub.enums.PNPushType.GCM)\
self.remove_channels.channels(['ch1', 'ch2', 'ch3']).push_type(pubnub.enums.PNPushType.FCM)\
.device_id("coolDevice")

params = (pnconf.subscribe_key, "coolDevice")
Expand All @@ -60,7 +60,7 @@ def test_push_remove_google(self):
self.assertEqual(self.remove_channels.build_params_callback()({}), {
'pnsdk': sdk_name,
'uuid': self.pubnub.uuid,
'type': 'gcm',
'type': 'fcm',
'remove': 'ch1,ch2,ch3'
})

Expand Down
6 changes: 3 additions & 3 deletions tests/functional/push/test_remove_device_from_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ def test_remove_push_gcm(self):
'type': 'gcm',
})

def test_remove_push_mpns(self):
self.remove_device.push_type(pubnub.enums.PNPushType.MPNS).device_id("coolDevice")
def test_remove_push_fcm(self):
self.remove_device.push_type(pubnub.enums.PNPushType.FCM).device_id("coolDevice")

params = (pnconf.subscribe_key, "coolDevice")
self.assertEqual(self.remove_device.build_path(), RemoveDeviceFromPush.REMOVE_PATH % params)

self.assertEqual(self.remove_device.build_params_callback()({}), {
'pnsdk': sdk_name,
'uuid': self.pubnub.uuid,
'type': 'mpns',
'type': 'fcm',
})

def test_remove_push_apns2(self):
Expand Down
8 changes: 6 additions & 2 deletions tests/integrational/asyncio/test_change_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ async def test_change_uuid():
assert isinstance(envelope.result, PNSignalResult)
assert isinstance(envelope.status, PNStatus)

await pn.stop()


@pn_vcr.use_cassette('tests/integrational/fixtures/asyncio/signal/uuid_no_lock.json',
filter_query_parameters=['seqn', 'pnsdk', 'l_sig'], serializer='pn_json')
Expand All @@ -51,13 +53,15 @@ async def test_change_uuid_no_lock():
assert isinstance(envelope.result, PNSignalResult)
assert isinstance(envelope.status, PNStatus)

await pn.stop()


def test_uuid_validation_at_init(_function_event_loop):
def test_uuid_validation_at_init():
with pytest.raises(AssertionError) as exception:
pnconf = PNConfiguration()
pnconf.publish_key = "demo"
pnconf.subscribe_key = "demo"
PubNubAsyncio(pnconf, custom_event_loop=_function_event_loop)
PubNubAsyncio(pnconf)

assert str(exception.value) == 'UUID missing or invalid type'

Expand Down
Loading