fix: cto= and rto= lines now work from YAML config (#751)

This commit is contained in:
Chris Caron 2022-11-12 10:46:56 -05:00 committed by GitHub
parent 640c00ae70
commit 29e4c5ebd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 11 deletions

View File

@ -194,7 +194,7 @@ class URLBase:
asset if isinstance(asset, AppriseAsset) else AppriseAsset() asset if isinstance(asset, AppriseAsset) else AppriseAsset()
# Certificate Verification (for SSL calls); default to being enabled # Certificate Verification (for SSL calls); default to being enabled
self.verify_certificate = kwargs.get('verify', True) self.verify_certificate = parse_bool(kwargs.get('verify', True))
# Secure Mode # Secure Mode
self.secure = kwargs.get('secure', False) self.secure = kwargs.get('secure', False)
@ -222,24 +222,22 @@ class URLBase:
self.password = URLBase.unquote(self.password) self.password = URLBase.unquote(self.password)
# Store our Timeout Variables # Store our Timeout Variables
if 'socket_read_timeout' in kwargs: if 'rto' in kwargs:
try: try:
self.socket_read_timeout = \ self.socket_read_timeout = float(kwargs.get('rto'))
float(kwargs.get('socket_read_timeout'))
except (TypeError, ValueError): except (TypeError, ValueError):
self.logger.warning( self.logger.warning(
'Invalid socket read timeout (rto) was specified {}' 'Invalid socket read timeout (rto) was specified {}'
.format(kwargs.get('socket_read_timeout'))) .format(kwargs.get('rto')))
if 'socket_connect_timeout' in kwargs: if 'cto' in kwargs:
try: try:
self.socket_connect_timeout = \ self.socket_connect_timeout = float(kwargs.get('cto'))
float(kwargs.get('socket_connect_timeout'))
except (TypeError, ValueError): except (TypeError, ValueError):
self.logger.warning( self.logger.warning(
'Invalid socket connect timeout (cto) was specified {}' 'Invalid socket connect timeout (cto) was specified {}'
.format(kwargs.get('socket_connect_timeout'))) .format(kwargs.get('cto')))
if 'tag' in kwargs: if 'tag' in kwargs:
# We want to associate some tags with our notification service. # We want to associate some tags with our notification service.
@ -647,11 +645,11 @@ class URLBase:
# Store our socket read timeout if specified # Store our socket read timeout if specified
if 'rto' in results['qsd']: if 'rto' in results['qsd']:
results['socket_read_timeout'] = results['qsd']['rto'] results['rto'] = results['qsd']['rto']
# Store our socket connect timeout if specified # Store our socket connect timeout if specified
if 'cto' in results['qsd']: if 'cto' in results['qsd']:
results['socket_connect_timeout'] = results['qsd']['cto'] results['cto'] = results['qsd']['cto']
if 'port' in results['qsd']: if 'port' in results['qsd']:
results['port'] = results['qsd']['port'] results['port'] = results['qsd']['port']

View File

@ -27,6 +27,7 @@ import pytest
from apprise.AppriseAsset import AppriseAsset from apprise.AppriseAsset import AppriseAsset
from apprise.config.ConfigBase import ConfigBase from apprise.config.ConfigBase import ConfigBase
from apprise import ConfigFormat from apprise import ConfigFormat
from inspect import cleandoc
import yaml import yaml
# Disable logging for a cleaner testing output # Disable logging for a cleaner testing output
@ -957,6 +958,44 @@ def test_yaml_vs_text_tagging():
assert 'mytag' in yaml_result[0] assert 'mytag' in yaml_result[0]
def test_config_base_config_parse_yaml_globals():
"""
API: ConfigBase.config_parse_yaml globals
"""
# general reference used below
asset = AppriseAsset()
# Invalid Syntax (throws a ScannerError)
results, config = ConfigBase.config_parse_yaml(cleandoc("""
urls:
- jsons://localhost1:
- to: jeff@gmail.com
tag: jeff, customer
cto: 30
rto: 30
verify: no
- jsons://localhost2?cto=30&rto=30&verify=no:
- to: json@gmail.com
tag: json, customer
"""), asset=asset)
# Invalid data gets us an empty result set
assert isinstance(results, list)
# Our results loaded
assert len(results) == 2
assert len(config) == 0
# Now verify that our global variables correctly initialized
for entry in results:
assert entry.verify_certificate is False
assert entry.socket_read_timeout == 30
assert entry.socket_connect_timeout == 30
# This test fails on CentOS 8.x so it was moved into it's own function # This test fails on CentOS 8.x so it was moved into it's own function
# so it could be bypassed. The ability to use lists in YAML files didn't # so it could be bypassed. The ability to use lists in YAML files didn't
# appear to happen until later on; it's certainly not available in v3.12 # appear to happen until later on; it's certainly not available in v3.12