From 0369c0af3c2224d3e2cc58dd051a6537e90f3cf0 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Mon, 7 Aug 2023 13:50:23 -0400 Subject: [PATCH] Added test case to check a synology notice posting --- test/test_plugin_custom_form.py | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/test/test_plugin_custom_form.py b/test/test_plugin_custom_form.py index 6b594bb87b..3d47d18780 100644 --- a/test/test_plugin_custom_form.py +++ b/test/test_plugin_custom_form.py @@ -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'