Add SupportedChallengesValidatorTest.

This commit is contained in:
Jakub Warmuz
2015-10-04 20:24:53 +00:00
parent 94c6e307c9
commit 1774ab64c4
2 changed files with 33 additions and 2 deletions
+6 -2
View File
@@ -115,7 +115,11 @@ SUPPORTED_CHALLENGES = set([challenges.DVSNI, challenges.SimpleHTTP])
def supported_challenges_validator(data):
"""Supported challenges validator."""
"""Supported challenges validator for the `argparse`.
It should be passed as `type` argument to `add_argument`.
"""
challs = data.split(",")
unrecognized = [name for name in challs
if name not in challenges.Challenge.TYPES]
@@ -127,7 +131,7 @@ def supported_challenges_validator(data):
if not set(challs).issubset(choices):
raise argparse.ArgumentTypeError(
"Plugin does not support the following (valid) "
"challenges: {0}".format(", ".join(challs - choices)))
"challenges: {0}".format(", ".join(set(challs) - choices)))
return data
+27
View File
@@ -1,4 +1,5 @@
"""Tests for letsencrypt.plugins.standalone."""
import argparse
import socket
import unittest
@@ -63,6 +64,28 @@ class ServerManagerTest(unittest.TestCase):
self.assertEqual(self.mgr.running(), {})
class SupportedChallengesValidatorTest(unittest.TestCase):
"""Tests for plugins.standalone.supported_challenges_validator."""
def _call(self, data):
from letsencrypt.plugins.standalone import (
supported_challenges_validator)
return supported_challenges_validator(data)
def test_correct(self):
self.assertEqual("dvsni", self._call("dvsni"))
self.assertEqual("simpleHttp", self._call("simpleHttp"))
self.assertEqual("dvsni,simpleHttp", self._call("dvsni,simpleHttp"))
self.assertEqual("simpleHttp,dvsni", self._call("simpleHttp,dvsni"))
def test_unrecognized(self):
assert "foo" not in challenges.Challenge.TYPES
self.assertRaises(argparse.ArgumentTypeError, self._call, "foo")
def test_not_subset(self):
self.assertRaises(argparse.ArgumentTypeError, self._call, "dns")
class AuthenticatorTest(unittest.TestCase):
"""Tests for letsencrypt.plugins.standalone.Authenticator."""
@@ -72,6 +95,10 @@ class AuthenticatorTest(unittest.TestCase):
standalone_supported_challenges="dvsni,simpleHttp")
self.auth = Authenticator(self.config, name="standalone")
def test_supported_challenges(self):
self.assertEqual(self.auth.supported_challenges,
set([challenges.DVSNI, challenges.SimpleHTTP]))
def test_more_info(self):
self.assertTrue(isinstance(self.auth.more_info(), six.string_types))