-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,67 @@ | ||
import unittest | ||
from unittest.mock import patch, MagicMock | ||
from click.testing import CliRunner | ||
from simple_notifications import cli | ||
from simple_notifications.cli import pushover, pushbullet, email | ||
import os | ||
|
||
class TestNotifications(unittest.TestCase): | ||
|
||
def test_help(): | ||
runner = CliRunner() | ||
result = runner.invoke(cli.notification) | ||
assert result.exit_code == 0 | ||
assert "Usage: " in result.output | ||
def setUp(self): | ||
self.runner = CliRunner() | ||
os.environ['LC_ALL'] = 'en_US.UTF-8' | ||
os.environ['LANG'] = 'en_US.UTF-8' | ||
|
||
|
||
def test_help(): | ||
runner = CliRunner() | ||
result = runner.invoke(cli.notification) | ||
assert result.exit_code == 0 | ||
assert "Usage: " in result.output | ||
|
||
|
||
@patch('simple_notifications.cli.simple_notifications_config.PUSHOVER_APP_TOKEN', 'fake_token') | ||
@patch('simple_notifications.cli.simple_notifications_config.USER_KEY', 'fake_user_key') | ||
@patch('requests.post') | ||
def test_pushover(self, mock_post): | ||
mock_post.return_value = MagicMock(status_code=200) | ||
result = self.runner.invoke(pushover, ['--subject', 'Test Subject', '--body', 'Test Body', '--image', 'no']) | ||
print("Output:", result.output) # Debugging output | ||
print("Exception:", result.exception) # Print exception if any | ||
print("Exit Code:", result.exit_code) # Print exit code | ||
self.assertEqual(result.exit_code, 0) | ||
self.assertIn('Sending out Pushover notification...', result.output) | ||
self.assertIn('Sending complete.', result.output) | ||
|
||
|
||
@patch('simple_notifications.cli.simple_notifications_config.PUSHBULLET_APP_TOKEN', 'fake_token') | ||
@patch('requests.post') | ||
def test_pushbullet(self, mock_post): | ||
mock_post.return_value = MagicMock(status_code=200) | ||
result = self.runner.invoke(pushbullet, ['--subject', 'Test Subject', '--body', 'Test Body']) | ||
print("Output:", result.output) # Debugging output | ||
print("Exception:", result.exception) # Print exception if any | ||
print("Exit Code:", result.exit_code) # Print exit code | ||
self.assertEqual(result.exit_code, 0) | ||
self.assertIn('Sending out Pushbullet notification...', result.output) | ||
self.assertIn('Sending complete.', result.output) | ||
|
||
|
||
@patch('simple_notifications.cli.simple_notifications_config.EMAIL_SENDER', '[email protected]') | ||
@patch('simple_notifications.cli.simple_notifications_config.EMAIL_SERVER', 'smtp.example.com') | ||
@patch('simple_notifications.cli.simple_notifications_config.EMAIL_SERVER_PORT', '587') | ||
@patch('simple_notifications.cli.simple_notifications_config.EMAIL_PASSWORD', 'fake_password') | ||
@patch('smtplib.SMTP') | ||
def test_email(self, mock_smtp): | ||
mock_smtp_instance = mock_smtp.return_value | ||
result = self.runner.invoke(email, ['--subject', 'Test Subject', '--body', 'Test Body', '--recipients', '[email protected]']) | ||
print("Output:", result.output) # Debugging output | ||
print("Exception:", result.exception) # Print exception if any | ||
print("Exit Code:", result.exit_code) # Print exit code | ||
self.assertEqual(result.exit_code, 0) | ||
self.assertIn('Sending out Email notification...', result.output) | ||
self.assertIn('Sending complete.', result.output) | ||
mock_smtp_instance.sendmail.assert_called_once() | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |