Skip to content

Commit

Permalink
more test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Jul 6, 2024
1 parent 4e219ba commit 9bd6251
Show file tree
Hide file tree
Showing 23 changed files with 103 additions and 23 deletions.
5 changes: 3 additions & 2 deletions apprise/plugins/dbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,10 @@ def url_identifier(self):
"""
Returns all of the identifiers that make this URL unique from
another simliar one. Targets or end points should never be identified
here.
here. False implies we do not support unique ID generation as there
simply isn't enough details to do so with.
"""
return self.schema
return False

Check warning on line 423 in apprise/plugins/dbus.py

View check run for this annotation

Codecov / codecov/patch

apprise/plugins/dbus.py#L423

Added line #L423 was not covered by tests

@staticmethod
def parse_url(url):
Expand Down
5 changes: 3 additions & 2 deletions apprise/plugins/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,8 +1040,9 @@ def url_identifier(self):
"""
return (
self.secure_protocol if self.secure else self.protocol,
self.user, self.password, self.host, self.port,
self.from_addr,
self.user, self.password, self.host,
self.port if self.port
else SECURE_MODES[self.secure_mode]['default_port'],
)

def __len__(self):
Expand Down
6 changes: 4 additions & 2 deletions apprise/plugins/gnome.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,15 @@ def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs):

return True

@property
def url_identifier(self):
"""
Returns all of the identifiers that make this URL unique from
another simliar one. Targets or end points should never be identified
here.
here. False implies we do not support unique ID generation as there
simply isn't enough details to do so with.
"""
return self.protocol
return False

def url(self, privacy=False, *args, **kwargs):
"""
Expand Down
4 changes: 3 additions & 1 deletion apprise/plugins/growl.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs):

return True

@property
def url_identifier(self):
"""
Returns all of the identifiers that make this URL unique from
Expand All @@ -346,7 +347,8 @@ def url_identifier(self):
"""
return (
self.secure_protocol if self.secure else self.protocol,
self.user, self.password, self.host, self.port,
self.user, self.password, self.host,
self.port if self.port else self.default_port,
)

def url(self, privacy=False, *args, **kwargs):
Expand Down
6 changes: 4 additions & 2 deletions apprise/plugins/macosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,15 @@ def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs):
self.logger.info('Sent MacOSX notification.')
return True

@property
def url_identifier(self):
"""
Returns all of the identifiers that make this URL unique from
another simliar one. Targets or end points should never be identified
here.
here. False implies we do not support unique ID generation as there
simply isn't enough details to do so with.
"""
return self.protocol
return False

def url(self, privacy=False, *args, **kwargs):
"""
Expand Down
5 changes: 4 additions & 1 deletion apprise/plugins/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,10 @@ def url_identifier(self):
"""
return (
self.secure_protocol if self.secure else self.protocol,
self.user, self.password, self.host, self.port,
self.user, self.password, self.host,
self.port if self.port else (
self.mqtt_secure_port if self.secure
else self.mqtt_insecure_port),
self.fullpath.rstrip('/'),
self.client_id,
)
Expand Down
22 changes: 15 additions & 7 deletions apprise/plugins/ntfy.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,16 +665,24 @@ def url_identifier(self):
"""

kwargs = [
self.secure_protocol if self.secure else self.protocol,
self.host,
self.port if self.port else (443 if self.secure else 80),
self.secure_protocol if self.mode == NtfyMode.CLOUD else (
self.secure_protocol if self.secure else self.protocol),
self.host if self.mode == NtfyMode.PRIVATE else '',
443 if self.mode == NtfyMode.CLOUD else (
self.port if self.port else (443 if self.secure else 80)),
]

if self.auth == NtfyAuth.BASIC:
kwargs.extend([self.user, self.password])
if self.mode == NtfyMode.PRIVATE:
if self.auth == NtfyAuth.BASIC:
kwargs.extend([
self.user if self.user else None,
self.password if self.password else None,
])

elif self.token: # NtfyAuth.TOKEN also
kwargs.append(self.token)
elif self.token: # NtfyAuth.TOKEN also
kwargs.append(self.token)

return kwargs

def url(self, privacy=False, *args, **kwargs):
"""
Expand Down
6 changes: 5 additions & 1 deletion apprise/plugins/rsyslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,11 @@ def url_identifier(self):
another simliar one. Targets or end points should never be identified
here.
"""
return (self.protocol, self.host, self.port)
return (
self.protocol, self.host,
self.port if self.port
else self.template_tokens['port']['default'],
)

def url(self, privacy=False, *args, **kwargs):
"""
Expand Down
5 changes: 3 additions & 2 deletions apprise/plugins/syslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,10 @@ def url_identifier(self):
"""
Returns all of the identifiers that make this URL unique from
another simliar one. Targets or end points should never be identified
here.
here. False implies we do not support unique ID generation as there
simply isn't enough details to do so with.
"""
return self.protocol
return False

Check warning on line 253 in apprise/plugins/syslog.py

View check run for this annotation

Codecov / codecov/patch

apprise/plugins/syslog.py#L253

Added line #L253 was not covered by tests

def url(self, privacy=False, *args, **kwargs):
"""
Expand Down
5 changes: 3 additions & 2 deletions apprise/plugins/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,10 @@ def url_identifier(self):
"""
Returns all of the identifiers that make this URL unique from
another simliar one. Targets or end points should never be identified
here.
here. False implies we do not support unique ID generation as there
simply isn't enough details to do so with.
"""
return self.protocol
return False

def url(self, privacy=False, *args, **kwargs):
"""
Expand Down
6 changes: 5 additions & 1 deletion apprise/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def __init__(self, asset=None, **kwargs):
# Store our Timeout Variables
if 'cache' in kwargs and not parse_bool(kwargs.get('cache', True)):
# Enforce the disabling of cache (ortherwise defaults are use)
self.__url_identifier = False
self.url_identifier = False

if 'tag' in kwargs:
# We want to associate some tags with our notification service.
Expand Down Expand Up @@ -912,6 +912,10 @@ def post_process_parse_url_results(results):
if 'cto' in results['qsd']:
results['cto'] = results['qsd']['cto']

# Store our persistent cache boolean
if 'cache' in results['qsd']:
results['cache'] = results['qsd']['cache']

if 'port' in results['qsd']:
results['port'] = results['qsd']['port']

Expand Down
7 changes: 7 additions & 0 deletions test/helpers/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ def run(self, url, meta, mock_request, mock_post, mock_get):
"URL Identifier: '{}' != expected '{}'".format(
obj_cmp.url_identifier, obj.url_identifier))

# Back our check up
if obj.url_id() != obj_cmp.url_id():
print('Provided %s' % url)
raise AssertionError(
"URL ID(): '{}' != expected '{}'".format(
obj_cmp.url_id(), obj.url_id()))

# Our object should be the same instance as what we had
# originally expected above.
if not isinstance(obj_cmp, NotifyBase):
Expand Down
6 changes: 6 additions & 0 deletions test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,12 @@ def __init__(self, **kwargs):
assert plugin.url_identifier_salt == b'abc123'
assert plugin.url_id(lazy=False)

# Set our cache flag to be no (disabling caching entirely)
plugin = a.instantiate('good://localhost?cache=False')
assert isinstance(plugin, NotifyBase)
assert plugin.url_identifier_salt == b''
assert plugin.url_id(lazy=False) is None

asset = AppriseAsset(encoding='ascii')
plugin = a.instantiate('good://localhost?salt=ボールト"', asset=asset)
assert isinstance(plugin, NotifyBase)
Expand Down
3 changes: 3 additions & 0 deletions test/test_plugin_glib.py → test/test_plugin_dbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ def test_plugin_dbus_general_success(mocker, dbus_glib_environment):
assert obj.url().startswith('dbus://_/')
assert re.search('image=yes', obj.url())

# URL ID Generation is disabled
assert obj.url_id() is None

assert obj.notify(
title='title', body='body',
notify_type=apprise.NotifyType.INFO) is True
Expand Down
3 changes: 3 additions & 0 deletions test/test_plugin_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ def test_plugin_email(mock_smtp, mock_smtpssl):
# We loaded okay; now lets make sure we can reverse this url
assert isinstance(obj.url(), str)

# Get our URL Identifier
assert isinstance(obj.url_id(), str)

# Verify we can acquire a target count as an integer
assert isinstance(len(obj), int)

Expand Down
3 changes: 3 additions & 0 deletions test/test_plugin_gnome.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def test_plugin_gnome_general_success(obj):
# Test url() call
assert isinstance(obj.url(), str) is True

# our URL Identifier is disabled
assert obj.url_id() is None

# test notifications
assert obj.notify(title='title', body='body',
notify_type=apprise.NotifyType.INFO) is True
Expand Down
3 changes: 3 additions & 0 deletions test/test_plugin_growl.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ def test_plugin_growl_general(mock_gntp):

assert isinstance(obj, instance) is True

# Test our URL Identifier is generated
assert isinstance(obj.url_id(), str) is True

if isinstance(obj, NotifyBase):
# We loaded okay; now lets make sure we can reverse this url
assert isinstance(obj.url(), str) is True
Expand Down
5 changes: 5 additions & 0 deletions test/test_plugin_macosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def test_plugin_macosx_general_success(macos_notify_environment):
# Test url() call
assert isinstance(obj.url(), str) is True

# URL Identifier has been disabled as this isn't unique enough
# to be mapped to more the 1 end point; verify that None is always
# returned
assert obj.url_id() is None

# test notifications
assert obj.notify(title='title', body='body',
notify_type=apprise.NotifyType.INFO) is True
Expand Down
3 changes: 3 additions & 0 deletions test/test_plugin_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ def test_plugin_mqtt_default_success(mqtt_client_mock):
assert len(obj) == 1
assert obj.url().startswith('mqtt://localhost:1234/my/topic')

# Genrate the URL Identifier
assert isinstance(obj.url_id(), str)

# Verify default settings.
assert re.search(r'qos=0', obj.url())
assert re.search(r'version=v3.1.1', obj.url())
Expand Down
9 changes: 9 additions & 0 deletions test/test_plugin_ntfy.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,15 @@ def test_plugin_ntfy_config_files(mock_post, mock_get):
assert next(aobj.find(tag='ntfy_invalid')).priority == \
NtfyPriority.NORMAL

# A cloud reference without any identifiers; the ntfy:// (insecure mode)
# is not considered during the id generation as ntfys:// is always
# implied
results = NotifyNtfy.parse_url('ntfy://')
obj = NotifyNtfy(**results)
new_results = NotifyNtfy.parse_url(obj.url())
obj2 = NotifyNtfy(**new_results)
assert obj.url_id() == obj2.url_id()


@mock.patch('requests.post')
def test_plugin_ntfy_message_to_attach(mock_post):
Expand Down
3 changes: 3 additions & 0 deletions test/test_plugin_rsyslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def test_plugin_rsyslog_by_url(mock_getpid, mock_socket):
assert obj.url().startswith('rsyslog://localhost:9000/daemon') is True
assert re.search(r'logpid=no', obj.url()) is not None

# Verify our URL ID is generated
assert isinstance(obj.url_id(), str)

# Test notifications
# + 1 byte in size due to user
# + length of pid returned
Expand Down
3 changes: 3 additions & 0 deletions test/test_plugin_syslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def test_plugin_syslog_by_url(openlog, syslog):
assert re.search(r'logpid=yes', obj.url()) is not None
assert re.search(r'logperror=no', obj.url()) is not None

# We do not support generation of a URL ID
assert obj.url_id() is None

assert isinstance(
apprise.Apprise.instantiate(
'syslog://:@/'), NotifySyslog)
Expand Down
3 changes: 3 additions & 0 deletions test/test_plugin_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def test_plugin_windows_mocked():
# Test URL functionality
assert isinstance(obj.url(), str)

# Verify that a URL ID can not be generated
assert obj.url_id() is None

# Check that it found our mocked environments
assert obj.enabled is True

Expand Down

0 comments on commit 9bd6251

Please sign in to comment.