improved logic and error response checking

pull/1135/head
Chris Caron 2024-08-27 15:06:15 -04:00
parent 598c054f91
commit a2b1115873
2 changed files with 21 additions and 16 deletions

View File

@ -213,7 +213,7 @@ class NotifyWxPusher(NotifyBase):
'uids': self._users, 'uids': self._users,
# unsupported at this time # unsupported at this time
'verifyPay': False, # 'verifyPay': False,
# 'verifyPayType': 0, # 'verifyPayType': 0,
'url': None, 'url': None,
} }
@ -244,8 +244,9 @@ class NotifyWxPusher(NotifyBase):
# AttributeError = r is None # AttributeError = r is None
content = {} content = {}
# 1000 is the expected return code for a successful query
if r.status_code == requests.codes.ok and \ if r.status_code == requests.codes.ok and \
content and content.get('success', False): content and content.get("code") == 1000:
# We're good! # We're good!
self.logger.info( self.logger.info(
@ -254,16 +255,17 @@ class NotifyWxPusher(NotifyBase):
else: else:
# We had a problem # We had a problem
error_str = content.get('msg') if content else None
status_str = \ status_str = \
NotifyWxPusher.http_response_code_lookup( NotifyWxPusher.http_response_code_lookup(
r.status_code) r.status_code) if not error_str else error_str
self.logger.warning( self.logger.warning(
'Failed to send WxPusher notification: ' 'Failed to send WxPusher notification, '
'{}{}error={}.'.format( 'code={}/{}: {}'.format(
status_str, r.status_code,
', ' if status_str else '', 'unk' if not content else content.get("code"),
r.status_code)) status_str))
self.logger.debug( self.logger.debug(
'Response Details:\r\n{}'.format( 'Response Details:\r\n{}'.format(
@ -283,6 +285,15 @@ class NotifyWxPusher(NotifyBase):
return True return True
@property
def url_identifier(self):
"""
Returns all of the identifiers that make this URL unique from
another simliar one. Targets or end points should never be identified
here.
"""
return (self.secure_protocol, self.token)
def url(self, privacy=False, *args, **kwargs): def url(self, privacy=False, *args, **kwargs):
""" """
Returns the URL built dynamically based on specified arguments. Returns the URL built dynamically based on specified arguments.

View File

@ -39,8 +39,8 @@ from helpers import AppriseURLTester
import logging import logging
logging.disable(logging.CRITICAL) logging.disable(logging.CRITICAL)
WXPUSHER_GOOD_RESPONSE = dumps({"success": True}) WXPUSHER_GOOD_RESPONSE = dumps({"code": 1000})
WXPUSHER_BAD_RESPONSE = dumps({"success": False}) WXPUSHER_BAD_RESPONSE = dumps({"code": 99})
# Attachment Directory # Attachment Directory
@ -244,8 +244,6 @@ def test_plugin_wxpusher_edge_cases(mock_post):
'contentType': 0, 'contentType': 0,
'topicIds': [], 'topicIds': [],
'uids': ['UID_abcd'], 'uids': ['UID_abcd'],
'verifyPay': False,
'verifyPayType': 0,
'url': None, 'url': None,
} }
@ -291,8 +289,6 @@ def test_plugin_wxpusher_result_set(mock_post):
'contentType': 0, 'contentType': 0,
'topicIds': [123], 'topicIds': [123],
'uids': ['UID_456'], 'uids': ['UID_456'],
'verifyPay': False,
'verifyPayType': 0,
'url': None, 'url': None,
} }
@ -323,8 +319,6 @@ def test_plugin_wxpusher_result_set(mock_post):
'contentType': 0, 'contentType': 0,
'topicIds': [123456789], 'topicIds': [123456789],
'uids': ['UID_123', 'UID_abc'], 'uids': ['UID_123', 'UID_abc'],
'verifyPay': False,
'verifyPayType': 0,
'url': None, 'url': None,
} }