| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 581ef26 commit d62a15e
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -207,6 +207,10 @@ def encode_android(cls, android): | |||
| 207 | 207 | 'fcm_options': cls.encode_android_fcm_options(android.fcm_options), | |
| 208 | 208 | 'direct_boot_ok': _Validators.check_boolean( | |
| 209 | 209 | 'AndroidConfig.direct_boot_ok', android.direct_boot_ok), | |
| 210 | + 'bandwidth_constrained_ok': _Validators.check_boolean( | ||
| 211 | + 'AndroidConfig.bandwidth_constrained_ok', android.bandwidth_constrained_ok), | ||
| 212 | + 'restricted_satellite_ok': _Validators.check_boolean( | ||
| 213 | + 'AndroidConfig.restricted_satellite_ok', android.restricted_satellite_ok), | ||
| 210 | 214 | } | |
| 211 | 215 | result = cls.remove_null_values(result) | |
| 212 | 216 | priority = result.get('priority') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,9 @@ | |||
| 13 | 13 | # limitations under the License. | |
| 14 | 14 | ||
| 15 | 15 | """Types and utilities used by the messaging (FCM) module.""" | |
| 16 | + from __future__ import annotations | ||
| 17 | + import datetime | ||
| 18 | + from typing import Dict, Optional, Union | ||
| 16 | 19 | ||
| 17 | 20 | from firebase_admin import exceptions | |
| 18 | 21 | ||
@@ -51,10 +54,25 @@ class AndroidConfig: | |||
| 51 | 54 | fcm_options: A ``messaging.AndroidFCMOptions`` to be included in the message (optional). | |
| 52 | 55 | direct_boot_ok: A boolean indicating whether messages will be allowed to be delivered to | |
| 53 | 56 | the app while the device is in direct boot mode (optional). | |
| 57 | + bandwidth_constrained_ok: A boolean indicating whether messages will be allowed to be | ||
| 58 | + delivered to the app while the device is on a bandwidth constrained network (optional). | ||
| 59 | + restricted_satellite_ok: A boolean indicating whether messages will be allowed to be | ||
| 60 | + delivered to the app while the device is on a restricted satellite network (optional). | ||
| 54 | 61 | """ | |
| 55 | 62 | ||
| 56 | - def __init__(self, collapse_key=None, priority=None, ttl=None, restricted_package_name=None, | ||
| 57 | - data=None, notification=None, fcm_options=None, direct_boot_ok=None): | ||
| 63 | + def __init__( | ||
| 64 | + self, | ||
| 65 | + collapse_key: Optional[str] = None, | ||
| 66 | + priority: Optional[str] = None, | ||
| 67 | + ttl: Optional[Union[int, float, datetime.timedelta]] = None, | ||
| 68 | + restricted_package_name: Optional[str] = None, | ||
| 69 | + data: Optional[Dict[str, str]] = None, | ||
| 70 | + notification: Optional[AndroidNotification] = None, | ||
| 71 | + fcm_options: Optional[AndroidFCMOptions] = None, | ||
| 72 | + direct_boot_ok: Optional[bool] = None, | ||
| 73 | + bandwidth_constrained_ok: Optional[bool] = None, | ||
| 74 | + restricted_satellite_ok: Optional[bool] = None | ||
| 75 | + ): | ||
| 58 | 76 | self.collapse_key = collapse_key | |
| 59 | 77 | self.priority = priority | |
| 60 | 78 | self.ttl = ttl | |
@@ -63,6 +81,8 @@ def __init__(self, collapse_key=None, priority=None, ttl=None, restricted_packag | |||
| 63 | 81 | self.notification = notification | |
| 64 | 82 | self.fcm_options = fcm_options | |
| 65 | 83 | self.direct_boot_ok = direct_boot_ok | |
| 84 | + self.bandwidth_constrained_ok = bandwidth_constrained_ok | ||
| 85 | + self.restricted_satellite_ok = restricted_satellite_ok | ||
| 66 | 86 | ||
| 67 | 87 | ||
| 68 | 88 | class AndroidNotification: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -335,6 +335,18 @@ def test_invalid_direct_boot_ok(self, data): | |||
| 335 | 335 | check_encoding(messaging.Message( | |
| 336 | 336 | topic='topic', android=messaging.AndroidConfig(direct_boot_ok=data))) | |
| 337 | 337 | ||
| 338 | + @pytest.mark.parametrize('data', NON_BOOL_ARGS) | ||
| 339 | + def test_invalid_bandwidth_constrained_ok(self, data): | ||
| 340 | + with pytest.raises(ValueError): | ||
| 341 | + check_encoding(messaging.Message( | ||
| 342 | + topic='topic', android=messaging.AndroidConfig(bandwidth_constrained_ok=data))) | ||
| 343 | + | ||
| 344 | + @pytest.mark.parametrize('data', NON_BOOL_ARGS) | ||
| 345 | + def test_invalid_restricted_satellite_ok(self, data): | ||
| 346 | + with pytest.raises(ValueError): | ||
| 347 | + check_encoding(messaging.Message( | ||
| 348 | + topic='topic', android=messaging.AndroidConfig(restricted_satellite_ok=data))) | ||
| 349 | + | ||
| 338 | 350 | ||
| 339 | 351 | def test_android_config(self): | |
| 340 | 352 | msg = messaging.Message( | |
@@ -347,6 +359,8 @@ def test_android_config(self): | |||
| 347 | 359 | data={'k1': 'v1', 'k2': 'v2'}, | |
| 348 | 360 | fcm_options=messaging.AndroidFCMOptions('analytics_label_v1'), | |
| 349 | 361 | direct_boot_ok=True, | |
| 362 | + bandwidth_constrained_ok=True, | ||
| 363 | + restricted_satellite_ok=True, | ||
| 350 | 364 | ) | |
| 351 | 365 | ) | |
| 352 | 366 | expected = { | |
@@ -364,6 +378,8 @@ def test_android_config(self): | |||
| 364 | 378 | 'analytics_label': 'analytics_label_v1', | |
| 365 | 379 | }, | |
| 366 | 380 | 'direct_boot_ok': True, | |
| 381 | + 'bandwidth_constrained_ok': True, | ||
| 382 | + 'restricted_satellite_ok': True, | ||
| 367 | 383 | }, | |
| 368 | 384 | } | |
| 369 | 385 | check_encoding(msg, expected) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments