Skip to content

Commit

Permalink
add channel_id to messaging.AndroidNotification (#227)
Browse files Browse the repository at this point in the history
* fix FcmErrorCode error type

* add channel_id to messaging.AndroidNotification

* fix test
  • Loading branch information
chemidy authored and hiranya911 committed Dec 1, 2018
1 parent 3e31716 commit 92652ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Unreleased

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


# v2.13.0

- [added] The `db.Reference` type now provides a `listen()` API for
Expand Down
6 changes: 5 additions & 1 deletion firebase_admin/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,12 @@ class AndroidNotification(object):
title text (optional).
title_loc_args: A list of resource keys that will be used in place of the format specifiers
in ``title_loc_key`` (optional).
channel_id: channel_id of the notification (optional).
"""

def __init__(self, title=None, body=None, icon=None, color=None, sound=None, tag=None,
click_action=None, body_loc_key=None, body_loc_args=None, title_loc_key=None,
title_loc_args=None):
title_loc_args=None, channel_id=None):
self.title = title
self.body = body
self.icon = icon
Expand All @@ -262,6 +263,7 @@ def __init__(self, title=None, body=None, icon=None, color=None, sound=None, tag
self.body_loc_args = body_loc_args
self.title_loc_key = title_loc_key
self.title_loc_args = title_loc_args
self.channel_id = channel_id


class WebpushConfig(object):
Expand Down Expand Up @@ -596,6 +598,8 @@ def encode_android_notification(cls, notification):
'AndroidNotification.title_loc_args', notification.title_loc_args),
'title_loc_key': _Validators.check_string(
'AndroidNotification.title_loc_key', notification.title_loc_key),
'channel_id': _Validators.check_string(
'AndroidNotification.channel_id', notification.channel_id),
}
result = cls.remove_null_values(result)
color = result.get('color')
Expand Down
9 changes: 8 additions & 1 deletion tests/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,20 @@ def test_no_body_loc_key(self):
expected = 'AndroidNotification.body_loc_key is required when specifying body_loc_args.'
assert str(excinfo.value) == expected

@pytest.mark.parametrize('data', NON_STRING_ARGS)
def test_invalid_channek_id(self, data):
notification = messaging.AndroidNotification(channel_id=data)
excinfo = self._check_notification(notification)
assert str(excinfo.value) == 'AndroidNotification.channel_id must be a string.'

def test_android_notification(self):
msg = messaging.Message(
topic='topic',
android=messaging.AndroidConfig(
notification=messaging.AndroidNotification(
title='t', body='b', icon='i', color='#112233', sound='s', tag='t',
click_action='ca', title_loc_key='tlk', body_loc_key='blk',
title_loc_args=['t1', 't2'], body_loc_args=['b1', 'b2']
title_loc_args=['t1', 't2'], body_loc_args=['b1', 'b2'], channel_id='c'
)
)
)
Expand All @@ -361,6 +367,7 @@ def test_android_notification(self):
'body_loc_key': 'blk',
'title_loc_args': ['t1', 't2'],
'body_loc_args': ['b1', 'b2'],
'channel_id' : 'c',
},
},
}
Expand Down

0 comments on commit 92652ff

Please sign in to comment.