|
|
|
@ -224,3 +224,155 @@ def test_plugin_custom_form_attachments(mock_post):
|
|
|
|
|
assert obj.notify(
|
|
|
|
|
body='body', title='title', notify_type=NotifyType.INFO,
|
|
|
|
|
attach=attach) is False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@mock.patch('requests.post')
|
|
|
|
|
@mock.patch('requests.get')
|
|
|
|
|
def test_plugin_custom_form_edge_cases(mock_get, mock_post):
|
|
|
|
|
"""
|
|
|
|
|
NotifyForm() Edge Cases
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
# Disable Throttling to speed testing
|
|
|
|
|
plugins.NotifyBase.request_rate_per_sec = 0
|
|
|
|
|
|
|
|
|
|
# Prepare our response
|
|
|
|
|
response = requests.Request()
|
|
|
|
|
response.status_code = requests.codes.ok
|
|
|
|
|
|
|
|
|
|
# Prepare Mock
|
|
|
|
|
mock_post.return_value = response
|
|
|
|
|
mock_get.return_value = response
|
|
|
|
|
|
|
|
|
|
results = plugins.NotifyForm.parse_url(
|
|
|
|
|
'form://localhost:8080/command?:abcd=test&method=POST')
|
|
|
|
|
|
|
|
|
|
assert isinstance(results, dict)
|
|
|
|
|
assert results['user'] is None
|
|
|
|
|
assert results['password'] is None
|
|
|
|
|
assert results['port'] == 8080
|
|
|
|
|
assert results['host'] == 'localhost'
|
|
|
|
|
assert results['fullpath'] == '/command'
|
|
|
|
|
assert results['path'] == '/'
|
|
|
|
|
assert results['query'] == 'command'
|
|
|
|
|
assert results['schema'] == 'form'
|
|
|
|
|
assert results['url'] == 'form://localhost:8080/command'
|
|
|
|
|
assert isinstance(results['qsd:'], dict) is True
|
|
|
|
|
assert results['qsd:']['abcd'] == 'test'
|
|
|
|
|
|
|
|
|
|
instance = plugins.NotifyForm(**results)
|
|
|
|
|
assert isinstance(instance, plugins.NotifyForm)
|
|
|
|
|
|
|
|
|
|
response = instance.send(title='title', body='body')
|
|
|
|
|
assert response is True
|
|
|
|
|
assert mock_post.call_count == 1
|
|
|
|
|
assert mock_get.call_count == 0
|
|
|
|
|
|
|
|
|
|
details = mock_post.call_args_list[0]
|
|
|
|
|
assert details[0][0] == 'http://localhost:8080/command'
|
|
|
|
|
assert 'abcd' in details[1]['data']
|
|
|
|
|
assert details[1]['data']['abcd'] == 'test'
|
|
|
|
|
assert 'title' in details[1]['data']
|
|
|
|
|
assert details[1]['data']['title'] == 'title'
|
|
|
|
|
assert 'message' in details[1]['data']
|
|
|
|
|
assert details[1]['data']['message'] == 'body'
|
|
|
|
|
|
|
|
|
|
assert instance.url(privacy=False).startswith(
|
|
|
|
|
'form://localhost:8080/command?')
|
|
|
|
|
|
|
|
|
|
# Generate a new URL based on our last and verify key values are the same
|
|
|
|
|
new_results = plugins.NotifyForm.parse_url(instance.url(safe=False))
|
|
|
|
|
for k in ('user', 'password', 'port', 'host', 'fullpath', 'path', 'query',
|
|
|
|
|
'schema', 'url', 'payload', 'method'):
|
|
|
|
|
assert new_results[k] == results[k]
|
|
|
|
|
|
|
|
|
|
# Reset our mock configuration
|
|
|
|
|
mock_post.reset_mock()
|
|
|
|
|
mock_get.reset_mock()
|
|
|
|
|
|
|
|
|
|
results = plugins.NotifyForm.parse_url(
|
|
|
|
|
'form://localhost:8080/command?:message=test&method=POST')
|
|
|
|
|
|
|
|
|
|
assert isinstance(results, dict)
|
|
|
|
|
assert results['user'] is None
|
|
|
|
|
assert results['password'] is None
|
|
|
|
|
assert results['port'] == 8080
|
|
|
|
|
assert results['host'] == 'localhost'
|
|
|
|
|
assert results['fullpath'] == '/command'
|
|
|
|
|
assert results['path'] == '/'
|
|
|
|
|
assert results['query'] == 'command'
|
|
|
|
|
assert results['schema'] == 'form'
|
|
|
|
|
assert results['url'] == 'form://localhost:8080/command'
|
|
|
|
|
assert isinstance(results['qsd:'], dict) is True
|
|
|
|
|
assert results['qsd:']['message'] == 'test'
|
|
|
|
|
|
|
|
|
|
instance = plugins.NotifyForm(**results)
|
|
|
|
|
assert isinstance(instance, plugins.NotifyForm)
|
|
|
|
|
|
|
|
|
|
response = instance.send(title='title', body='body')
|
|
|
|
|
assert response is True
|
|
|
|
|
assert mock_post.call_count == 1
|
|
|
|
|
assert mock_get.call_count == 0
|
|
|
|
|
|
|
|
|
|
details = mock_post.call_args_list[0]
|
|
|
|
|
assert details[0][0] == 'http://localhost:8080/command'
|
|
|
|
|
assert 'title' in details[1]['data']
|
|
|
|
|
assert details[1]['data']['title'] == 'title'
|
|
|
|
|
# 'body' is over-ridden by 'test' passed inline with the URL
|
|
|
|
|
assert 'message' in details[1]['data']
|
|
|
|
|
assert details[1]['data']['message'] == 'test'
|
|
|
|
|
|
|
|
|
|
assert instance.url(privacy=False).startswith(
|
|
|
|
|
'form://localhost:8080/command?')
|
|
|
|
|
|
|
|
|
|
# Generate a new URL based on our last and verify key values are the same
|
|
|
|
|
new_results = plugins.NotifyForm.parse_url(instance.url(safe=False))
|
|
|
|
|
for k in ('user', 'password', 'port', 'host', 'fullpath', 'path', 'query',
|
|
|
|
|
'schema', 'url', 'payload', 'method'):
|
|
|
|
|
assert new_results[k] == results[k]
|
|
|
|
|
|
|
|
|
|
# Reset our mock configuration
|
|
|
|
|
mock_post.reset_mock()
|
|
|
|
|
mock_get.reset_mock()
|
|
|
|
|
|
|
|
|
|
results = plugins.NotifyForm.parse_url(
|
|
|
|
|
'form://localhost:8080/command?:message=test&method=GET')
|
|
|
|
|
|
|
|
|
|
assert isinstance(results, dict)
|
|
|
|
|
assert results['user'] is None
|
|
|
|
|
assert results['password'] is None
|
|
|
|
|
assert results['port'] == 8080
|
|
|
|
|
assert results['host'] == 'localhost'
|
|
|
|
|
assert results['fullpath'] == '/command'
|
|
|
|
|
assert results['path'] == '/'
|
|
|
|
|
assert results['query'] == 'command'
|
|
|
|
|
assert results['schema'] == 'form'
|
|
|
|
|
assert results['url'] == 'form://localhost:8080/command'
|
|
|
|
|
assert isinstance(results['qsd:'], dict) is True
|
|
|
|
|
assert results['qsd:']['message'] == 'test'
|
|
|
|
|
|
|
|
|
|
instance = plugins.NotifyForm(**results)
|
|
|
|
|
assert isinstance(instance, plugins.NotifyForm)
|
|
|
|
|
|
|
|
|
|
response = instance.send(title='title', body='body')
|
|
|
|
|
assert response is True
|
|
|
|
|
assert mock_post.call_count == 0
|
|
|
|
|
assert mock_get.call_count == 1
|
|
|
|
|
|
|
|
|
|
details = mock_get.call_args_list[0]
|
|
|
|
|
assert details[0][0] == 'http://localhost:8080/command'
|
|
|
|
|
|
|
|
|
|
assert 'title' in details[1]['params']
|
|
|
|
|
assert details[1]['params']['title'] == 'title'
|
|
|
|
|
# 'body' is over-ridden by 'test' passed inline with the URL
|
|
|
|
|
assert 'message' in details[1]['params']
|
|
|
|
|
assert details[1]['params']['message'] == 'test'
|
|
|
|
|
|
|
|
|
|
assert instance.url(privacy=False).startswith(
|
|
|
|
|
'form://localhost:8080/command?')
|
|
|
|
|
|
|
|
|
|
# Generate a new URL based on our last and verify key values are the same
|
|
|
|
|
new_results = plugins.NotifyForm.parse_url(instance.url(safe=False))
|
|
|
|
|
for k in ('user', 'password', 'port', 'host', 'fullpath', 'path', 'query',
|
|
|
|
|
'schema', 'url', 'payload', 'method'):
|
|
|
|
|
assert new_results[k] == results[k]
|
|
|
|
|