mirror of
https://github.com/caronc/apprise.git
synced 2025-01-22 05:49:23 +01:00
ascii() lookup added to plugin base
This commit is contained in:
parent
9569fe1c52
commit
e98f65790c
@ -70,6 +70,9 @@ class AppriseAsset:
|
||||
NotifyType.WARNING: '#CACF29',
|
||||
}
|
||||
|
||||
# The default color to return if a mapping isn't found in our table above
|
||||
default_html_color = '#888888'
|
||||
|
||||
# Ascii Notification
|
||||
ascii_notify_map = {
|
||||
NotifyType.INFO: '[i]',
|
||||
@ -78,8 +81,8 @@ class AppriseAsset:
|
||||
NotifyType.WARNING: '[~]',
|
||||
}
|
||||
|
||||
# The default color to return if a mapping isn't found in our table above
|
||||
default_html_color = '#888888'
|
||||
# The default ascii to return if a mapping isn't found in our table above
|
||||
default_ascii_chars = '[?]'
|
||||
|
||||
# The default image extension to use
|
||||
default_extension = '.png'
|
||||
@ -223,9 +226,8 @@ class AppriseAsset:
|
||||
Returns an ascii representation based on passed in notify type
|
||||
|
||||
"""
|
||||
|
||||
# look our response up
|
||||
return self.ascii_notify_map.get(notify_type, self.default_html_color)
|
||||
return self.ascii_notify_map.get(notify_type, self.default_ascii_chars)
|
||||
|
||||
def image_url(self, notify_type, image_size, logo=False, extension=None):
|
||||
"""
|
||||
|
@ -364,6 +364,17 @@ class NotifyBase(URLBase):
|
||||
color_type=color_type,
|
||||
)
|
||||
|
||||
def ascii(self, notify_type):
|
||||
"""
|
||||
Returns the ascii characters associated with the notify_type
|
||||
"""
|
||||
if notify_type not in NOTIFY_TYPES:
|
||||
return None
|
||||
|
||||
return self.asset.ascii(
|
||||
notify_type=notify_type,
|
||||
)
|
||||
|
||||
def notify(self, *args, **kwargs):
|
||||
"""
|
||||
Performs notification
|
||||
|
@ -957,6 +957,18 @@ def test_apprise_asset(tmpdir):
|
||||
# None is the default
|
||||
assert a.color(NotifyType.INFO) == '#3AA3E3'
|
||||
|
||||
# Invalid Type
|
||||
with pytest.raises(ValueError):
|
||||
# The exception we expect since dict is not supported
|
||||
a.color(NotifyType.INFO, dict)
|
||||
|
||||
# Test our ASCII mappings
|
||||
assert a.ascii('invalid') == '[?]'
|
||||
assert a.ascii(NotifyType.INFO) == '[i]'
|
||||
assert a.ascii(NotifyType.SUCCESS) == '[+]'
|
||||
assert a.ascii(NotifyType.WARNING) == '[~]'
|
||||
assert a.ascii(NotifyType.FAILURE) == '[!]'
|
||||
|
||||
# Invalid Type
|
||||
with pytest.raises(ValueError):
|
||||
# The exception we expect since dict is not supported
|
||||
|
@ -154,6 +154,13 @@ def test_notify_base():
|
||||
assert isinstance(
|
||||
nb.color(notify_type=NotifyType.INFO, color_type=tuple), tuple)
|
||||
|
||||
# Ascii Handling
|
||||
assert nb.ascii(notify_type='invalid') is None
|
||||
assert nb.ascii(NotifyType.INFO) == '[i]'
|
||||
assert nb.ascii(NotifyType.SUCCESS) == '[+]'
|
||||
assert nb.ascii(NotifyType.WARNING) == '[~]'
|
||||
assert nb.ascii(NotifyType.FAILURE) == '[!]'
|
||||
|
||||
# Create an object
|
||||
nb = NotifyBase()
|
||||
# Force an image size since the default doesn't have one
|
||||
|
Loading…
Reference in New Issue
Block a user