Commits

Jeffrey Goettsch committed f291c82

Fixed the issue of pushnotify.pushover.Client.notify not splitting messages properly.

Comments (0)

Files changed (2)

pushnotify/pushover.py

         """
 
         def send_notify(desc_list, event, kwargs, apikey, device_key=''):
-            data = {'token': self.developerkey,
-                    'user': apikey,
-                    'title': event,
-                    'message': description,
-                    'timestamp': int(time.time())}
+            status = True
 
-            if device_key:
-                data['device'] = device_key
+            for description in desc_list:
+                data = {'token': self.developerkey,
+                        'user': apikey,
+                        'title': event,
+                        'message': description,
+                        'timestamp': int(time.time())}
 
-            if kwargs:
-                data.update(kwargs)
+                if device_key:
+                    data['device'] = device_key
 
-            response = self._post(self._urls['notify'], data)
-            status = self._parse_response_stream(response)
+                if kwargs:
+                    data.update(kwargs)
 
-            return not status
+                response_stream = self._post(self._urls['notify'], data)
+                this_status = self._parse_response_stream(response_stream)
+
+                status = status and this_status
+
+            return status
 
         if not self.apikeys:
             self.logger.warn('notify called with no users set')
+            return
 
         desc_list = []
         if split:
         # raise a single exception if and only if every notification
         # fails
 
-        raise_exception = True
+        all_ok = True
 
         for apikey, device_keys in self.apikeys.items():
             if not device_keys:
-                this_raise_exception = send_notify(desc_list, event, kwargs,
+                this_ok = send_notify(desc_list, event, kwargs,
                                                    apikey)
             else:
                 for device_key in device_keys:
-                    this_raise_exception = send_notify(
+                    this_ok = send_notify(
                         desc_list, event, kwargs, apikey, device_key)
 
-            raise_exception = raise_exception and this_raise_exception
+            all_ok = all_ok and this_ok
 
-        if raise_exception:
+        if not all_ok:
             self._raise_exception()
 
     def verify_user(self, apikey):

pushnotify/tests/tests.py

                            kwargs={'priority': 1, 'url': 'http://google.com/',
                                    'url_title': 'Google'})
 
+    def test_notify_valid_split(self):
+        """Test notify with a valid notification, splitting up a long
+        description.
+
+        """
+
+        long_desc = 'a' * 513
+        self.client.notify(long_desc, self.event, split=True)
+
     def test_notify_invalid_developerkey(self):
         """Test notify with an invalid developer key.