Skip to content

Commit

Permalink
Stateless GET Parameter Support (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc authored Jan 27, 2024
1 parent 2b21ab7 commit 97abaa4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
27 changes: 27 additions & 0 deletions apprise_api/api/tests/test_stateless_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,33 @@ def test_notify_default_urls(self, mock_notify):
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://[email protected]',
'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):
"""
Expand Down
21 changes: 21 additions & 0 deletions apprise_api/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,27 @@ def post(self, request):
# 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) \
Expand Down

0 comments on commit 97abaa4

Please sign in to comment.