AppriseAsset refactored; added body_format default (#181)

pull/184/head
Chris Caron 2019-11-26 20:11:06 -05:00 committed by GitHub
parent 35a8ffaad6
commit 4bddcadfb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 14 deletions

View File

@ -323,6 +323,10 @@ class Apprise(object):
# bad attachments # bad attachments
return False return False
# Allow Asset default value
body_format = self.asset.body_format \
if body_format is None else body_format
# Iterate over our loaded plugins # Iterate over our loaded plugins
for server in self.find(tag): for server in self.find(tag):
if status is None: if status is None:

View File

@ -86,23 +86,32 @@ class AppriseAsset(object):
'apprise-{TYPE}-{XY}{EXTENSION}', 'apprise-{TYPE}-{XY}{EXTENSION}',
)) ))
def __init__(self, theme='default', image_path_mask=None, # This value can also be set on calls to Apprise.notify(). This allows
image_url_mask=None, default_extension=None): # you to let Apprise upfront the type of data being passed in. This
# must be of type NotifyFormat. Possible values could be:
# - NotifyFormat.TEXT
# - NotifyFormat.MARKDOWN
# - NotifyFormat.HTML
# - None
#
# If no format is specified (hence None), then no special pre-formating
# actions will take place during a notificaton. This has been and always
# will be the default.
body_format = None
def __init__(self, **kwargs):
""" """
Asset Initialization Asset Initialization
""" """
if theme: # Assign default arguments if specified
self.theme = theme for key, value in kwargs.items():
if not hasattr(AppriseAsset, key):
raise AttributeError(
'AppriseAsset init(): '
'An invalid key {} was specified.'.format(key))
if image_path_mask is not None: setattr(self, key, value)
self.image_path_mask = image_path_mask
if image_url_mask is not None:
self.image_url_mask = image_url_mask
if default_extension is not None:
self.default_extension = default_extension
def color(self, notify_type, color_type=None): def color(self, notify_type, color_type=None):
""" """

View File

@ -666,9 +666,13 @@ def test_apprise_asset(tmpdir):
API: AppriseAsset() object API: AppriseAsset() object
""" """
a = AppriseAsset(theme=None) a = AppriseAsset(theme='light')
# Default theme # Default theme
assert a.theme == 'default' assert a.theme == 'light'
# Invalid kw handling
with pytest.raises(AttributeError):
AppriseAsset(invalid_kw='value')
a = AppriseAsset( a = AppriseAsset(
theme='dark', theme='dark',