10000 Add subtitle field to ApsAlert (#239) · CyberSys/firebase-admin-python@6840951 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6840951

Browse files
authored
Add subtitle field to ApsAlert (firebase#239)
1 parent 932cf17 commit 6840951

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

firebase_admin/messaging.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ class ApsAlert(object):
424424
Args:
425425
title: Title of the alert (optional). If specified, overrides the title set via
426426
``messaging.Notification``.
427+
subtitle: Subtitle of the alert (optional).
427428
body: Body of the alert (optional). If specified, overrides the body set via
428429
``messaging.Notification``.
429430
loc_key: Key of the body string in the app's string resources to use to localize the
@@ -439,9 +440,10 @@ class ApsAlert(object):
439440
launch_image: Image for the notification action (optional).
440441
"""
441442

442-
def __init__(self, title=None, body=None, loc_key=None, loc_args=None, title_loc_key=None,
443-
title_loc_args=None, action_loc_key=None, launch_image=None):
443+
def __init__(self, title=None, subtitle=None, body=None, loc_key=None, loc_args=None,
444+
title_loc_key=None, title_loc_args=None, action_loc_key=None, launch_image=None):
444445
self.title = title
446+
self.subtitle = subtitle
445447
self.body = body
446448
self.loc_key = loc_key
447449
self.loc_args = loc_args
@@ -765,6 +767,7 @@ def encode_aps_alert(cls, alert):
765767
raise ValueError('Aps.alert must be a string or an instance of ApsAlert class.')
766768
result = {
767769
'title': _Validators.check_string('ApsAlert.title', alert.title),
770+
'subtitle': _Validators.check_string('ApsAlert.subtitle', alert.subtitle),
768771
'body': _Validators.check_string('ApsAlert.body', alert.body),
769772
'title-loc-key': _Validators.check_string(
770773
'ApsAlert.title_loc_key', alert.title_loc_key),

tests/test_messaging.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,13 @@ def test_invalid_title(self, data):
850850
expected = 'ApsAlert.title must be a string.'
851851
assert str(excinfo.value) == expected
852852

853+
@pytest.mark.parametrize('data', NON_STRING_ARGS)
854+
def test_invalid_subtitle(self, data):
855+
alert = messaging.ApsAlert(subtitle=data)
856+
excinfo = self._check_alert(alert)
857+
expected = 'ApsAlert.subtitle must be a string.'
858+
assert str(excinfo.value) == expected
859+
853860
@pytest.mark.parametrize('data', NON_STRING_ARGS)
854861
def test_invalid_body(self, data):
855862
alert = messaging.ApsAlert(body=data)
@@ -927,6 +934,7 @@ def test_aps_alert(self):
927934
aps=messaging.Aps(
928935
alert=messaging.ApsAlert(
929936
title='t',
937+
subtitle='st',
930938
body='b',
931939
title_loc_key='tlk',
932940
title_loc_args=['t1', 't2'],
@@ -946,6 +954,7 @@ def test_aps_alert(self):
946954
'aps': {
947955
'alert': {
948956
'title': 't',
957+
'subtitle': 'st',
949958
'body': 'b',
950959
'title-loc-key': 'tlk',
951960
'title-loc-args': ['t1', 't2'],

0 commit comments

Comments
 (0)
0