From a2b11158730982c26478f3d767d69fc6eb5f58c9 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Tue, 27 Aug 2024 15:06:15 -0400 Subject: [PATCH] improved logic and error response checking --- apprise/plugins/wxpusher.py | 27 +++++++++++++++++++-------- test/test_plugin_wxpusher.py | 10 ++-------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/apprise/plugins/wxpusher.py b/apprise/plugins/wxpusher.py index a4b16f8d..1561813e 100644 --- a/apprise/plugins/wxpusher.py +++ b/apprise/plugins/wxpusher.py @@ -213,7 +213,7 @@ class NotifyWxPusher(NotifyBase): 'uids': self._users, # unsupported at this time - 'verifyPay': False, + # 'verifyPay': False, # 'verifyPayType': 0, 'url': None, } @@ -244,8 +244,9 @@ class NotifyWxPusher(NotifyBase): # AttributeError = r is None content = {} + # 1000 is the expected return code for a successful query if r.status_code == requests.codes.ok and \ - content and content.get('success', False): + content and content.get("code") == 1000: # We're good! self.logger.info( @@ -254,16 +255,17 @@ class NotifyWxPusher(NotifyBase): else: # We had a problem + error_str = content.get('msg') if content else None status_str = \ NotifyWxPusher.http_response_code_lookup( - r.status_code) + r.status_code) if not error_str else error_str self.logger.warning( - 'Failed to send WxPusher notification: ' - '{}{}error={}.'.format( - status_str, - ', ' if status_str else '', - r.status_code)) + 'Failed to send WxPusher notification, ' + 'code={}/{}: {}'.format( + r.status_code, + 'unk' if not content else content.get("code"), + status_str)) self.logger.debug( 'Response Details:\r\n{}'.format( @@ -283,6 +285,15 @@ class NotifyWxPusher(NotifyBase): 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): """ Returns the URL built dynamically based on specified arguments. diff --git a/test/test_plugin_wxpusher.py b/test/test_plugin_wxpusher.py index ea3ffcb9..c56acf80 100644 --- a/test/test_plugin_wxpusher.py +++ b/test/test_plugin_wxpusher.py @@ -39,8 +39,8 @@ from helpers import AppriseURLTester import logging logging.disable(logging.CRITICAL) -WXPUSHER_GOOD_RESPONSE = dumps({"success": True}) -WXPUSHER_BAD_RESPONSE = dumps({"success": False}) +WXPUSHER_GOOD_RESPONSE = dumps({"code": 1000}) +WXPUSHER_BAD_RESPONSE = dumps({"code": 99}) # Attachment Directory @@ -244,8 +244,6 @@ def test_plugin_wxpusher_edge_cases(mock_post): 'contentType': 0, 'topicIds': [], 'uids': ['UID_abcd'], - 'verifyPay': False, - 'verifyPayType': 0, 'url': None, } @@ -291,8 +289,6 @@ def test_plugin_wxpusher_result_set(mock_post): 'contentType': 0, 'topicIds': [123], 'uids': ['UID_456'], - 'verifyPay': False, - 'verifyPayType': 0, 'url': None, } @@ -323,8 +319,6 @@ def test_plugin_wxpusher_result_set(mock_post): 'contentType': 0, 'topicIds': [123456789], 'uids': ['UID_123', 'UID_abc'], - 'verifyPay': False, - 'verifyPayType': 0, 'url': None, }