Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Apprise v1.7.x #159

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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 <https://github.com/caronc/apprise/wiki> 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 <https://github.com/caronc/apprise/wiki> to see the ever-growing list of the services supported today.

## API Details

Expand Down Expand Up @@ -437,4 +437,3 @@ a.add(config)
# Send a test message
a.notify('test message')
```

34 changes: 15 additions & 19 deletions apprise_api/api/tests/test_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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=""):
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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')
Expand Down
25 changes: 13 additions & 12 deletions apprise_api/api/tests/test_stateless_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import json
import apprise

# Grant access to our Notification Manager Singleton
N_MGR = apprise.NotificationManager.NotificationManager()


class StatelessNotifyTests(SimpleTestCase):
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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
49 changes: 11 additions & 38 deletions apprise_api/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand All @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down