-
Notifications
You must be signed in to change notification settings - Fork 340
feat(fcm): Add 12 new Android Notification Parameters Support #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a965841
c8d86e6
ad0bebe
53aa966
484d1d9
04a9d50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,8 +97,9 @@ class AndroidNotification(object): | |
user clicks it in the panel. When set to ``True``, the notification persists even when | ||
the user clicks it (optional). | ||
event_timestamp: For notifications that inform users about events with an absolute time | ||
hiranya911 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
reference, sets the time that the event in the notification occurred. Notifications | ||
in the panel are sorted by this time (optional). | ||
reference, sets the time that the event in the notification occurred as a | ||
``datetime.datetime`` instance. Notifications in the panel are sorted by this time | ||
(optional). | ||
local_only: Set whether or not this notification is relevant only to the current device. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest sticking with "Sets" |
||
Some notifications can be bridged to other devices for remote display, such as a Wear OS | ||
watch. This hint can be set to recommend this notification not be bridged (optional). | ||
|
@@ -110,13 +111,12 @@ class AndroidNotification(object): | |
has been delivered. Whereas ``AndroidMessagePriority`` is an FCM concept that controls | ||
when the message is delivered (optional). Must be one of ``default``, ``min``, ``low``, | ||
``high``, ``max`` or ``normal``. | ||
vibrate_timings_millis: Set the vibration pattern to use. Pass in an array of seconds | ||
to turn the vibrator on or off (optional). The first value indicates the duration to | ||
wait before turning the vibrator on. The next value indicates the duration to keep the | ||
vibrator on. Subsequent values alternate between duration to turn the vibrator off and | ||
to turn the vibrator on. If ``vibrate_timings_millis`` is set and | ||
``default_vibrate_timings`` is set to ``True``, the default value is used instead of the | ||
user-specified ``vibrate_timings_millis``. | ||
vibrate_timings_millis: Sets the vibration pattern to use. Pass in an array of milliseconds | ||
to turn the vibrator on or off. The first value indicates the duration to wait before | ||
turning the vibrator on. The next value indicates the duration to keep the vibrator on. | ||
Subsequent values alternate between duration to turn the vibrator off and to turn the | ||
vibrator on. If ``vibrate_timings`` is set and ``default_vibrate_timings`` is set to | ||
``True``, the default value is used instead of the user-specified ``vibrate_timings``. | ||
default_vibrate_timings: If set to ``True``, use the Android framework's default vibrate | ||
pattern for the notification (optional). Default values are specified in ``config.xml`` | ||
https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml. | ||
|
@@ -183,14 +183,14 @@ class LightSettings(object): | |
``messaging.AndroidNotification``. | ||
|
||
Args: | ||
color: Set color of the LED in ``#rrggbb`` or ``#rrggbbaa`` format (required). | ||
color: Set color of the LED in ``#rrggbb`` or ``#rrggbbaa`` format. | ||
light_on_duration_millis: Along with ``light_off_duration``, define the blink rate of LED | ||
flashes (required). | ||
flashes. | ||
light_off_duration_millis: Along with ``light_on_duration``, define the blink rate of LED | ||
flashes (required). | ||
flashes. | ||
""" | ||
def __init__(self, color=None, light_on_duration_millis=None, | ||
light_off_duration_millis=None): | ||
def __init__(self, color, light_on_duration_millis, | ||
light_off_duration_millis): | ||
self.color = color | ||
self.light_on_duration_millis = light_on_duration_millis | ||
self.light_off_duration_millis = light_off_duration_millis | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
NON_DICT_ARGS = ['', list(), tuple(), True, False, 1, 0, {1: 'foo'}, {'foo': 1}] | ||
NON_OBJECT_ARGS = [list(), tuple(), dict(), 'foo', 0, 1, True, False] | ||
NON_LIST_ARGS = ['', tuple(), dict(), True, False, 1, 0, [1], ['foo', 1]] | ||
NON_UNUM_ARGS = ['1.23s', list(), tuple(), dict(), -1.23] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: NON_UINT_ARGS? |
||
HTTP_ERROR_CODES = { | ||
400: exceptions.InvalidArgumentError, | ||
403: exceptions.PermissionDeniedError, | ||
|
@@ -292,7 +293,7 @@ def test_invalid_priority(self, data): | |
else: | ||
assert str(excinfo.value) == 'AndroidConfig.priority must be a non-empty string.' | ||
|
||
@pytest.mark.parametrize('data', ['1.23s', list(), tuple(), dict(), -1.23]) | ||
@pytest.mark.parametrize('data', NON_UNUM_ARGS) | ||
def test_invalid_ttl(self, data): | ||
with pytest.raises(ValueError) as excinfo: | ||
check_encoding(messaging.Message( | ||
|
@@ -479,60 +480,51 @@ def test_invalid_channel_id(self, data): | |
excinfo = self._check_notification(notification) | ||
assert str(excinfo.value) == 'AndroidNotification.channel_id must be a string.' | ||
|
||
@pytest.mark.parametrize('data', NON_STRING_ARGS) | ||
def test_invalid_event_timestamp(self, data): | ||
notification = messaging.AndroidNotification(event_timestamp=data) | ||
@pytest.mark.parametrize('timestamp', [100, '', 'foo', {}, [], list(), dict()]) | ||
def test_invalid_event_timestamp(self, timestamp): | ||
notification = messaging.AndroidNotification(event_timestamp=timestamp) | ||
excinfo = self._check_notification(notification) | ||
expected = 'AndroidNotification.event_timestamp must be a datetime.' | ||
assert str(excinfo.value) == expected | ||
|
||
@pytest.mark.parametrize('data', NON_STRING_ARGS + ['', 'topic', 'priority', 'foo']) | ||
def test_invalid_priority(self, data): | ||
notification = messaging.AndroidNotification(priority=data) | ||
@pytest.mark.parametrize('priority', NON_STRING_ARGS + ['foo']) | ||
def test_invalid_priority(self, priority): | ||
notification = messaging.AndroidNotification(priority=priority) | ||
excinfo = self._check_notification(notification) | ||
if isinstance(data, six.string_types): | ||
if not data: | ||
if isinstance(priority, six.string_types): | ||
if not priority: | ||
expected = 'AndroidNotification.priority must be a non-empty string.' | ||
else: | ||
expected = ('AndroidNotification.priority must be "default", "min", "low", "high" ' | ||
'or "max".') | ||
assert str(excinfo.value) == expected | ||
else: | ||
expected = 'AndroidNotification.priority must be a non-empty string.' | ||
assert str(excinfo.value) == expected | ||
assert str(excinfo.value) == expected | ||
|
||
@pytest.mark.parametrize('data', NON_STRING_ARGS + ['', 'topic', 'priority', 'foo']) | ||
def test_invalid_visibility(self, data): | ||
notification = messaging.AndroidNotification(visibility=data) | ||
@pytest.mark.parametrize('visibility', NON_STRING_ARGS + ['', 'topic', 'priority', 'foo']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove topic and priority |
||
def test_invalid_visibility(self, visibility): | ||
notification = messaging.AndroidNotification(visibility=visibility) | ||
excinfo = self._check_notification(notification) | ||
if isinstance(data, six.string_types): | ||
if not data: | ||
if isinstance(visibility, six.string_types): | ||
if not visibility: | ||
expected = 'AndroidNotification.visibility must be a non-empty string.' | ||
else: | ||
expected = ('AndroidNotification.visibility must be "private", "public" or' | ||
' "secret".') | ||
assert str(excinfo.value) == expected | ||
else: | ||
expected = 'AndroidNotification.visibility must be a non-empty string.' | ||
assert str(excinfo.value) == expected | ||
assert str(excinfo.value) == expected | ||
|
||
@pytest.mark.parametrize('data', ['', 1, True, 'msec', ['500', 500], [0, 'abc']]) | ||
def test_invalid_vibrate_timings_millis(self, data): | ||
notification = messaging.AndroidNotification(vibrate_timings_millis=data) | ||
@pytest.mark.parametrize('vibrate_timings', ['', 1, True, 'msec', ['500', 500], [0, 'abc']]) | ||
def test_invalid_vibrate_timings_millis(self, vibrate_timings): | ||
notification = messaging.AndroidNotification(vibrate_timings_millis=vibrate_timings) | ||
excinfo = self._check_notification(notification) | ||
if isinstance(data, list): | ||
if isinstance(vibrate_timings, list): | ||
expected = ('AndroidNotification.vibrate_timings_millis must not contain non-number ' | ||
'values.') | ||
assert str(excinfo.value) == expected | ||
else: | ||
expected = 'AndroidNotification.vibrate_timings_millis must be a list of numbers.' | ||
assert str(excinfo.value) == expected | ||
|
||
@pytest.mark.parametrize('data', ['', 'foo', list(), tuple(), dict()]) | ||
def test_invalid_notification_count(self, data): | ||
notification = messaging.AndroidNotification(notification_count=data) | ||
excinfo = self._check_notification(notification) | ||
assert str(excinfo.value) == 'AndroidNotification.notification_count must be a number.' | ||
assert str(excinfo.value) == expected | ||
|
||
def test_negative_vibrate_timings_millis(self): | ||
notification = messaging.AndroidNotification( | ||
|
@@ -541,6 +533,12 @@ def test_negative_vibrate_timings_millis(self): | |
expected = 'AndroidNotification.vibrate_timings_millis must not be negative.' | ||
assert str(excinfo.value) == expected | ||
|
||
@pytest.mark.parametrize('notification_count', ['', 'foo', list(), tuple(), dict()]) | ||
def test_invalid_notification_count(self, notification_count): | ||
notification = messaging.AndroidNotification(notification_count=notification_count) | ||
excinfo = self._check_notification(notification) | ||
assert str(excinfo.value) == 'AndroidNotification.notification_count must be a number.' | ||
|
||
def test_android_notification(self): | ||
msg = messaging.Message( | ||
topic='topic', | ||
|
@@ -628,27 +626,27 @@ def test_invalid_light_settings(self, data): | |
assert str(excinfo.value) == expected | ||
|
||
def test_no_color(self): | ||
light_settings = messaging.LightSettings(light_on_duration_millis=200, | ||
light_settings = messaging.LightSettings(color=None, light_on_duration_millis=200, | ||
light_off_duration_millis=200) | ||
excinfo = self._check_light_settings(light_settings) | ||
expected = 'LightSettings.color is required.' | ||
assert str(excinfo.value) == expected | ||
|
||
def test_no_light_on_duration_millis(self): | ||
light_settings = messaging.LightSettings(color='#aabbcc', | ||
light_settings = messaging.LightSettings(color='#aabbcc', light_on_duration_millis=None, | ||
light_off_duration_millis=200) | ||
excinfo = self._check_light_settings(light_settings) | ||
expected = 'LightSettings.light_on_duration_millis is required.' | ||
assert str(excinfo.value) == expected | ||
|
||
def test_no_light_off_duration_millis(self): | ||
light_settings = messaging.LightSettings(color='#aabbcc', | ||
light_on_duration_millis=200) | ||
light_settings = messaging.LightSettings(color='#aabbcc', light_on_duration_millis=200, | ||
light_off_duration_millis=None) | ||
excinfo = self._check_light_settings(light_settings) | ||
expected = 'LightSettings.light_off_duration_millis is required.' | ||
assert str(excinfo.value) == expected | ||
|
||
@pytest.mark.parametrize('data', ['1.23s', list(), tuple(), dict(), -1.23]) | ||
@pytest.mark.parametrize('data', NON_UNUM_ARGS) | ||
def test_invalid_light_off_duration_millis(self, data): | ||
light_settings = messaging.LightSettings(color='#aabbcc', | ||
light_on_duration_millis=200, | ||
|
@@ -662,7 +660,7 @@ def test_invalid_light_off_duration_millis(self, data): | |
'duration in milliseconds or ' | ||
'an instance of datetime.timedelta.') | ||
|
||
@pytest.mark.parametrize('data', ['1.23s', list(), tuple(), dict(), -1.23]) | ||
@pytest.mark.parametrize('data', NON_UNUM_ARGS) | ||
def test_invalid_light_on_duration_millis(self, data): | ||
light_settings = messaging.LightSettings(color='#aabbcc', | ||
light_on_duration_millis=data, | ||
|
Uh oh!
There was an error while loading. Please reload this page.