Stateless GET Parameter Support (#166)

This commit is contained in:
Chris Caron 2024-01-27 14:05:07 -05:00 committed by GitHub
parent 2b21ab71ef
commit 97abaa4f96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 0 deletions

View File

@ -372,6 +372,33 @@ class StatelessNotifyTests(SimpleTestCase):
assert response.status_code == 200
assert mock_notify.call_count == 1
@mock.patch('apprise.Apprise.notify')
def test_notify_with_get_parameters(self, mock_notify):
"""
Test sending a simple notification using JSON with GET
parameters
"""
# Set our return value
mock_notify.return_value = True
# Preare our JSON data
json_data = {
'urls': 'json://user@my.domain.ca',
'body': 'test notifiction',
}
# Send our notification as a JSON object
response = self.client.post(
'/notify/?title=my%20title&format=text&type=info',
data=json.dumps(json_data),
content_type='application/json',
)
# Still supported
assert response.status_code == 200
assert mock_notify.call_count == 1
@mock.patch('apprise.Apprise.notify')
def test_notify_by_loaded_urls_with_json(self, mock_notify):
"""

View File

@ -1039,6 +1039,27 @@ class StatelessNotifyView(View):
# defined
content['urls'] = settings.APPRISE_STATELESS_URLS
#
# Allow 'format' value to be specified as part of the URL
# parameters if not found otherwise defined.
#
if not content.get('format') and 'format' in request.GET:
content['format'] = request.GET['format']
#
# Allow 'type' value to be specified as part of the URL parameters
# if not found otherwise defined.
#
if not content.get('type') and 'type' in request.GET:
content['type'] = request.GET['type']
#
# Allow 'title' value to be specified as part of the URL parameters
# if not found otherwise defined.
#
if not content.get('title') and 'title' in request.GET:
content['title'] = request.GET['title']
# Some basic error checking
if not content.get('body') or \
content.get('type', apprise.NotifyType.INFO) \