Jeffrey Goettsch avatar Jeffrey Goettsch committed 07e34fd

Prowl client now raises a ProviderKeyError when retrieve_token or retreive_apikey is called with a bad Provider Key.

Comments (0)

Files changed (3)


+class ProviderKeyError(PushNotifyError):
+    """Raised when a provided Provider key is invalid.
+    Args:
+        args[0]: A string containing a message from the server.
+        args[1]: An integer containing an error code from the server.
+    """
+    pass
 class RateLimitExceeded(PushNotifyError):
     """Raised when too many requests are submitted in too small a time


     def _parse_response(self, response, verify=False):
         xmlresp =
+        print 'xmlresp:', xmlresp
         root = ElementTree.fromstring(xmlresp)
         self._last_type = root[0].tag.lower()
             raise exceptions.FormatError(self._last_message,
         elif self._last_code == '401':
-            raise exceptions.ApiKeyError(self._last_message,
-                                         int(self._last_code))
+            if 'provider' not in self._last_message.lower():
+                raise exceptions.ApiKeyError(self._last_message,
+                                             int(self._last_code))
+            else:
+                raise exceptions.ProviderKeyError(self._last_message,
+                                                  int(self._last_code))
         elif self._last_code == '406':
             raise exceptions.RateLimitExceeded(self._last_message,
             token: A string containing a registration token returned
                 from the retrieve_token method.
+        Raises:
+            pushnotify.exceptions.ProviderKeyError
             A string containing the API key.
         associated a 'Retrieve success URL' with your provider key, they
         will be redirected there.
+        Raises:
+            pushnotify.exceptions.ProviderKeyError
             A two-item tuple where the first item is a string containing
             a registration token, and the second item is a string


         # invalid providerkey
         self.client.providerkey = self.client.providerkey[0:-1]
-        self.assertRaises(exceptions.ApiKeyError,
+        self.assertRaises(exceptions.ProviderKeyError,
                           self.client.retrieve_apikey, PROWL_REG_TOKEN)
     def test_retrieve_token_valid(self):
         self.client.providerkey = self.client.providerkey[0:-1]
-        self.assertRaises(exceptions.ApiKeyError,
+        self.assertRaises(exceptions.ProviderKeyError,
     def test_verify_user_valid(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.