Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add test cases for messaging.WebpushFcmOptions
  • Loading branch information
robertu7 committed Oct 5, 2018
commit a9dc962896cdf08dad9a7c5e778a00db3ca747a5
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ single-line-if-stmt=no
no-space-check=trailing-comma,dict-separator

# Maximum number of lines in a module
max-module-lines=1000
max-module-lines=1200

# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
# tab).
Expand Down
2 changes: 1 addition & 1 deletion firebase_admin/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class WebpushConfig(object):
data: A dictionary of data fields (optional). All keys and values in the dictionary must be
strings. When specified, overrides any data fields set via ``Message.data``.
notification: A ``messaging.WebpushNotification`` to be included in the message (optional).
fcm_options: A ``messaging.WebpushFcmOptions``. (optional).
fcm_options: A ``messaging.WebpushFcmOptions`` (optional).

.. _Webpush Specification: https://tools.ietf.org/html/rfc8030#section-5
"""
Expand Down
23 changes: 23 additions & 0 deletions tests/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,29 @@ def test_invalid_action_icon(self, data):
assert str(excinfo.value) == 'WebpushNotificationAction.icon must be a string.'


class TestWebpushFcmOptionsEncoder(object):

def _check_fcm_options(self, fcm_options):
with pytest.raises(ValueError) as excinfo:
check_encoding(messaging.Message(
topic='topic', webpush=messaging.WebpushConfig(fcm_options=fcm_options)))
return excinfo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a test case to verify the happy path.

@pytest.mark.parametrize('data', NON_OBJECT_ARGS)
def test_invalid_webpush_fcm_options(self, data):
with pytest.raises(ValueError) as excinfo:
check_encoding(messaging.Message(
topic='topic', webpush=messaging.WebpushConfig(fcm_options=data)))
expected = 'WebpushConfig.fcm_options must be an instance of WebFcmOptions class.'
assert str(excinfo.value) == expected

@pytest.mark.parametrize('data', NON_STRING_ARGS)
def test_invalid_link(self, data):
notification = messaging.WebpushFcmOptions(link=data)
excinfo = self._check_fcm_options(notification)
assert str(excinfo.value) == 'WebpushFcmOptions.link must be a string.'


class TestAPNSConfigEncoder(object):

@pytest.mark.parametrize('data', NON_OBJECT_ARGS)
Expand Down