Skip to content
Merged
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
4 changes: 4 additions & 0 deletions firebase_admin/_messaging_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ def encode_android(cls, android):
'fcm_options': cls.encode_android_fcm_options(android.fcm_options),
'direct_boot_ok': _Validators.check_boolean(
'AndroidConfig.direct_boot_ok', android.direct_boot_ok),
'bandwidth_constrained_ok': _Validators.check_boolean(
'AndroidConfig.bandwidth_constrained_ok', android.bandwidth_constrained_ok),
'restricted_satellite_ok': _Validators.check_boolean(
'AndroidConfig.restricted_satellite_ok', android.restricted_satellite_ok),
}
result = cls.remove_null_values(result)
priority = result.get('priority')
Expand Down
24 changes: 22 additions & 2 deletions firebase_admin/_messaging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# limitations under the License.

"""Types and utilities used by the messaging (FCM) module."""
from __future__ import annotations
import datetime
from typing import Dict, Optional, Union

from firebase_admin import exceptions

Expand Down Expand Up @@ -51,10 +54,25 @@ class AndroidConfig:
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).
bandwidth_constrained_ok: A boolean indicating whether messages will be allowed to be
delivered to the app while the device is on a bandwidth constrained network (optional).
restricted_satellite_ok: A boolean indicating whether messages will be allowed to be
delivered to the app while the device is on a restricted satellite network (optional).
"""

def __init__(self, collapse_key=None, priority=None, ttl=None, restricted_package_name=None,
data=None, notification=None, fcm_options=None, direct_boot_ok=None):
def __init__(
self,
collapse_key: Optional[str] = None,
priority: Optional[str] = None,
ttl: Optional[Union[int, float, datetime.timedelta]] = None,
restricted_package_name: Optional[str] = None,
data: Optional[Dict[str, str]] = None,
notification: Optional[AndroidNotification] = None,
fcm_options: Optional[AndroidFCMOptions] = None,
direct_boot_ok: Optional[bool] = None,
bandwidth_constrained_ok: Optional[bool] = None,
restricted_satellite_ok: Optional[bool] = None
):
self.collapse_key = collapse_key
self.priority = priority
self.ttl = ttl
Expand All @@ -63,6 +81,8 @@ def __init__(self, collapse_key=None, priority=None, ttl=None, restricted_packag
self.notification = notification
self.fcm_options = fcm_options
self.direct_boot_ok = direct_boot_ok
self.bandwidth_constrained_ok = bandwidth_constrained_ok
self.restricted_satellite_ok = restricted_satellite_ok


class AndroidNotification:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,18 @@ def test_invalid_direct_boot_ok(self, data):
check_encoding(messaging.Message(
topic='topic', android=messaging.AndroidConfig(direct_boot_ok=data)))

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

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


def test_android_config(self):
msg = messaging.Message(
Expand All @@ -347,6 +359,8 @@ def test_android_config(self):
data={'k1': 'v1', 'k2': 'v2'},
fcm_options=messaging.AndroidFCMOptions('analytics_label_v1'),
direct_boot_ok=True,
bandwidth_constrained_ok=True,
restricted_satellite_ok=True,
)
)
expected = {
Expand All @@ -364,6 +378,8 @@ def test_android_config(self):
'analytics_label': 'analytics_label_v1',
},
'direct_boot_ok': True,
'bandwidth_constrained_ok': True,
'restricted_satellite_ok': True,
},
}
check_encoding(msg, expected)
Expand Down
Loading