8000 add channel_id to messaging.AndroidNotification (#227) · loggi/firebase-admin-python@92652ff · GitHub
[go: up one dir, main page]

Skip to content

Commit 92652ff

Browse files
chemidyhiranya911
authored andcommitted
add channel_id to messaging.AndroidNotification (firebase#227)
* fix FcmErrorCode error type * add channel_id to messaging.AndroidNotification * fix test
1 parent 3e31716 commit 92652ff

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Unreleased
22

3+
- [added] `messaging.AndroidNotification`type now supports channel_id.
34
- [fixed] Fixing error handling in FCM. The SDK now checks the key
45
type.googleapis.com/google.firebase.fcm.v1.FcmError to set error code.
56
- [fixed] Ensuring that `UserRecord.tokens_valid_after_time` always
67
returns an integer, and never returns `None`.
78
- [fixed] Fixing a performance issue in the `db.listen()` API
89
where it was taking a long time to process large RTDB nodes.
910

11+
1012
# v2.13.0
1113

1214
- [added] The `db.Reference` type now provides a `listen()` API for

firebase_admin/messaging.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,12 @@ class AndroidNotification(object):
246246
title text (optional).
247247
title_loc_args: A list of resource keys that will be used in place of the format specifiers
248248
in ``title_loc_key`` (optional).
249+
channel_id: channel_id of the notification (optional).
249250
"""
250251

251252
def __init__(self, title=None, body=None, icon=None, color=None, sound=None, tag=None,
252253
click_action=None, body_loc_key=None, body_loc_args=None, title_loc_key=None,
253-
title_loc_args=None):
254+
title_loc_args=None, channel_id=None):
254255
self.title = title
255256
self.body = body
256257
self.icon = icon
@@ -262,6 +263,7 @@ def __init__(self, title=None, body=None, icon=None, color=None, sound=None, tag
262263
self.body_loc_args = body_loc_args
263264
self.title_loc_key = title_loc_key
264265
self.title_loc_args = title_loc_args
266+
self.channel_id = channel_id
265267

266268

267269
class WebpushConfig(object):
@@ -596,6 +598,8 @@ def encode_android_notification(cls, notification):
596598
'AndroidNotification.title_loc_args', notification.title_loc_args),
597599
'title_loc_key': _Validators.check_string(
598600
'AndroidNotification.title_loc_key', notification.title_loc_key),
601+
'channel_id': _Validators.check_string(
602+
'AndroidNotification.channel_id', notification.channel_id),
599603
}
600604
result = cls.remove_null_values(result)
601605
color = result.get('color')

tests/test_messaging.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,20 @@ def test_no_body_loc_key(self):
335335
expected = 'AndroidNotification.body_loc_key is required when specifying body_loc_args.'
336336
assert str(excinfo.value) == expected
337337

338+
@pytest.mark.parametrize('data', NON_STRING_ARGS)
339+
def test_invalid_channek_id(self, data):
340+
notification = messaging.AndroidNotification(channel_id=data)
341+
excinfo = self._check_notification(notification)
342+
assert str(excinfo.value) == 'AndroidNotification.channel_id must be a string.'
343+
338344
def test_android_notification(self):
339345
msg = messaging.Message(
340346
topic='topic',
341347
android=messaging.AndroidConfig(
342348
notification=messaging.AndroidNotification(
343349
title='t', body='b', icon='i', color='#112233', sound='s', tag='t',
344350
click_action='ca', title_loc_key='tlk', body_loc_key=< 7EF4 span class=pl-s>'blk',
345-
title_loc_args=['t1', 't2'], body_loc_args=['b1', 'b2']
351+
title_loc_args=['t1', 't2'], body_loc_args=['b1', 'b2'], channel_id='c'
346352
)
347353
)
348354
)
@@ -361,6 +367,7 @@ def test_android_notification(self):
361367
'body_loc_key': 'blk',
362368
'title_loc_args': ['t1', 't2'],
363369
'body_loc_args': ['b1', 'b2'],
370+
'channel_id' : 'c',
364371
},
365372
},
366373
}

0 commit comments

Comments
 (0)
0