diff --git a/README.md b/README.md index 203cf7c..3550b07 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Take advantage of [Apprise](https://github.com/caronc/apprise) through your network with a user-friendly API. -- Send notifications to more than 95+ services. +- Send notifications to more than 100+ services. - An incredibly lightweight gateway to Apprise. - A production ready micro-service at your disposal. @@ -112,7 +112,7 @@ The following architectures are supported: `amd64`, `arm/v7`, and `arm64`. The f ## Apprise URLs -📣 In order to trigger a notification, you first need to define one or more [Apprise URLs](https://github.com/caronc/apprise/wiki) to support the services you wish to leverage. Apprise supports over 95+ notification services today and is always expanding to add support for more! Visit to see the ever-growing list of the services supported today. +📣 In order to trigger a notification, you first need to define one or more [Apprise URLs](https://github.com/caronc/apprise/wiki) to support the services you wish to leverage. Visit to see the ever-growing list of the services supported today. ## API Details @@ -437,4 +437,3 @@ a.add(config) # Send a test message a.notify('test message') ``` - diff --git a/apprise_api/api/tests/test_notify.py b/apprise_api/api/tests/test_notify.py index cee59ff..3c18740 100644 --- a/apprise_api/api/tests/test_notify.py +++ b/apprise_api/api/tests/test_notify.py @@ -31,6 +31,9 @@ import apprise from inspect import cleandoc +# Grant access to our Notification Manager Singleton +N_MGR = apprise.NotificationManager.NotificationManager() + class NotifyTests(SimpleTestCase): """ @@ -247,7 +250,7 @@ def test_notify_with_tags(self, mock_post): # Disable Throttling to speed testing apprise.plugins.NotifyBase.request_rate_per_sec = 0 # Ensure we're enabled for the purpose of our testing - apprise.common.NOTIFY_SCHEMA_MAP['json'].enabled = True + N_MGR['json'].enabled = True # Prepare our response response = requests.Request() @@ -339,7 +342,7 @@ def test_notify_with_tags_via_apprise(self, mock_post): # Disable Throttling to speed testing apprise.plugins.NotifyBase.request_rate_per_sec = 0 # Ensure we're enabled for the purpose of our testing - apprise.common.NOTIFY_SCHEMA_MAP['json'].enabled = True + N_MGR['json'].enabled = True # Prepare our response response = requests.Request() @@ -441,7 +444,7 @@ def test_advanced_notify_with_tags(self, mock_post): # Disable Throttling to speed testing apprise.plugins.NotifyBase.request_rate_per_sec = 0 # Ensure we're enabled for the purpose of our testing - apprise.common.NOTIFY_SCHEMA_MAP['json'].enabled = True + N_MGR['json'].enabled = True # Prepare our response response = requests.Request() @@ -931,7 +934,7 @@ def test_notify_with_filters(self, mock_send): } # Verify by default email is enabled - assert apprise.common.NOTIFY_SCHEMA_MAP['mailto'].enabled is True + assert N_MGR['mailto'].enabled is True # Send our service with the `mailto://` denied with override_settings(APPRISE_ALLOW_SERVICES=""): @@ -948,11 +951,10 @@ def test_notify_with_filters(self, mock_send): assert mock_send.call_count == 0 # What actually took place behind close doors: - assert \ - apprise.common.NOTIFY_SCHEMA_MAP['mailto'].enabled is False + assert N_MGR['mailto'].enabled is False # Reset our flag (for next test) - apprise.common.NOTIFY_SCHEMA_MAP['mailto'].enabled = True + N_MGR['mailto'].enabled = True # Reset Mock mock_send.reset_mock() @@ -972,8 +974,7 @@ def test_notify_with_filters(self, mock_send): assert mock_send.call_count == 1 # Verify that mailto was never turned off - assert \ - apprise.common.NOTIFY_SCHEMA_MAP['mailto'].enabled is True + assert N_MGR['mailto'].enabled is True # Reset Mock mock_send.reset_mock() @@ -993,8 +994,7 @@ def test_notify_with_filters(self, mock_send): assert mock_send.call_count == 1 # Verify email was never turned off - assert \ - apprise.common.NOTIFY_SCHEMA_MAP['mailto'].enabled is True + assert N_MGR['mailto'].enabled is True # Reset Mock mock_send.reset_mock() @@ -1014,8 +1014,7 @@ def test_notify_with_filters(self, mock_send): assert mock_send.call_count == 1 # Verify email was never turned off - assert \ - apprise.common.NOTIFY_SCHEMA_MAP['mailto'].enabled is True + assert N_MGR['mailto'].enabled is True # Reset Mock mock_send.reset_mock() @@ -1035,12 +1034,10 @@ def test_notify_with_filters(self, mock_send): assert mock_send.call_count == 0 # What actually took place behind close doors: - assert \ - apprise.common.NOTIFY_SCHEMA_MAP['mailto']\ - .enabled is False + assert N_MGR['mailto'].enabled is False # Reset our flag (for next test) - apprise.common.NOTIFY_SCHEMA_MAP['mailto'].enabled = True + N_MGR['mailto'].enabled = True # Reset Mock mock_send.reset_mock() @@ -1060,8 +1057,7 @@ def test_notify_with_filters(self, mock_send): assert mock_send.call_count == 1 # nothing was changed - assert \ - apprise.common.NOTIFY_SCHEMA_MAP['mailto'].enabled is True + assert N_MGR['mailto'].enabled is True @override_settings(APPRISE_RECURSION_MAX=1) @mock.patch('apprise.Apprise.notify') diff --git a/apprise_api/api/tests/test_stateless_notify.py b/apprise_api/api/tests/test_stateless_notify.py index 4872ae9..ff60715 100644 --- a/apprise_api/api/tests/test_stateless_notify.py +++ b/apprise_api/api/tests/test_stateless_notify.py @@ -31,6 +31,9 @@ import json import apprise +# Grant access to our Notification Manager Singleton +N_MGR = apprise.NotificationManager.NotificationManager() + class StatelessNotifyTests(SimpleTestCase): """ @@ -202,7 +205,7 @@ def test_partial_notify(self, mock_notify): """ # Ensure we're enabled for the purpose of our testing - apprise.common.NOTIFY_SCHEMA_MAP['mailto'].enabled = True + N_MGR['mailto'].enabled = True # Set our return value; first we return a true, then we fail # on the second call @@ -488,7 +491,7 @@ def test_notify_with_filters(self, mock_send): ) # Ensure we're enabled for the purpose of our testing - apprise.common.NOTIFY_SCHEMA_MAP['json'].enabled = True + N_MGR['json'].enabled = True # Reset Mock mock_send.reset_mock() @@ -508,11 +511,10 @@ def test_notify_with_filters(self, mock_send): assert mock_send.call_count == 0 # What actually took place behind close doors: - assert \ - apprise.common.NOTIFY_SCHEMA_MAP['json'].enabled is False + assert N_MGR['json'].enabled is False # Reset our flag (for next test) - apprise.common.NOTIFY_SCHEMA_MAP['json'].enabled = True + N_MGR['json'].enabled = True # Reset Mock mock_send.reset_mock() @@ -532,7 +534,7 @@ def test_notify_with_filters(self, mock_send): assert mock_send.call_count == 1 # Verify that json was never turned off - assert apprise.common.NOTIFY_SCHEMA_MAP['json'].enabled is True + assert N_MGR['json'].enabled is True # Reset Mock mock_send.reset_mock() @@ -552,7 +554,7 @@ def test_notify_with_filters(self, mock_send): assert mock_send.call_count == 1 # Verify email was never turned off - assert apprise.common.NOTIFY_SCHEMA_MAP['json'].enabled is True + assert N_MGR['json'].enabled is True # Reset Mock mock_send.reset_mock() @@ -572,7 +574,7 @@ def test_notify_with_filters(self, mock_send): assert mock_send.call_count == 1 # Verify email was never turned off - assert apprise.common.NOTIFY_SCHEMA_MAP['json'].enabled is True + assert N_MGR['json'].enabled is True # Reset Mock mock_send.reset_mock() @@ -592,11 +594,10 @@ def test_notify_with_filters(self, mock_send): assert mock_send.call_count == 0 # What actually took place behind close doors: - assert \ - apprise.common.NOTIFY_SCHEMA_MAP['json'].enabled is False + assert N_MGR['json'].enabled is False # Reset our flag (for next test) - apprise.common.NOTIFY_SCHEMA_MAP['json'].enabled = True + N_MGR['json'].enabled = True # Reset Mock mock_send.reset_mock() @@ -616,4 +617,4 @@ def test_notify_with_filters(self, mock_send): assert mock_send.call_count == 1 # nothing was changed - assert apprise.common.NOTIFY_SCHEMA_MAP['json'].enabled is True + assert N_MGR['json'].enabled is True diff --git a/apprise_api/api/utils.py b/apprise_api/api/utils.py index 8e42215..05b989a 100644 --- a/apprise_api/api/utils.py +++ b/apprise_api/api/utils.py @@ -66,8 +66,14 @@ class AppriseStoreMode(object): AppriseStoreMode.DISABLED, ) +# Access our Attachment Manager Singleton +A_MGR = apprise.AttachmentManager.AttachmentManager() -class Attachment(apprise.attachment.AttachFile): +# Access our Notification Manager Singleton +N_MGR = apprise.NotificationManager.NotificationManager() + + +class Attachment(A_MGR['file']): """ A Light Weight Attachment Object for Auto-cleanup that wraps the Apprise Attachments @@ -79,6 +85,7 @@ def __init__(self, filename, path=None, delete=True): """ self._filename = filename self.delete = delete + self._path = None try: os.makedirs(settings.APPRISE_ATTACH_DIR, exist_ok=True) @@ -121,7 +128,7 @@ def __del__(self): """ De-Construtor is used to tidy up files during garbage collection """ - if self.delete: + if self.delete and self._path: try: os.remove(self._path) except FileNotFoundError: @@ -542,33 +549,7 @@ def apply_global_filters(): for x in re.split(r'[ ,]+', settings.APPRISE_ALLOW_SERVICES) if alphanum_re.match(x)] - for plugin in set(apprise.common.NOTIFY_SCHEMA_MAP.values()): - if entries: - # Get a list of the current schema's associated with - # a given plugin - schemas = set(apprise.plugins.details(plugin) - ['tokens']['schema']['values']) - - # Check what was defined and see if there is a hit - for entry in entries: - if entry in schemas: - # We had a hit; we're done - break - - if entry in schemas: - entries.remove(entry) - # We can keep this plugin enabled and move along to the - # next one... - continue - - # if we reach here, we have to block our plugin - plugin.enabled = False - - for entry in entries: - # Generate some noise for those who have bad configurations - logger.warning( - 'APPRISE_ALLOW_SERVICES plugin %s:// was not found - ' - 'ignoring.', entry) + N_MGR.enable_only(*entries) elif settings.APPRISE_DENY_SERVICES: alphanum_re = re.compile( @@ -578,15 +559,7 @@ def apply_global_filters(): for x in re.split(r'[ ,]+', settings.APPRISE_DENY_SERVICES) if alphanum_re.match(x)] - for name in entries: - try: - # Force plugin to be disabled - apprise.common.NOTIFY_SCHEMA_MAP[name].enabled = False - - except KeyError: - logger.warning( - 'APPRISE_DENY_SERVICES plugin %s:// was not found -' - ' ignoring.', name) + N_MGR.disable(*entries) def gen_unique_config_id(): diff --git a/requirements.txt b/requirements.txt index 5d54950..b3aa21b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ # apprise @ git+https://github.com/caronc/apprise@custom-tag-or-version ## 3. The below grabs our stable version (generally the best choice): -apprise == 1.6.0 +apprise == 1.7.1 ## Apprise API Minimum Requirements django