1
0
mirror of https://github.com/certbot/certbot.git synced 2026-01-23 07:20:55 +03:00

raise ValueError instead of raw Exception

This commit is contained in:
Seth Schoen
2015-02-10 17:51:49 -08:00
parent 4d7a673887
commit 9cc7b0945b
2 changed files with 7 additions and 10 deletions

View File

@@ -273,13 +273,11 @@ class StandaloneAuthenticator(object):
if self.child_pid or self.tasks:
# We should not be willing to continue with perform
# if there were existing pending challenges.
# TODO: Specify a correct exception subclass.
raise Exception(".perform() was called with pending tasks!")
raise ValueError(".perform() was called with pending tasks!")
results_if_success = []
results_if_failure = []
if not chall_list or not isinstance(chall_list, list):
# TODO: Specify a correct exception subclass.
raise Exception(".perform() was called without challenge list")
raise ValueError(".perform() was called without challenge list")
for chall in chall_list:
if isinstance(chall, challenge_util.DvsniChall):
# We will attempt to do it
@@ -296,8 +294,7 @@ class StandaloneAuthenticator(object):
results_if_success.append(False)
results_if_failure.append(False)
if not self.tasks:
# TODO: Specify a correct exception subclass.
raise Exception("nothing for .perform() to do")
raise ValueError("nothing for .perform() to do")
# Try to do the authentication; note that this creates
# the listener subprocess via os.fork()
if self.start_listener(constants.DVSNI_CHALLENGE_PORT, key):

View File

@@ -240,18 +240,18 @@ class PerformTest(unittest.TestCase):
self.authenticator.tasks = {"foononce.acme.invalid": "cert_data"}
extra_challenge = challenge_util.DvsniChall("a", "b", "c", "d")
self.assertRaises(
Exception, self.authenticator.perform, [extra_challenge])
ValueError, self.authenticator.perform, [extra_challenge])
def test_perform_without_challenge_list(self):
extra_challenge = challenge_util.DvsniChall("a", "b", "c", "d")
# This is wrong because a challenge must be specified.
self.assertRaises(Exception, self.authenticator.perform, [])
self.assertRaises(ValueError, self.authenticator.perform, [])
# This is wrong because it must be a list, not a bare challenge.
self.assertRaises(
Exception, self.authenticator.perform, extra_challenge)
ValueError, self.authenticator.perform, extra_challenge)
# This is wrong because the list must contain at least one challenge.
self.assertRaises(
Exception, self.authenticator.perform, range(20))
ValueError, self.authenticator.perform, range(20))
class StartListenerTest(unittest.TestCase):