Skip to content

Commit

Permalink
altered synology payload
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Nov 18, 2023
1 parent b0678dd commit 29255c2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apprise/plugins/NotifySynology.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs):
# Prepare HTTP Headers
headers = {
'User-Agent': self.app_id,
'Content-Type': 'application/json'
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': '*/*',
}

# Apply any/all header over-rides defined
Expand Down Expand Up @@ -262,7 +263,7 @@ def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs):
try:
r = requests.post(
url,
data=dumps(payload),
data=f"payload={dumps(payload)}",
params=params,
headers=headers,
auth=auth,
Expand Down
43 changes: 43 additions & 0 deletions test/test_plugin_synology.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
# POSSIBILITY OF SUCH DAMAGE.

import requests
from unittest import mock

from apprise.plugins.NotifySynology import NotifySynology
from helpers import AppriseURLTester
Expand Down Expand Up @@ -133,3 +134,45 @@ def test_plugin_custom_synology_urls():

# Run our general tests
AppriseURLTester(tests=apprise_url_tests).run_all()


@mock.patch('requests.post')
def test_plugin_synology_edge_cases(mock_post):
"""
NotifySynology() Edge Cases
"""

# Prepare our response
response = requests.Request()
response.status_code = requests.codes.ok

# Prepare Mock
mock_post.return_value = response

# This string also tests that type is set to nothing
results = NotifySynology.parse_url(
'synology://user:pass@localhost:8080/token')

assert isinstance(results, dict)
assert results['user'] == 'user'
assert results['password'] == 'pass'
assert results['port'] == 8080
assert results['host'] == 'localhost'
assert results['fullpath'] == ''
assert results['path'] == '/'
assert results['query'] == 'token'
assert results['schema'] == 'synology'
assert results['url'] == 'synology://user:pass@localhost:8080/token'

instance = NotifySynology(**results)
assert isinstance(instance, NotifySynology)

response = instance.send(title='title', body='body')
assert response is True
assert mock_post.call_count == 1

details = mock_post.call_args_list[0]
assert details[0][0] == 'http://localhost:8080/webapi/entry.cgi'

assert details[1]['data'].startswith('payload=')

0 comments on commit 29255c2

Please sign in to comment.