refactored how plugins inheritied properties

This commit is contained in:
Chris Caron 2018-03-30 22:29:36 -04:00
parent b040e232ae
commit 7e38921835
28 changed files with 170 additions and 162 deletions

View File

@ -99,12 +99,22 @@ class NotifyBase(object):
# us a safe play range...
throttle_attempt = 5.5
# Allows the user to specify the NotifyImageSize object
image_size = None
# The maximum allowable characters allowed in the body per message
body_maxlen = 32768
# Defines the maximum allowable characters in the title
title_maxlen = 250
# Default Notify Format
notify_format = NotifyFormat.TEXT
# Logging
logger = logging.getLogger(__name__)
def __init__(self, title_maxlen=100, body_maxlen=512,
notify_format=NotifyFormat.TEXT, image_size=None,
secure=False, throttle=None, **kwargs):
def __init__(self, **kwargs):
"""
Initialize some general logging and common server arguments that will
keep things consistent when working with the notifiers that will
@ -112,38 +122,15 @@ class NotifyBase(object):
"""
if notify_format.lower() not in NOTIFY_FORMATS:
self.logger.error(
'Invalid notification format %s' % notify_format,
)
raise TypeError(
'Invalid notification format %s' % notify_format,
)
if image_size and image_size not in NOTIFY_IMAGE_SIZES:
self.logger.error(
'Invalid image size %s' % image_size,
)
raise TypeError(
'Invalid image size %s' % image_size,
)
# Prepare our Assets
self.asset = AppriseAsset()
self.notify_format = notify_format.lower()
self.title_maxlen = title_maxlen
self.body_maxlen = body_maxlen
self.image_size = image_size
self.secure = secure
if isinstance(throttle, (float, int)):
# Custom throttle override
self.throttle_attempt = throttle
# Certificate Verification (for SSL calls); default to being enabled
self.verify_certificate = kwargs.get('verify', True)
# Secure Mode
self.secure = kwargs.get('secure', False)
self.host = kwargs.get('host', '')
self.port = kwargs.get('port')
if self.port:
@ -156,6 +143,19 @@ class NotifyBase(object):
self.user = kwargs.get('user')
self.password = kwargs.get('password')
if 'notify_format' in kwargs:
# Store the specified notify_format if specified
notify_format = kwargs.get('notify_format')
if notify_format.lower() not in NOTIFY_FORMATS:
self.logger.error(
'Invalid notification format %s' % notify_format,
)
raise TypeError(
'Invalid notification format %s' % notify_format,
)
# Provide override
self.notify_format = notify_format
def throttle(self, throttle_time=None):
"""
A common throttle control

View File

@ -57,9 +57,6 @@ VALIDATE_SECRET = re.compile(r'[A-Z0-9_-]{64}', re.I)
# into a usable list.
TAGS_LIST_DELIM = re.compile(r'[ \t\r\n,\\/]+')
# Image Support (72x72)
BOXCAR_IMAGE_XY = NotifyImageSize.XY_72
class NotifyBoxcar(NotifyBase):
"""
@ -72,13 +69,17 @@ class NotifyBoxcar(NotifyBase):
# Boxcar URL
notify_url = 'https://boxcar-api.io/api/push/'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_72
# The maximum allowable characters allowed in the body per message
body_maxlen = 10000
def __init__(self, access, secret, recipients=None, **kwargs):
"""
Initialize Boxcar Object
"""
super(NotifyBoxcar, self).__init__(
title_maxlen=250, body_maxlen=10000,
image_size=BOXCAR_IMAGE_XY, **kwargs)
super(NotifyBoxcar, self).__init__(**kwargs)
# Initialize tag list
self.tags = list()

View File

@ -43,9 +43,6 @@ from ..common import NotifyImageSize
from ..common import NotifyFormat
from ..utils import parse_bool
# Image Support (256x256)
DISCORD_IMAGE_XY = NotifyImageSize.XY_256
class NotifyDiscord(NotifyBase):
"""
@ -59,17 +56,22 @@ class NotifyDiscord(NotifyBase):
# Discord Webhook
notify_url = 'https://discordapp.com/api/webhooks'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_256
# The maximum allowable characters allowed in the body per message
body_maxlen = 2000
# Default Notify Format
notify_format = NotifyFormat.MARKDOWN
def __init__(self, webhook_id, webhook_token, tts=False, avatar=True,
footer=False, thumbnail=True,
notify_format=NotifyFormat.MARKDOWN, **kwargs):
footer=False, thumbnail=True, **kwargs):
"""
Initialize Discord Object
"""
super(NotifyDiscord, self).__init__(
title_maxlen=250, body_maxlen=2000,
notify_format=notify_format,
image_size=DISCORD_IMAGE_XY, **kwargs)
super(NotifyDiscord, self).__init__(**kwargs)
if not webhook_id:
raise TypeError(

View File

@ -128,14 +128,11 @@ class NotifyEmail(NotifyBase):
# Default SMTP Timeout (in seconds)
connect_timeout = 15
def __init__(self, to, notify_format, **kwargs):
def __init__(self, to, **kwargs):
"""
Initialize Email Object
"""
super(NotifyEmail, self).__init__(
title_maxlen=250, body_maxlen=32768,
notify_format=notify_format,
**kwargs)
super(NotifyEmail, self).__init__(**kwargs)
# Store To Addr
self.to_addr = to

View File

@ -62,8 +62,7 @@ class NotifyEmby(NotifyBase):
Initialize Emby Object
"""
super(NotifyEmby, self).__init__(
title_maxlen=250, body_maxlen=32768, **kwargs)
super(NotifyEmby, self).__init__(**kwargs)
if self.secure:
self.schema = 'https'

View File

@ -2,7 +2,7 @@
#
# Faast Notify Wrapper
#
# Copyright (C) 2017 Chris Caron <lead2gold@gmail.com>
# Copyright (C) 2017-2018 Chris Caron <lead2gold@gmail.com>
#
# This file is part of apprise.
#
@ -22,9 +22,6 @@ from .NotifyBase import NotifyBase
from .NotifyBase import HTTP_ERROR_MAP
from ..common import NotifyImageSize
# Image Support (72x72)
FAAST_IMAGE_XY = NotifyImageSize.XY_72
class NotifyFaast(NotifyBase):
"""
@ -37,13 +34,14 @@ class NotifyFaast(NotifyBase):
# Faast uses the http protocol with JSON requests
notify_url = 'https://www.appnotifications.com/account/notifications.json'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_72
def __init__(self, authtoken, **kwargs):
"""
Initialize Faast Object
"""
super(NotifyFaast, self).__init__(
title_maxlen=250, body_maxlen=32768, image_size=FAAST_IMAGE_XY,
**kwargs)
super(NotifyFaast, self).__init__(**kwargs)
self.authtoken = authtoken

View File

@ -23,9 +23,6 @@ from .gntp import errors
from ..NotifyBase import NotifyBase
from ...common import NotifyImageSize
# Image Support (72x72)
GROWL_IMAGE_XY = NotifyImageSize.XY_72
# Priorities
class GrowlPriority(object):
@ -59,13 +56,14 @@ class NotifyGrowl(NotifyBase):
# Default Growl Port
default_port = 23053
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_72
def __init__(self, priority=None, version=2, **kwargs):
"""
Initialize Growl Object
"""
super(NotifyGrowl, self).__init__(
title_maxlen=250, body_maxlen=32768,
image_size=GROWL_IMAGE_XY, **kwargs)
super(NotifyGrowl, self).__init__(**kwargs)
if not self.port:
self.port = self.default_port

View File

@ -76,8 +76,7 @@ class NotifyIFTTT(NotifyBase):
Initialize IFTTT Object
"""
super(NotifyIFTTT, self).__init__(
title_maxlen=250, body_maxlen=32768, **kwargs)
super(NotifyIFTTT, self).__init__(**kwargs)
if not apikey:
raise TypeError('You must specify the Webhooks apikey.')

View File

@ -24,9 +24,6 @@ from .NotifyBase import HTTP_ERROR_MAP
from ..common import NotifyImageSize
from ..utils import compat_is_basestring
# Image Support (128x128)
JSON_IMAGE_XY = NotifyImageSize.XY_128
class NotifyJSON(NotifyBase):
"""
@ -39,13 +36,14 @@ class NotifyJSON(NotifyBase):
# The default secure protocol
secure_protocol = 'jsons'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_128
def __init__(self, **kwargs):
"""
Initialize JSON Object
"""
super(NotifyJSON, self).__init__(
title_maxlen=250, body_maxlen=32768, image_size=JSON_IMAGE_XY,
**kwargs)
super(NotifyJSON, self).__init__(**kwargs)
if self.secure:
self.schema = 'https'

View File

@ -71,13 +71,17 @@ class NotifyJoin(NotifyBase):
notify_url = \
'https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_72
# The maximum allowable characters allowed in the body per message
body_maxlen = 1000
def __init__(self, apikey, devices, **kwargs):
"""
Initialize Join Object
"""
super(NotifyJoin, self).__init__(
title_maxlen=250, body_maxlen=1000, image_size=JOIN_IMAGE_XY,
**kwargs)
super(NotifyJoin, self).__init__(**kwargs)
if not VALIDATE_APIKEY.match(apikey.strip()):
self.logger.warning(

View File

@ -2,7 +2,7 @@
#
# MatterMost Notify Wrapper
#
# Copyright (C) 2017 Chris Caron <lead2gold@gmail.com>
# Copyright (C) 2017-2018 Chris Caron <lead2gold@gmail.com>
#
# This file is part of apprise.
#
@ -31,9 +31,6 @@ from ..common import NotifyImageSize
# Used to validate Authorization Token
VALIDATE_AUTHTOKEN = re.compile(r'[A-Za-z0-9]{24,32}')
# Image Support (72x72)
MATTERMOST_IMAGE_XY = NotifyImageSize.XY_72
class NotifyMatterMost(NotifyBase):
"""
@ -49,13 +46,17 @@ class NotifyMatterMost(NotifyBase):
# The default Mattermost port
default_port = 8065
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_72
# The maximum allowable characters allowed in the body per message
body_maxlen = 4000
def __init__(self, authtoken, channel=None, **kwargs):
"""
Initialize MatterMost Object
"""
super(NotifyMatterMost, self).__init__(
title_maxlen=250, body_maxlen=4000, image_size=MATTERMOST_IMAGE_XY,
**kwargs)
super(NotifyMatterMost, self).__init__(**kwargs)
if self.secure:
self.schema = 'https'

View File

@ -2,7 +2,7 @@
#
# Notify My Android (NMA) Notify Wrapper
#
# Copyright (C) 2017 Chris Caron <lead2gold@gmail.com>
# Copyright (C) 2017-2018 Chris Caron <lead2gold@gmail.com>
#
# This file is part of apprise.
#
@ -64,12 +64,17 @@ class NotifyMyAndroid(NotifyBase):
# Notify My Android uses the http protocol with JSON requests
notify_url = 'https://www.notifymyandroid.com/publicapi/notify'
# The maximum allowable characters allowed in the body per message
body_maxlen = 10000
# Defines the maximum allowable characters in the title
title_maxlen = 1000
def __init__(self, apikey, priority=None, devapikey=None, **kwargs):
"""
Initialize Notify My Android Object
"""
super(NotifyMyAndroid, self).__init__(
title_maxlen=1000, body_maxlen=10000, **kwargs)
super(NotifyMyAndroid, self).__init__(**kwargs)
# The Priority of the message
if priority not in NMA_PRIORITIES:

View File

@ -2,7 +2,7 @@
#
# Prowl Notify Wrapper
#
# Copyright (C) 2017 Chris Caron <lead2gold@gmail.com>
# Copyright (C) 2017-2018 Chris Caron <lead2gold@gmail.com>
#
# This file is part of apprise.
#
@ -65,12 +65,17 @@ class NotifyProwl(NotifyBase):
# Prowl uses the http protocol with JSON requests
notify_url = 'https://api.prowlapp.com/publicapi/add'
# The maximum allowable characters allowed in the body per message
body_maxlen = 10000
# Defines the maximum allowable characters in the title
title_maxlen = 1024
def __init__(self, apikey, providerkey=None, priority=None, **kwargs):
"""
Initialize Prowl Object
"""
super(NotifyProwl, self).__init__(
title_maxlen=1024, body_maxlen=10000, **kwargs)
super(NotifyProwl, self).__init__(**kwargs)
if priority not in PROWL_PRIORITIES:
self.priority = ProwlPriority.NORMAL

View File

@ -2,7 +2,7 @@
#
# PushBullet Notify Wrapper
#
# Copyright (C) 2017 Chris Caron <lead2gold@gmail.com>
# Copyright (C) 2017-2018 Chris Caron <lead2gold@gmail.com>
#
# This file is part of apprise.
#
@ -55,8 +55,7 @@ class NotifyPushBullet(NotifyBase):
"""
Initialize PushBullet Object
"""
super(NotifyPushBullet, self).__init__(
title_maxlen=250, body_maxlen=32768, **kwargs)
super(NotifyPushBullet, self).__init__(**kwargs)
self.accesstoken = accesstoken
if compat_is_basestring(recipients):

View File

@ -2,7 +2,7 @@
#
# Pushalot Notify Wrapper
#
# Copyright (C) 2017 Chris Caron <lead2gold@gmail.com>
# Copyright (C) 2017-2018 Chris Caron <lead2gold@gmail.com>
#
# This file is part of apprise.
#
@ -24,9 +24,6 @@ from .NotifyBase import NotifyBase
from .NotifyBase import HTTP_ERROR_MAP
from ..common import NotifyImageSize
# Image Support (72x72)
PUSHALOT_IMAGE_XY = NotifyImageSize.XY_72
# Extend HTTP Error Messages
PUSHALOT_HTTP_ERROR_MAP = HTTP_ERROR_MAP.copy()
PUSHALOT_HTTP_ERROR_MAP.update({
@ -49,13 +46,14 @@ class NotifyPushalot(NotifyBase):
# Pushalot uses the http protocol with JSON requests
notify_url = 'https://pushalot.com/api/sendmessage'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_72
def __init__(self, authtoken, is_important=False, **kwargs):
"""
Initialize Pushalot Object
"""
super(NotifyPushalot, self).__init__(
title_maxlen=250, body_maxlen=32768,
image_size=PUSHALOT_IMAGE_XY, **kwargs)
super(NotifyPushalot, self).__init__(**kwargs)
# Is Important Flag
self.is_important = is_important

View File

@ -42,8 +42,7 @@ class NotifyPushjet(NotifyBase):
"""
Initialize Pushjet Object
"""
super(NotifyPushjet, self).__init__(
title_maxlen=250, body_maxlen=32768, **kwargs)
super(NotifyPushjet, self).__init__(**kwargs)
def notify(self, title, body, notify_type):
"""

View File

@ -74,12 +74,14 @@ class NotifyPushover(NotifyBase):
# Pushover uses the http protocol with JSON requests
notify_url = 'https://api.pushover.net/1/messages.json'
# The maximum allowable characters allowed in the body per message
body_maxlen = 512
def __init__(self, token, devices=None, priority=None, **kwargs):
"""
Initialize Pushover Object
"""
super(NotifyPushover, self).__init__(
title_maxlen=250, body_maxlen=512, **kwargs)
super(NotifyPushover, self).__init__(**kwargs)
try:
# The token associated with the account

View File

@ -2,7 +2,7 @@
#
# Notify Rocket.Chat Notify Wrapper
#
# Copyright (C) 2017 Chris Caron <lead2gold@gmail.com>
# Copyright (C) 2017-2018 Chris Caron <lead2gold@gmail.com>
#
# This file is part of apprise.
#
@ -50,12 +50,14 @@ class NotifyRocketChat(NotifyBase):
# The default secure protocol
secure_protocol = 'rockets'
# Defines the maximum allowable characters in the title
title_maxlen = 200
def __init__(self, recipients=None, **kwargs):
"""
Initialize Notify Rocket.Chat Object
"""
super(NotifyRocketChat, self).__init__(
title_maxlen=200, body_maxlen=32768, **kwargs)
super(NotifyRocketChat, self).__init__(**kwargs)
if self.secure:
self.schema = 'https'

View File

@ -65,9 +65,6 @@ CHANNEL_LIST_DELIM = re.compile(r'[ \t\r\n,#\\/]+')
# Used to detect a channel
IS_CHANNEL_RE = re.compile(r'[+#@]?([A-Z0-9_]{1,32})', re.I)
# Image Support (72x72)
SLACK_IMAGE_XY = NotifyImageSize.XY_72
class NotifySlack(NotifyBase):
"""
@ -80,13 +77,17 @@ class NotifySlack(NotifyBase):
# Slack uses the http protocol with JSON requests
notify_url = 'https://hooks.slack.com/services'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_72
# The maximum allowable characters allowed in the body per message
body_maxlen = 1000
def __init__(self, token_a, token_b, token_c, channels, **kwargs):
"""
Initialize Slack Object
"""
super(NotifySlack, self).__init__(
title_maxlen=250, body_maxlen=1000,
image_size=SLACK_IMAGE_XY, **kwargs)
super(NotifySlack, self).__init__(**kwargs)
if not VALIDATE_TOKEN_A.match(token_a.strip()):
self.logger.warning(

View File

@ -50,9 +50,6 @@ from .NotifyBase import NotifyBase
from .NotifyBase import HTTP_ERROR_MAP
from ..common import NotifyImageSize
# Image Support (256x256)
STRIDE_IMAGE_XY = NotifyImageSize.XY_256
# A Simple UUID4 checker
IS_VALID_TOKEN = re.compile(
r'([0-9a-f]{8})-*([0-9a-f]{4})-*(4[0-9a-f]{3})-*'
@ -72,14 +69,18 @@ class NotifyStride(NotifyBase):
notify_url = 'https://api.atlassian.com/site/{cloud_id}/' \
'conversation/{convo_id}/message'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_256
# The maximum allowable characters allowed in the body per message
body_maxlen = 2000
def __init__(self, auth_token, cloud_id, convo_id, **kwargs):
"""
Initialize Stride Object
"""
super(NotifyStride, self).__init__(
title_maxlen=250, body_maxlen=2000,
image_size=STRIDE_IMAGE_XY, **kwargs)
super(NotifyStride, self).__init__(**kwargs)
if not auth_token:
raise TypeError(

View File

@ -53,7 +53,6 @@ from json import dumps
from .NotifyBase import NotifyBase
from .NotifyBase import HTTP_ERROR_MAP
from ..common import NotifyImageSize
from ..common import NotifyFormat
from ..utils import compat_is_basestring
from ..utils import parse_bool
@ -89,15 +88,18 @@ class NotifyTelegram(NotifyBase):
# Telegram uses the http protocol with JSON requests
notify_url = 'https://api.telegram.org/bot'
def __init__(self, bot_token, chat_ids, notify_format=NotifyFormat.TEXT,
detect_bot_owner=True, include_image=True, **kwargs):
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_256
# The maximum allowable characters allowed in the body per message
body_maxlen = 4096
def __init__(self, bot_token, chat_ids, detect_bot_owner=True,
include_image=True, **kwargs):
"""
Initialize Telegram Object
"""
super(NotifyTelegram, self).__init__(
title_maxlen=250, body_maxlen=4096,
notify_format=notify_format,
image_size=TELEGRAM_IMAGE_XY, **kwargs)
super(NotifyTelegram, self).__init__(**kwargs)
try:
self.bot_token = bot_token.strip()

View File

@ -24,9 +24,6 @@ from .NotifyBase import HTTP_ERROR_MAP
from ..common import NotifyImageSize
from ..utils import compat_is_basestring
# Image Support (128x128)
TOASTY_IMAGE_XY = NotifyImageSize.XY_128
# Used to break apart list of potential devices by their delimiter
# into a usable list.
DEVICES_LIST_DELIM = re.compile(r'[ \t\r\n,\\/]+')
@ -43,13 +40,14 @@ class NotifyToasty(NotifyBase):
# Toasty uses the http protocol with JSON requests
notify_url = 'http://api.supertoasty.com/notify/'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_128
def __init__(self, devices, **kwargs):
"""
Initialize Toasty Object
"""
super(NotifyToasty, self).__init__(
title_maxlen=250, body_maxlen=32768, image_size=TOASTY_IMAGE_XY,
**kwargs)
super(NotifyToasty, self).__init__(**kwargs)
if compat_is_basestring(devices):
self.devices = [x for x in filter(bool, DEVICES_LIST_DELIM.split(

View File

@ -19,9 +19,6 @@
from . import tweepy
from ..NotifyBase import NotifyBase
# Direct Messages have not image support
TWITTER_IMAGE_XY = None
class NotifyTwitter(NotifyBase):
"""
@ -32,16 +29,17 @@ class NotifyTwitter(NotifyBase):
# The default secure protocol
secure_protocol = 'tweet'
# The maximum allowable characters allowed in the body per message
# This is used during a Private DM Message Size (not Public Tweets
# which are limited to 240 characters)
body_maxlen = 4096
def __init__(self, ckey, csecret, akey, asecret, **kwargs):
"""
Initialize Twitter Object
Tweets are restriced to 140 (soon to be 240), but DM messages
do not have any restriction on them
"""
super(NotifyTwitter, self).__init__(
title_maxlen=250, body_maxlen=4096,
image_size=TWITTER_IMAGE_XY, **kwargs)
super(NotifyTwitter, self).__init__(**kwargs)
if not ckey:
raise TypeError(

View File

@ -25,9 +25,6 @@ from .NotifyBase import HTTP_ERROR_MAP
from ..common import NotifyType
from ..common import NotifyImageSize
# Image Support (128x128)
XBMC_IMAGE_XY = NotifyImageSize.XY_128
class NotifyXBMC(NotifyBase):
"""
@ -43,6 +40,9 @@ class NotifyXBMC(NotifyBase):
# XBMC uses the http protocol with JSON requests
xbmc_default_port = 8080
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_128
# XBMC default protocol version (v2)
xbmc_remote_protocol = 2
@ -53,9 +53,7 @@ class NotifyXBMC(NotifyBase):
"""
Initialize XBMC/KODI Object
"""
super(NotifyXBMC, self).__init__(
title_maxlen=250, body_maxlen=32768,
image_size=XBMC_IMAGE_XY, **kwargs)
super(NotifyXBMC, self).__init__(**kwargs)
if self.secure:
self.schema = 'https'

View File

@ -24,9 +24,6 @@ from .NotifyBase import HTTP_ERROR_MAP
from ..common import NotifyImageSize
from ..utils import compat_is_basestring
# Image Support (128x128)
XML_IMAGE_XY = NotifyImageSize.XY_128
class NotifyXML(NotifyBase):
"""
@ -39,13 +36,14 @@ class NotifyXML(NotifyBase):
# The default secure protocol
secure_protocol = 'xmls'
# Allows the user to specify the NotifyImageSize object
image_size = NotifyImageSize.XY_128
def __init__(self, **kwargs):
"""
Initialize XML Object
"""
super(NotifyXML, self).__init__(
title_maxlen=250, body_maxlen=32768,
image_size=XML_IMAGE_XY, **kwargs)
super(NotifyXML, self).__init__(**kwargs)
self.payload = """<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope

View File

@ -423,6 +423,7 @@ def test_apprise_asset(tmpdir):
# Disable all image references
a = AppriseAsset(image_path_mask=False, image_url_mask=False)
# We always return none in these calls now
assert(a.image_raw(NotifyType.INFO, NotifyImageSize.XY_256) is None)
assert(a.image_url(NotifyType.INFO, NotifyImageSize.XY_256) is None)

View File

@ -2,7 +2,7 @@
#
# NotifyBase Unit Tests
#
# Copyright (C) 2017 Chris Caron <lead2gold@gmail.com>
# Copyright (C) 2017-2018 Chris Caron <lead2gold@gmail.com>
#
# This file is part of apprise.
#
@ -38,14 +38,6 @@ def test_notify_base():
except TypeError:
assert(True)
try:
nb = NotifyBase(image_size='invalid')
# We should never reach here as an exception should be thrown
assert(False)
except TypeError:
assert(True)
# Bad port information
nb = NotifyBase(port='invalid')
assert nb.port is None
@ -54,7 +46,8 @@ def test_notify_base():
assert nb.port == 10
# Throttle overrides..
nb = NotifyBase(throttle=0)
nb = NotifyBase()
nb.throttle_attempt = 0.0
start_time = default_timer()
nb.throttle()
elapsed = default_timer() - start_time
@ -85,8 +78,10 @@ def test_notify_base():
assert isinstance(
nb.color(notify_type=NotifyType.INFO, color_type=tuple), tuple)
# Create an object with an ImageSize loaded into it
nb = NotifyBase(image_size=NotifyImageSize.XY_256)
# Create an object
nb = NotifyBase()
# Force an image size since the default doesn't have one
nb.image_size = NotifyImageSize.XY_256
# We'll get an object this time around
assert nb.image_url(notify_type=NotifyType.INFO) is not None

View File

@ -2594,6 +2594,15 @@ def test_notify_telegram_plugin(mock_post, mock_get):
nimg_obj.throttle_attempt = 0
obj.throttle_attempt = 0
# Test that our default settings over-ride base settings since they are
# not the same as the one specified in the base; this check merely
# ensures our plugin inheritance is working properly
assert obj.body_maxlen == plugins.NotifyTelegram.body_maxlen
# We don't override the title maxlen so we should be set to the same
# as our parent class in this case
assert obj.title_maxlen == plugins.NotifyBase.NotifyBase.title_maxlen
# This tests erroneous messages involving multiple chat ids
assert obj.notify(
title='title', body='body', notify_type=NotifyType.INFO) is False