commit f5be372df769be8934ac6666e1433e3b92718eab Author: Isis Lovecruft isis@torproject.org Date: Wed May 14 20:41:00 2014 +0000
Simplify GimpCaptchaKeyError and ReCaptchaKeyError into CaptchaKeyError.
* REMOVE exception class captcha.GimpCaptchaKeyError. * REMOVE exception class captcha.ReCaptchaKeyError. * ADD exception class captcha.CaptchaKeyError. --- lib/bridgedb/captcha.py | 17 +++++++---------- lib/bridgedb/test/test_captcha.py | 16 ++++++++-------- 2 files changed, 15 insertions(+), 18 deletions(-)
diff --git a/lib/bridgedb/captcha.py b/lib/bridgedb/captcha.py index 0018988..15f1083 100644 --- a/lib/bridgedb/captcha.py +++ b/lib/bridgedb/captcha.py @@ -68,15 +68,12 @@ from bridgedb import crypto from bridgedb.txrecaptcha import API_SSL_SERVER
-class ReCaptchaKeyError(Exception): - """Exception raised when recaptcha API keys are not supplied.""" +class CaptchaKeyError(Exception): + """Raised if a CAPTCHA system's keys are invalid or missing."""
class GimpCaptchaError(Exception): """General exception raised when a Gimp CAPTCHA cannot be retrieved."""
-class GimpCaptchaKeyError(ValueError): - """Raised when there is a problem with one of the Gimp CAPTCHA keys.""" -
class ICaptcha(Interface): """Interface specification for CAPTCHAs.""" @@ -135,12 +132,12 @@ class ReCaptcha(Captcha): stored at ``ReCaptcha.image`` and the challenge string at ``ReCaptcha.challenge``.
- :raises ReCaptchaKeyError: If either the :ivar:`pubkey` or - :ivar:`privkey` are missing. + :raises CaptchaKeyError: If either the :ivar:`publicKey` or + :ivar:`secretKey` are missing. :raises HTTPError: If the server returned any HTTP error status code. """ if not self.pubkey or not self.privkey: - raise ReCaptchaKeyError('You must supply recaptcha API keys') + raise CaptchaKeyError('You must supply recaptcha API keys')
urlbase = API_SSL_SERVER form = "/noscript?k=%s" % self.pubkey @@ -173,7 +170,7 @@ class GimpCaptcha(Captcha): images have been stored in. This can be set via the ``GIMP_CAPTCHA_DIR`` setting in the config file. :raises GimpCaptchaError: if **cacheDir** is not a directory. - :raises GimpCaptchaKeyError: if any of **secretKey**, **publicKey**, + :raises CaptchaKeyError: if any of **secretKey**, **publicKey**, or **hmacKey** is invalid, or missing. """ super(GimpCaptcha, self).__init__() @@ -182,7 +179,7 @@ class GimpCaptcha(Captcha): raise GimpCaptchaError("Gimp captcha cache isn't a directory: %r" % cacheDir) if not (publicKey and secretKey and hmacKey): - raise GimpCaptchaKeyError( + raise CaptchaKeyError( "Invalid key supplied to GimpCaptcha: SK=%r PK=%r HMAC=%r" % (secretKey, publicKey, hmacKey))
diff --git a/lib/bridgedb/test/test_captcha.py b/lib/bridgedb/test/test_captcha.py index 7a6f2c4..a383545 100644 --- a/lib/bridgedb/test/test_captcha.py +++ b/lib/bridgedb/test/test_captcha.py @@ -88,7 +88,7 @@ class ReCaptchaTests(unittest.TestCase): def test_get_noKeys(self): """ReCaptcha.get() without API keys should fail.""" c = captcha.ReCaptcha() - self.assertRaises(captcha.ReCaptchaKeyError, c.get) + self.assertRaises(captcha.CaptchaKeyError, c.get)
class GimpCaptchaTests(unittest.TestCase): @@ -106,23 +106,23 @@ class GimpCaptchaTests(unittest.TestCase):
def test_init_noSecretKey(self): """Calling GimpCaptcha.__init__() without a secret key parameter should raise - a GimpCaptchaKeyError. + a CaptchaKeyError. """ - self.assertRaises(captcha.GimpCaptchaKeyError, captcha.GimpCaptcha, + self.assertRaises(captcha.CaptchaKeyError, captcha.GimpCaptcha, None, self.publik, self.hmacKey, self.cacheDir)
def test_init_noPublicKey(self): - """__init__() without publicKey should raise a GimpCaptchaKeyError.""" - self.assertRaises(captcha.GimpCaptchaKeyError, captcha.GimpCaptcha, + """__init__() without publicKey should raise a CaptchaKeyError.""" + self.assertRaises(captcha.CaptchaKeyError, captcha.GimpCaptcha, self.sekrit, None, self.hmacKey, self.cacheDir)
def test_init_noHMACKey(self): - """__init__() without hmacKey should raise a GimpCaptchaKeyError.""" - self.assertRaises(captcha.GimpCaptchaKeyError, captcha.GimpCaptcha, + """__init__() without hmacKey should raise a CaptchaKeyError.""" + self.assertRaises(captcha.CaptchaKeyError, captcha.GimpCaptcha, self.sekrit, self.publik, None, self.cacheDir)
def test_init_noCacheDir(self): - """__init__() without cacheDir should raise a GimpCaptchaKeyError.""" + """__init__() without cacheDir should raise a CaptchaKeyError.""" self.assertRaises(captcha.GimpCaptchaError, captcha.GimpCaptcha, self.sekrit, self.publik, self.hmacKey, None)