Skip to content

Commit

Permalink
updated for more test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Jul 9, 2023
1 parent 7a9d055 commit 74a3a28
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
12 changes: 6 additions & 6 deletions apprise/plugins/NotifyPushy.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
from ..AppriseLocale import gettext_lazy as _

# Used to detect a Device and Topic
VALIDATE_DEVICE = re.compile(r'^[@]?(?P<device>[a-z0-9]+)$', re.I)
VALIDATE_TOPIC = re.compile(r'^#(?P<topic>[a-z0-9]+)$', re.I)
VALIDATE_DEVICE = re.compile(r'^@(?P<device>[a-z0-9]+)$', re.I)
VALIDATE_TOPIC = re.compile(r'^[#]?(?P<topic>[a-z0-9]+)$', re.I)

# Extend HTTP Error Messages
PUSHY_HTTP_ERROR_MAP = {
Expand Down Expand Up @@ -146,14 +146,14 @@ def __init__(self, apikey, targets=None, sound=None, badge=None, **kwargs):
self.topics = []

for target in parse_list(targets):
result = VALIDATE_DEVICE.match(target)
result = VALIDATE_TOPIC.match(target)
if result:
self.devices.append(result.group('device'))
self.topics.append(result.group('topic'))
continue

result = VALIDATE_TOPIC.match(target)
result = VALIDATE_DEVICE.match(target)
if result:
self.topics.append(result.group('topic'))
self.devices.append(result.group('device'))
continue

self.logger.warning(
Expand Down
5 changes: 5 additions & 0 deletions test/helpers/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,14 @@ def __notify(self, url, obj, meta, asset, mock_patch, mock_del, mock_put,
requests_response_text = dumps(requests_response_text)
requests_response_content = requests_response_text.encode('utf-8')

else:
requests_response_content = u''
requests_response_text = ''

# A request
robj = mock.Mock()
robj.content = u''
robj.text = ''
mock_get.return_value = robj
mock_post.return_value = robj
mock_head.return_value = robj
Expand Down
28 changes: 25 additions & 3 deletions test/test_plugin_pushy.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,38 @@
# to actually notify anything if no device_key was specified
'notify_response': False,
'requests_response_text': GOOD_RESPONSE,

}),
('pushy://apikey/device', {
('pushy://apikey/topic', {
# No Device/Topic specified
'instance': NotifyPushy,
# Expected notify() response False because the success flag
# was set to false
'notify_response': False,
'requests_response_text': {'success': False}
}),
('pushy://apikey/%20(', {
# Invalid topic specified
'instance': NotifyPushy,
# Expected notify() response False because there is no one to notify
'notify_response': False,
'requests_response_text': GOOD_RESPONSE,
}),
('pushy://apikey/@device', {
# Everything is okay
'instance': NotifyPushy,
'requests_response_text': GOOD_RESPONSE,

# Our expected url(privacy=True) startswith() response:
'privacy_url': 'pushy://a...y/@device/',
}),
('pushy://apikey/topic', {
# Everything is okay; no prefix means it's a topic
'instance': NotifyPushy,
'requests_response_text': GOOD_RESPONSE,

# Our expected url(privacy=True) startswith() response:
'privacy_url': 'pushy://a...y/#topic/',
}),
('pushy://apikey/device/?sound=alarm.aiff', {
# alarm.aiff sound loaded
'instance': NotifyPushy,
Expand All @@ -95,7 +117,7 @@
'instance': NotifyPushy,
'requests_response_text': GOOD_RESPONSE,
}),
('pushy://apikey/?to=device', {
('pushy://apikey/?to=@device', {
# test use of to= argument
'instance': NotifyPushy,
'requests_response_text': GOOD_RESPONSE,
Expand Down

0 comments on commit 74a3a28

Please sign in to comment.