mirror of
https://github.com/caronc/apprise.git
synced 2025-08-14 02:18:37 +02:00
Resolve ambiguity with apprise.plugins
module namespace
While the namespace is physically made of modules, it has been amended to be the namespace home for the corresponding notifier classes as well. This turned out to confuse both humans and machines on various ends. While it has apparently worked for a while, it croaks on Python 3.11 now, and is not considered to have been a good idea in general.
This commit is contained in:
@ -32,6 +32,9 @@ import socket
|
||||
|
||||
# Disable logging for a cleaner testing output
|
||||
import logging
|
||||
|
||||
from apprise.plugins.NotifySyslog import NotifySyslog
|
||||
|
||||
logging.disable(logging.CRITICAL)
|
||||
|
||||
|
||||
@ -43,9 +46,9 @@ def test_plugin_syslog_by_url(openlog, syslog):
|
||||
|
||||
"""
|
||||
# an invalid URL
|
||||
assert apprise.plugins.NotifySyslog.parse_url(object) is None
|
||||
assert apprise.plugins.NotifySyslog.parse_url(42) is None
|
||||
assert apprise.plugins.NotifySyslog.parse_url(None) is None
|
||||
assert NotifySyslog.parse_url(object) is None
|
||||
assert NotifySyslog.parse_url(42) is None
|
||||
assert NotifySyslog.parse_url(None) is None
|
||||
|
||||
obj = apprise.Apprise.instantiate('syslog://')
|
||||
assert obj.url().startswith('syslog://user') is True
|
||||
@ -55,10 +58,10 @@ def test_plugin_syslog_by_url(openlog, syslog):
|
||||
|
||||
assert isinstance(
|
||||
apprise.Apprise.instantiate(
|
||||
'syslog://:@/'), apprise.plugins.NotifySyslog)
|
||||
'syslog://:@/'), NotifySyslog)
|
||||
|
||||
obj = apprise.Apprise.instantiate('syslog://?logpid=no&logperror=yes')
|
||||
assert isinstance(obj, apprise.plugins.NotifySyslog)
|
||||
assert isinstance(obj, NotifySyslog)
|
||||
assert obj.url().startswith('syslog://user') is True
|
||||
assert re.search(r'logpid=no', obj.url()) is not None
|
||||
assert re.search(r'logperror=yes', obj.url()) is not None
|
||||
@ -72,7 +75,7 @@ def test_plugin_syslog_by_url(openlog, syslog):
|
||||
assert obj.notify("body", notify_type='invalid') is False
|
||||
|
||||
obj = apprise.Apprise.instantiate('syslog://_/?facility=local5')
|
||||
assert isinstance(obj, apprise.plugins.NotifySyslog)
|
||||
assert isinstance(obj, NotifySyslog)
|
||||
assert obj.url().startswith('syslog://local5') is True
|
||||
assert re.search(r'logpid=yes', obj.url()) is not None
|
||||
assert re.search(r'logperror=no', obj.url()) is not None
|
||||
@ -83,7 +86,7 @@ def test_plugin_syslog_by_url(openlog, syslog):
|
||||
|
||||
# j will cause a search to take place and match to daemon
|
||||
obj = apprise.Apprise.instantiate('syslog://_/?facility=d')
|
||||
assert isinstance(obj, apprise.plugins.NotifySyslog)
|
||||
assert isinstance(obj, NotifySyslog)
|
||||
assert obj.url().startswith('syslog://daemon') is True
|
||||
assert re.search(r'logpid=yes', obj.url()) is not None
|
||||
assert re.search(r'logperror=no', obj.url()) is not None
|
||||
@ -91,7 +94,7 @@ def test_plugin_syslog_by_url(openlog, syslog):
|
||||
|
||||
# Facility can also be specified on the url as a hostname
|
||||
obj = apprise.Apprise.instantiate('syslog://kern?logpid=no&logperror=y')
|
||||
assert isinstance(obj, apprise.plugins.NotifySyslog)
|
||||
assert isinstance(obj, NotifySyslog)
|
||||
assert obj.url().startswith('syslog://kern') is True
|
||||
assert re.search(r'logpid=no', obj.url()) is not None
|
||||
assert re.search(r'logperror=yes', obj.url()) is not None
|
||||
@ -99,7 +102,7 @@ def test_plugin_syslog_by_url(openlog, syslog):
|
||||
|
||||
# Facilities specified as an argument always over-ride host
|
||||
obj = apprise.Apprise.instantiate('syslog://kern?facility=d')
|
||||
assert isinstance(obj, apprise.plugins.NotifySyslog)
|
||||
assert isinstance(obj, NotifySyslog)
|
||||
assert obj.url().startswith('syslog://daemon') is True
|
||||
assert re.search(r'syslog://.*mode=local', obj.url())
|
||||
|
||||
@ -113,8 +116,8 @@ def test_plugin_syslog_edge_cases(openlog, syslog):
|
||||
"""
|
||||
|
||||
# Default
|
||||
obj = apprise.plugins.NotifySyslog(facility=None)
|
||||
assert isinstance(obj, apprise.plugins.NotifySyslog)
|
||||
obj = NotifySyslog(facility=None)
|
||||
assert isinstance(obj, NotifySyslog)
|
||||
assert obj.url().startswith('syslog://user') is True
|
||||
assert re.search(r'logpid=yes', obj.url()) is not None
|
||||
assert re.search(r'logperror=no', obj.url()) is not None
|
||||
@ -122,10 +125,10 @@ def test_plugin_syslog_edge_cases(openlog, syslog):
|
||||
|
||||
# Exception should be thrown about the fact no bot token was specified
|
||||
with pytest.raises(TypeError):
|
||||
apprise.plugins.NotifySyslog(facility='invalid')
|
||||
NotifySyslog(facility='invalid')
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
apprise.plugins.NotifySyslog(facility=object)
|
||||
NotifySyslog(facility=object)
|
||||
|
||||
|
||||
@mock.patch('syslog.syslog')
|
||||
@ -152,7 +155,7 @@ def test_plugin_syslog_remote(
|
||||
# localhost does not lookup to any of the facility codes so this
|
||||
# gets interpreted as a host
|
||||
obj = apprise.Apprise.instantiate('syslog://localhost')
|
||||
assert isinstance(obj, apprise.plugins.NotifySyslog)
|
||||
assert isinstance(obj, NotifySyslog)
|
||||
assert obj.url().startswith('syslog://localhost') is True
|
||||
assert re.search(r'syslog://.*mode=remote', obj.url())
|
||||
assert re.search(r'logpid=yes', obj.url()) is not None
|
||||
@ -160,7 +163,7 @@ def test_plugin_syslog_remote(
|
||||
|
||||
# Test with port
|
||||
obj = apprise.Apprise.instantiate('syslog://localhost:518')
|
||||
assert isinstance(obj, apprise.plugins.NotifySyslog)
|
||||
assert isinstance(obj, NotifySyslog)
|
||||
assert obj.url().startswith('syslog://localhost:518') is True
|
||||
assert re.search(r'syslog://.*mode=remote', obj.url())
|
||||
assert re.search(r'logpid=yes', obj.url()) is not None
|
||||
@ -168,7 +171,7 @@ def test_plugin_syslog_remote(
|
||||
|
||||
# Test with default port
|
||||
obj = apprise.Apprise.instantiate('syslog://localhost:514')
|
||||
assert isinstance(obj, apprise.plugins.NotifySyslog)
|
||||
assert isinstance(obj, NotifySyslog)
|
||||
assert obj.url().startswith('syslog://localhost') is True
|
||||
assert re.search(r'syslog://.*mode=remote', obj.url())
|
||||
assert re.search(r'logpid=yes', obj.url()) is not None
|
||||
@ -176,7 +179,7 @@ def test_plugin_syslog_remote(
|
||||
|
||||
# Specify a facility
|
||||
obj = apprise.Apprise.instantiate('syslog://localhost/kern')
|
||||
assert isinstance(obj, apprise.plugins.NotifySyslog)
|
||||
assert isinstance(obj, NotifySyslog)
|
||||
assert obj.url().startswith('syslog://localhost/kern') is True
|
||||
assert re.search(r'syslog://.*mode=remote', obj.url())
|
||||
assert re.search(r'logpid=yes', obj.url()) is not None
|
||||
@ -185,7 +188,7 @@ def test_plugin_syslog_remote(
|
||||
# Specify a facility requiring a lookup and having the port identified
|
||||
# resolves any ambiguity
|
||||
obj = apprise.Apprise.instantiate('syslog://kern:514/d')
|
||||
assert isinstance(obj, apprise.plugins.NotifySyslog)
|
||||
assert isinstance(obj, NotifySyslog)
|
||||
assert obj.url().startswith('syslog://kern/daemon') is True
|
||||
assert re.search(r'syslog://.*mode=remote', obj.url())
|
||||
assert re.search(r'logpid=yes', obj.url()) is not None
|
||||
@ -195,7 +198,7 @@ def test_plugin_syslog_remote(
|
||||
# We can attempt to exclusively set the mode as well without a port
|
||||
# to also remove ambiguity; this falls back to sending as the 'user'
|
||||
obj = apprise.Apprise.instantiate('syslog://kern/d?mode=remote&logpid=no')
|
||||
assert isinstance(obj, apprise.plugins.NotifySyslog)
|
||||
assert isinstance(obj, NotifySyslog)
|
||||
assert obj.url().startswith('syslog://kern/daemon') is True
|
||||
assert re.search(r'syslog://.*mode=remote', obj.url())
|
||||
assert re.search(r'logpid=no', obj.url()) is not None
|
||||
|
Reference in New Issue
Block a user