mirror of
https://github.com/caronc/apprise.git
synced 2025-08-09 16:35:07 +02:00
Support custom field mappings for JSON, FORM and XML Services (#876)
This commit is contained in:
@ -251,8 +251,8 @@ def test_plugin_custom_xml_edge_cases(mock_get, mock_post):
|
||||
mock_get.return_value = response
|
||||
|
||||
results = NotifyXML.parse_url(
|
||||
'xml://localhost:8080/command?:Message=test&method=GET'
|
||||
'&:Key=value&:,=invalid')
|
||||
'xml://localhost:8080/command?:Message=Body&method=GET'
|
||||
'&:Key=value&:,=invalid&:MessageType=')
|
||||
|
||||
assert isinstance(results, dict)
|
||||
assert results['user'] is None
|
||||
@ -265,13 +265,16 @@ def test_plugin_custom_xml_edge_cases(mock_get, mock_post):
|
||||
assert results['schema'] == 'xml'
|
||||
assert results['url'] == 'xml://localhost:8080/command'
|
||||
assert isinstance(results['qsd:'], dict) is True
|
||||
assert results['qsd:']['Message'] == 'test'
|
||||
assert results['qsd:']['Message'] == 'Body'
|
||||
assert results['qsd:']['Key'] == 'value'
|
||||
assert results['qsd:'][','] == 'invalid'
|
||||
|
||||
instance = NotifyXML(**results)
|
||||
assert isinstance(instance, NotifyXML)
|
||||
|
||||
# XSD URL is disabled due to custom formatting
|
||||
assert instance.xsd_url is None
|
||||
|
||||
response = instance.send(title='title', body='body')
|
||||
assert response is True
|
||||
assert mock_post.call_count == 0
|
||||
@ -290,9 +293,63 @@ def test_plugin_custom_xml_edge_cases(mock_get, mock_post):
|
||||
|
||||
# Test our data set for our key/value pair
|
||||
assert re.search(r'<Version>[1-9]+\.[0-9]+</Version>', details[1]['data'])
|
||||
assert re.search('<MessageType>info</MessageType>', details[1]['data'])
|
||||
assert re.search('<Subject>title</Subject>', details[1]['data'])
|
||||
# Custom entry Message acts as Over-ride and kicks in here
|
||||
assert re.search('<Message>test</Message>', details[1]['data'])
|
||||
|
||||
assert re.search('<Message>test</Message>', details[1]['data']) is None
|
||||
assert re.search('<Message>', details[1]['data']) is None
|
||||
# MessageType was removed from the payload
|
||||
assert re.search('<MessageType>', details[1]['data']) is None
|
||||
# However we can find our mapped Message to the new value Body
|
||||
assert re.search('<Body>body</Body>', details[1]['data'])
|
||||
# Custom entry
|
||||
assert re.search('<Key>value</Key>', details[1]['data'])
|
||||
|
||||
mock_post.reset_mock()
|
||||
mock_get.reset_mock()
|
||||
|
||||
results = NotifyXML.parse_url(
|
||||
'xml://localhost:8081/command?method=POST&:New=Value')
|
||||
|
||||
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'] == '/command'
|
||||
assert results['path'] == '/'
|
||||
assert results['query'] == 'command'
|
||||
assert results['schema'] == 'xml'
|
||||
assert results['url'] == 'xml://localhost:8081/command'
|
||||
assert isinstance(results['qsd:'], dict) is True
|
||||
assert results['qsd:']['New'] == 'Value'
|
||||
|
||||
instance = NotifyXML(**results)
|
||||
assert isinstance(instance, NotifyXML)
|
||||
|
||||
# XSD URL is disabled due to custom formatting
|
||||
assert instance.xsd_url is not None
|
||||
|
||||
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:8081/command'
|
||||
assert instance.url(privacy=False).startswith(
|
||||
'xml://localhost:8081/command?')
|
||||
|
||||
# Generate a new URL based on our last and verify key values are the same
|
||||
new_results = NotifyXML.parse_url(instance.url(safe=False))
|
||||
for k in ('user', 'password', 'port', 'host', 'fullpath', 'path', 'query',
|
||||
'schema', 'url', 'method'):
|
||||
assert new_results[k] == results[k]
|
||||
|
||||
# Test our data set for our key/value pair
|
||||
assert re.search(r'<Version>[1-9]+\.[0-9]+</Version>', details[1]['data'])
|
||||
assert re.search(r'<MessageType>info</MessageType>', details[1]['data'])
|
||||
assert re.search(r'<Subject>title</Subject>', details[1]['data'])
|
||||
# No over-ride
|
||||
assert re.search(r'<Message>body</Message>', details[1]['data'])
|
||||
# since there is no over-ride, an xmlns:xsi is provided
|
||||
assert re.search(r'<Notification xmlns:xsi=', details[1]['data'])
|
||||
|
Reference in New Issue
Block a user