more unittesting + bugfixes

This commit is contained in:
Chris Caron
2017-12-10 21:28:00 -05:00
parent 6cca5946e1
commit 82c5a11e5b
22 changed files with 788 additions and 246 deletions

View File

@ -27,19 +27,11 @@ import click
import logging
import sys
from apprise import Apprise
from apprise import AppriseAsset
from apprise import NotifyType
import apprise
# Logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
logger = logging.getLogger('apprise.plugins.NotifyBase')
# Defines our click context settings adding -h to the additional options that
# can be specified to get the help menu to come up
@ -60,41 +52,58 @@ def print_help_msg(command):
help='Specify the message title.')
@click.option('--body', '-b', default=None, type=str,
help='Specify the message body.')
@click.option('--notification-type', '-t', default=NotifyType.INFO, type=str,
@click.option('--notification-type', '-n', default=NotifyType.INFO, type=str,
metavar='TYPE', help='Specify the message type (default=info).')
@click.option('--theme', '-T', default='default', type=str,
help='Specify the default theme.')
@click.option('-v', '--verbose', count=True)
@click.argument('urls', nargs=-1,
metavar='SERVER_URL [SERVER_URL2 [SERVER_URL3]]',)
def _main(title, body, urls, notification_type, theme):
def _main(title, body, urls, notification_type, theme, verbose):
"""
Send a notification to all of the specified servers identified by their
URLs the content provided within the title, body and notification-type.
"""
# Logging
ch = logging.StreamHandler(sys.stdout)
if verbose > 2:
logger.setLevel(logging.DEBUG)
elif verbose == 1:
logger.setLevel(logging.INFO)
else:
logger.setLevel(logging.NONE)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
if not urls:
logger.error('You must specify at least one server URL.')
print_help_msg(_main)
return 1
# Prepare our asset
asset = AppriseAsset(theme=theme)
asset = apprise.AppriseAsset(theme=theme)
# Create our object
apprise = Apprise(asset=asset)
a = apprise.Apprise(asset=asset)
# Load our inventory up
for url in urls:
apprise.add(url)
a.add(url)
if body is None:
# if no body was specified, then read from STDIN
body = click.get_text_stream('stdin').read()
# now print it out
apprise.notify(title=title, body=body, notify_type=notification_type)
return 0
if a.notify(title=title, body=body, notify_type=notification_type):
return 0
return 1
if __name__ == '__main__':