Skip to content

Commit

Permalink
test coverage added
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Feb 17, 2021
1 parent 986a19d commit 62dd5ba
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
32 changes: 31 additions & 1 deletion test/test_pushover.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,56 @@ def test_pushover_attachments(mock_post, tmpdir):
assert mock_post.call_args_list[0][0][0] == \
'https://api.pushover.net/1/messages.json'

# Reset our mock object for multiple tests
mock_post.reset_mock()

# Test multiple attachments
assert attach.add(os.path.join(TEST_VAR_DIR, 'apprise-test.gif'))
assert obj.notify(body="test", attach=attach) is True

# Test our call count
assert mock_post.call_count == 2
assert mock_post.call_args_list[0][0][0] == \
'https://api.pushover.net/1/messages.json'
assert mock_post.call_args_list[1][0][0] == \
'https://api.pushover.net/1/messages.json'

# Reset our mock object for multiple tests
mock_post.reset_mock()

image = tmpdir.mkdir("pover_image").join("test.jpg")
image.write('a' * plugins.NotifyPushover.attach_max_size_bytes)

attach = AppriseAttachment.instantiate(str(image))
assert obj.notify(body="test", attach=attach) is True

# Test our call count
assert mock_post.call_count == 1
assert mock_post.call_args_list[0][0][0] == \
'https://api.pushover.net/1/messages.json'

# Reset our mock object for multiple tests
mock_post.reset_mock()

# Add 1 more byte to the file (putting it over the limit)
image.write('a' * (plugins.NotifyPushover.attach_max_size_bytes + 1))

attach = AppriseAttachment.instantiate(str(image))
assert obj.notify(body="test", attach=attach) is False

# Test our call count
assert mock_post.call_count == 0

# Test case when file is missing
attach = AppriseAttachment.instantiate(
'file://{}?cache=False'.format(str(image)))
os.unlink(str(image))
assert obj.notify(
body='body', title='title', attach=attach) is False

# Test our call count
assert mock_post.call_count == 0

# Test unsuported files:
image = tmpdir.mkdir("pover_unsupported").join("test.doc")
image.write('a' * 256)
Expand All @@ -119,7 +146,10 @@ def test_pushover_attachments(mock_post, tmpdir):

# Throw an exception on the first call to requests.post()
for side_effect in (requests.RequestException(), OSError(), bad_response):
mock_post.side_effect = [side_effect]
mock_post.side_effect = [side_effect, side_effect]

# We'll fail now because of our error handling
assert obj.send(body="test", attach=attach) is False

# Same case without an attachment
assert obj.send(body="test") is False
4 changes: 4 additions & 0 deletions test/test_rest_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,10 @@
# Our expected url(privacy=True) startswith() response:
'privacy_url': 'gotify://hostname/a/path/ending/in/a/slash/u...u/',
}),
# Markdown test
('gotify://hostname/%s?format=markdown' % ('t' * 16), {
'instance': plugins.NotifyGotify,
}),
# Provide a hostname, path, and token
('gotify://hostname/a/path/not/ending/in/a/slash/%s' % ('v' * 16), {
'instance': plugins.NotifyGotify,
Expand Down

0 comments on commit 62dd5ba

Please sign in to comment.