Skip to content

Commit

Permalink
Added test case to check a synology notice posting
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Aug 7, 2023
1 parent 236e67f commit 0369c0a
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/test_plugin_custom_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,61 @@ def test_plugin_custom_form_edge_cases(mock_get, mock_post):
for k in ('user', 'password', 'port', 'host', 'fullpath', 'path', 'query',
'schema', 'url', 'payload', 'method'):
assert new_results[k] == results[k]


@mock.patch('requests.post')
def test_plugin_custom_form_for_synology(mock_post):
"""
NotifyForm() Edge Cases
"""

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

# Prepare Mock
mock_post.return_value = response

results = NotifyForm.parse_url(
'forms://localhost:8081/webapi/entry.cgi?'
'-api=SYNO.Chat.External&-method=incoming&-version=2&-token=abc123')

assert isinstance(results, dict)
assert results['user'] is None
assert results['password'] is None
assert results['port'] == 8081
assert results['host'] == 'localhost'
assert results['fullpath'] == '/webapi/entry.cgi'
assert results['path'] == '/webapi/'
assert results['query'] == 'entry.cgi'
assert results['schema'] == 'forms'
assert results['url'] == 'forms://localhost:8081/webapi/entry.cgi'
assert isinstance(results['qsd:'], dict) is True
# Header Entries
assert results['qsd-']['api'] == 'SYNO.Chat.External'
assert results['qsd-']['method'] == 'incoming'
assert results['qsd-']['version'] == '2'
assert results['qsd-']['token'] == 'abc123'

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

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] == 'https://localhost:8081/webapi/entry.cgi'

params = details[1]['params']
assert params.get('api') == 'SYNO.Chat.External'
assert params.get('method') == 'incoming'
assert params.get('version') == '2'
assert params.get('token') == 'abc123'

payload = details[1]['data']
assert payload.get('version') == '1.0'
assert payload.get('title') == 'title'
assert payload.get('message') == 'body'
assert payload.get('type') == 'info'

0 comments on commit 0369c0a

Please sign in to comment.