Merged
Show file tree
Hide file tree
Changes from all commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Failed to load files.
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,17 +49,20 @@ class AndroidConfig:
strings. When specified, overrides any data fields set via ``Message.data``.
notification: A ``messaging.AndroidNotification`` to be included in the message (optional).
fcm_options: A ``messaging.AndroidFCMOptions`` to be included in the message (optional).
direct_boot_ok: A boolean indicating whether messages will be allowed to be delivered to
the app while the device is in direct boot mode (optional).
"""

def __init__(self, collapse_key=None, priority=None, ttl=None, restricted_package_name=None,
data=None, notification=None, fcm_options=None):
data=None, notification=None, fcm_options=None, direct_boot_ok=None):
self.collapse_key = collapse_key
self.priority = priority
self.ttl = ttl
self.restricted_package_name = restricted_package_name
self.data = data
self.notification = notification
self.fcm_options = fcm_options
self.direct_boot_ok = direct_boot_ok


class AndroidNotification:
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@
NON_OBJECT_ARGS = [list(), tuple(), dict(), 'foo', 0, 1, True, False]
NON_LIST_ARGS = ['', tuple(), dict(), True, False, 1, 0, [1], ['foo', 1]]
NON_UINT_ARGS = ['1.23s', list(), tuple(), dict(), -1.23]
NON_BOOL_ARGS = ['', list(), tuple(), dict(), 1, 0, [1], ['foo', 1], {1: 'foo'}, {'foo': 1}]
HTTP_ERROR_CODES = {
400: exceptions.InvalidArgumentError,
403: exceptions.PermissionDeniedError,
Expand DownExpand Up@@ -249,7 +250,8 @@ def test_fcm_options(self):
topic='topic',
fcm_options=messaging.FCMOptions('message-label'),
android=messaging.AndroidConfig(
fcm_options=messaging.AndroidFCMOptions('android-label')),
fcm_options=messaging.AndroidFCMOptions('android-label'),
direct_boot_ok=False),
apns=messaging.APNSConfig(fcm_options=
messaging.APNSFCMOptions(
analytics_label='apns-label',
Expand All@@ -259,7 +261,8 @@ def test_fcm_options(self):
{
'topic': 'topic',
'fcm_options': {'analytics_label': 'message-label'},
'android': {'fcm_options': {'analytics_label': 'android-label'}},
'android': {'fcm_options': {'analytics_label': 'android-label'},
'direct_boot_ok': False},
'apns': {'fcm_options': {'analytics_label': 'apns-label',
'image': 'https://images.unsplash.com/photo-14944386399'
'46-1ebd1d20bf85?fit=crop&w=900&q=60'}},
Expand DownExpand Up@@ -317,6 +320,20 @@ def test_invalid_data(self, data):
check_encoding(messaging.Message(
topic='topic', android=messaging.AndroidConfig(data=data)))

@pytest.mark.parametrize('data', NON_STRING_ARGS)
def test_invalid_analytics_label(self, data):
with pytest.raises(ValueError):
check_encoding(messaging.Message(
topic='topic', android=messaging.AndroidConfig(
fcm_options=messaging.AndroidFCMOptions(analytics_label=data))))

@pytest.mark.parametrize('data', NON_BOOL_ARGS)
def test_invalid_direct_boot_ok(self, data):
with pytest.raises(ValueError):
check_encoding(messaging.Message(
topic='topic', android=messaging.AndroidConfig(direct_boot_ok=data)))


def test_android_config(self):
msg = messaging.Message(
topic='topic',
Expand All@@ -326,7 +343,8 @@ def test_android_config(self):
priority='high',
ttl=123,
data={'k1': 'v1', 'k2': 'v2'},
fcm_options=messaging.AndroidFCMOptions('analytics_label_v1')
fcm_options=messaging.AndroidFCMOptions('analytics_label_v1'),
direct_boot_ok=True,
)
)
expected = {
Expand All@@ -343,6 +361,7 @@ def test_android_config(self):
'fcm_options': {
'analytics_label': 'analytics_label_v1',
},
'direct_boot_ok': True,
},
}
check_encoding(msg, expected)
Expand Down