mirror of
https://github.com/caronc/apprise.git
synced 2025-08-09 16:35:07 +02:00
Lametric Time/Clock support added (#267)
This commit is contained in:
@ -23,6 +23,7 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
import re
|
||||
import os
|
||||
import six
|
||||
import pytest
|
||||
@ -1247,6 +1248,164 @@ TEST_URLS = (
|
||||
'test_requests_exceptions': True,
|
||||
}),
|
||||
|
||||
##################################
|
||||
# NotifyLametric
|
||||
##################################
|
||||
('lametric://', {
|
||||
# No APIKey or Client ID/Secret specified
|
||||
'instance': TypeError,
|
||||
}),
|
||||
('lametric://:@/', {
|
||||
# No APIKey or Client ID/Secret specified
|
||||
'instance': TypeError,
|
||||
}),
|
||||
('lametric://{}/'.format(UUID4), {
|
||||
# No APIKey or Client ID specified
|
||||
'instance': TypeError,
|
||||
}),
|
||||
('lametric://root:{}@192.168.0.5:8080/'.format(UUID4), {
|
||||
# Everything is okay; this would be picked up in Device Mode
|
||||
# We're using a default port and enforcing a special user
|
||||
'instance': plugins.NotifyLametric,
|
||||
|
||||
# Our expected url(privacy=True) startswith() response:
|
||||
'privacy_url': 'lametric://root:8...2@192.168.0.5/',
|
||||
}),
|
||||
('lametric://{}@192.168.0.4:8000/'.format(UUID4), {
|
||||
# Everything is okay; this would be picked up in Device Mode
|
||||
# Port is enforced
|
||||
'instance': plugins.NotifyLametric,
|
||||
|
||||
# Our expected url(privacy=True) startswith() response:
|
||||
'privacy_url': 'lametric://8...2@192.168.0.4:8000/',
|
||||
}),
|
||||
('lametric://{}@192.168.0.5/'.format(UUID4), {
|
||||
# Everything is okay; this would be picked up in Device Mode
|
||||
'instance': plugins.NotifyLametric,
|
||||
|
||||
# Our expected url(privacy=True) startswith() response:
|
||||
'privacy_url': 'lametric://8...2@192.168.0.5/',
|
||||
}),
|
||||
('lametrics://{}@192.168.0.6/?mode=device'.format(UUID4), {
|
||||
# Everything is okay; Device mode forced
|
||||
'instance': plugins.NotifyLametric,
|
||||
|
||||
# Our expected url(privacy=True) startswith() response:
|
||||
'privacy_url': 'lametrics://8...2@192.168.0.6/',
|
||||
}),
|
||||
('lametric://192.168.2.8/?mode=device&apikey=abc123', {
|
||||
# Everything is okay; Device mode forced
|
||||
'instance': plugins.NotifyLametric,
|
||||
|
||||
# Our expected url(privacy=True) startswith() response:
|
||||
'privacy_url': 'lametric://a...3@192.168.2.8/',
|
||||
}),
|
||||
('lametrics://{}@abcd==/?mode=cloud'.format(UUID4), {
|
||||
# Everything is okay; Cloud mode forced
|
||||
'instance': plugins.NotifyLametric,
|
||||
|
||||
# Our expected url(privacy=True) startswith() response:
|
||||
'privacy_url': 'lametric://8...2@****/',
|
||||
}),
|
||||
('lametric://_/?mode=cloud&oauth_id=abcd&oauth_secret=1234&cycles=3', {
|
||||
# Everything is okay; Cloud mode forced
|
||||
# arguments used on URL path
|
||||
'instance': plugins.NotifyLametric,
|
||||
|
||||
# Our expected url(privacy=True) startswith() response:
|
||||
'privacy_url': 'lametric://a...d@****/',
|
||||
}),
|
||||
('lametrics://{}@abcd==/?mode=cloud&sound=knock&icon_type=info'
|
||||
'&priority=critical'.format(UUID4), {
|
||||
# Cloud mode forced, sound, icon_type, and priority not supported
|
||||
# with cloud mode so warnings are created
|
||||
'instance': plugins.NotifyLametric,
|
||||
|
||||
# Our expected url(privacy=True) startswith() response:
|
||||
'privacy_url': 'lametric://8...2@****/',
|
||||
}),
|
||||
('lametrics://{}@192.168.0.7/?mode=invalid'.format(UUID4), {
|
||||
# Invalid Mode
|
||||
'instance': TypeError,
|
||||
}),
|
||||
('lametrics://{}@192.168.0.6/?sound=alarm1'.format(UUID4), {
|
||||
# Device mode with sound set to alarm1
|
||||
'instance': plugins.NotifyLametric,
|
||||
}),
|
||||
('lametrics://{}@192.168.0.7/?sound=bike'.format(UUID4), {
|
||||
# Device mode with sound set to bicycle using alias
|
||||
'instance': plugins.NotifyLametric,
|
||||
# Bike is an alias,
|
||||
'url_matches': r'sound=bicycle',
|
||||
}),
|
||||
('lametrics://{}@192.168.0.8/?sound=invalid!'.format(UUID4), {
|
||||
# Invalid sounds just produce warnings... object still loads
|
||||
'instance': plugins.NotifyLametric,
|
||||
}),
|
||||
('lametrics://{}@192.168.0.9/?icon_type=alert'.format(UUID4), {
|
||||
# Icon Type Changed
|
||||
'instance': plugins.NotifyLametric,
|
||||
# icon=alert exists somewhere on our generated URL
|
||||
'url_matches': r'icon_type=alert',
|
||||
}),
|
||||
('lametrics://{}@192.168.0.10/?icon_type=invalid'.format(UUID4), {
|
||||
# Invalid icon types just produce warnings... object still loads
|
||||
'instance': plugins.NotifyLametric,
|
||||
}),
|
||||
('lametric://{}@192.168.1.1/?priority=warning'.format(UUID4), {
|
||||
# Priority changed
|
||||
'instance': plugins.NotifyLametric,
|
||||
}),
|
||||
('lametrics://{}@192.168.1.2/?priority=invalid'.format(UUID4), {
|
||||
# Invalid priority just produce warnings... object still loads
|
||||
'instance': plugins.NotifyLametric,
|
||||
}),
|
||||
('lametric://{}@192.168.1.3/?cycles=2'.format(UUID4), {
|
||||
# Cycles changed
|
||||
'instance': plugins.NotifyLametric,
|
||||
}),
|
||||
('lametric://{}@192.168.1.4/?cycles=-1'.format(UUID4), {
|
||||
# Cycles changed (out of range)
|
||||
'instance': plugins.NotifyLametric,
|
||||
}),
|
||||
('lametrics://{}@192.168.1.5/?cycles=invalid'.format(UUID4), {
|
||||
# Invalid priority just produce warnings... object still loads
|
||||
'instance': plugins.NotifyLametric,
|
||||
}),
|
||||
('lametric://{}@{}/'.format(
|
||||
UUID4, 'YWosnkdnoYREsdogfoSDff734kjsfbweo7r434597FYODIoicosdonnreiuhvd'
|
||||
'ciuhouerhohcd8sds89fdRw=='), {
|
||||
# Everything is okay; this would be picked up in Cloud Mode
|
||||
'instance': plugins.NotifyLametric,
|
||||
|
||||
# Our expected url(privacy=True) startswith() response:
|
||||
'privacy_url': 'lametric://8...2@****/',
|
||||
}),
|
||||
('lametric://{}@example.com/'.format(UUID4), {
|
||||
'instance': plugins.NotifyLametric,
|
||||
# force a failure
|
||||
'response': False,
|
||||
'requests_response_code': requests.codes.internal_server_error,
|
||||
|
||||
# Our expected url(privacy=True) startswith() response:
|
||||
'privacy_url': 'lametric://8...2@example.com/',
|
||||
}),
|
||||
('lametrics://{}@example.ca/'.format(UUID4), {
|
||||
'instance': plugins.NotifyLametric,
|
||||
# throw a bizzare code forcing us to fail to look it up
|
||||
'response': False,
|
||||
'requests_response_code': 999,
|
||||
|
||||
# Our expected url(privacy=True) startswith() response:
|
||||
'privacy_url': 'lametrics://8...2@example.ca/',
|
||||
}),
|
||||
('lametrics://{}@example.net/'.format(UUID4), {
|
||||
'instance': plugins.NotifyLametric,
|
||||
# Throws a series of connection and transfer exceptions when this flag
|
||||
# is set and tests that we gracfully handle them
|
||||
'test_requests_exceptions': True,
|
||||
}),
|
||||
|
||||
##################################
|
||||
# NotifyMailgun
|
||||
##################################
|
||||
@ -4447,6 +4606,9 @@ def test_rest_plugins(mock_post, mock_get):
|
||||
# Don't set this if don't need to check it's value
|
||||
privacy_url = meta.get('privacy_url')
|
||||
|
||||
# Our regular expression
|
||||
url_matches = meta.get('url_matches')
|
||||
|
||||
# Test attachments
|
||||
# Don't set this if don't need to check it's value
|
||||
check_attachments = meta.get('check_attachments', True)
|
||||
@ -4544,6 +4706,10 @@ def test_rest_plugins(mock_post, mock_get):
|
||||
# Assess that our privacy url is as expected
|
||||
assert obj.url(privacy=True).startswith(privacy_url)
|
||||
|
||||
if url_matches:
|
||||
# Assess that our URL matches a set regex
|
||||
assert re.search(url_matches, obj.url())
|
||||
|
||||
# Instantiate the exact same object again using the URL from
|
||||
# the one that was already created properly
|
||||
obj_cmp = Apprise.instantiate(obj.url())
|
||||
@ -5061,6 +5227,20 @@ def test_notify_gotify_plugin():
|
||||
plugins.NotifyGotify(token=" ")
|
||||
|
||||
|
||||
def test_notify_lametric_plugin():
|
||||
"""
|
||||
API: NotifyLametric() Extra Checks
|
||||
|
||||
"""
|
||||
# Initializes the plugin with an invalid API Key
|
||||
with pytest.raises(TypeError):
|
||||
plugins.NotifyLametric(apikey=None, mode="device")
|
||||
|
||||
# Initializes the plugin with an invalid Client Secret
|
||||
with pytest.raises(TypeError):
|
||||
plugins.NotifyLametric(client_id='valid', secret=None, mode="cloud")
|
||||
|
||||
|
||||
@mock.patch('requests.post')
|
||||
def test_notify_msg91_plugin(mock_post):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user