Skip to content

Commit

Permalink
Revert "fix: add to correct config."
Browse files Browse the repository at this point in the history
This reverts commit fb83427.
  • Loading branch information
jonathanedey committed Nov 20, 2023
1 parent 7294ae3 commit 580d293
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions firebase_admin/_messaging_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ def encode_android(cls, android):
'AndroidConfig.restricted_package_name', android.restricted_package_name),
'ttl': cls.encode_ttl(android.ttl),
'fcm_options': cls.encode_android_fcm_options(android.fcm_options),
'direct_boot_ok': _Validators.check_boolean(
'AndroidFCMOptions.direct_boot_ok', android.direct_boot_ok),
}
result = cls.remove_null_values(result)
priority = result.get('priority')
Expand All @@ -225,6 +223,8 @@ def encode_android_fcm_options(cls, fcm_options):
result = {
'analytics_label': _Validators.check_analytics_label(
'AndroidFCMOptions.analytics_label', fcm_options.analytics_label),
'direct_boot_ok': _Validators.check_boolean(
'AndroidFCMOptions.direct_boot_ok', fcm_options.direct_boot_ok)
}
result = cls.remove_null_values(result)
return result
Expand Down
10 changes: 5 additions & 5 deletions firebase_admin/_messaging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,17 @@ 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, direct_boot_ok=None):
data=None, notification=None, fcm_options=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 Expand Up @@ -206,10 +203,13 @@ class AndroidFCMOptions:
Args:
analytics_label: contains additional options for features provided by the FCM Android SDK
(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.
"""

def __init__(self, analytics_label=None):
def __init__(self, analytics_label=None, direct_boot_ok=None):
self.analytics_label = analytics_label
self.direct_boot_ok = direct_boot_ok


class WebpushConfig:
Expand Down
15 changes: 7 additions & 8 deletions tests/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ def test_fcm_options(self):
topic='topic',
fcm_options=messaging.FCMOptions('message-label'),
android=messaging.AndroidConfig(
fcm_options=messaging.AndroidFCMOptions('android-label'),
direct_boot_ok=False),
fcm_options=messaging.AndroidFCMOptions('android-label', False)),
apns=messaging.APNSConfig(fcm_options=
messaging.APNSFCMOptions(
analytics_label='apns-label',
Expand All @@ -261,8 +260,8 @@ def test_fcm_options(self):
{
'topic': 'topic',
'fcm_options': {'analytics_label': 'message-label'},
'android': {'fcm_options': {'analytics_label': 'android-label'},
'direct_boot_ok': False},
'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 Down Expand Up @@ -331,7 +330,8 @@ def test_invalid_analytics_label(self, data):
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)))
topic='topic', android=messaging.AndroidConfig(
fcm_options=messaging.AndroidFCMOptions(direct_boot_ok=data))))


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

0 comments on commit 580d293

Please sign in to comment.