From e98f65790cc94c295ac36fa1838228ca69e32124 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sun, 19 May 2024 15:07:45 -0400 Subject: [PATCH] ascii() lookup added to plugin base --- apprise/asset.py | 10 ++++++---- apprise/plugins/base.py | 11 +++++++++++ test/test_api.py | 12 ++++++++++++ test/test_notify_base.py | 7 +++++++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/apprise/asset.py b/apprise/asset.py index 450303d0..c0fab9c0 100644 --- a/apprise/asset.py +++ b/apprise/asset.py @@ -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): """ diff --git a/apprise/plugins/base.py b/apprise/plugins/base.py index 1abc3410..d18f0af0 100644 --- a/apprise/plugins/base.py +++ b/apprise/plugins/base.py @@ -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 diff --git a/test/test_api.py b/test/test_api.py index e25abfd9..025e5319 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -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 diff --git a/test/test_notify_base.py b/test/test_notify_base.py index c97f6a31..3d909aa0 100644 --- a/test/test_notify_base.py +++ b/test/test_notify_base.py @@ -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