Exemplo n.º 1
0
 def test_find_all(self):
     from letsencrypt.plugins.disco import PluginsRegistry
     with mock.patch("letsencrypt.plugins.disco.pkg_resources") as mock_pkg:
         mock_pkg.iter_entry_points.return_value = iter([EP_SA])
         plugins = PluginsRegistry.find_all()
     self.assertTrue(plugins["sa"].plugin_cls is standalone.Authenticator)
     self.assertTrue(plugins["sa"].entry_point is EP_SA)
Exemplo n.º 2
0
 def test_find_all(self):
     from letsencrypt.plugins.disco import PluginsRegistry
     with mock.patch("letsencrypt.plugins.disco.pkg_resources") as mock_pkg:
         mock_pkg.iter_entry_points.return_value = iter([EP_SA])
         plugins = PluginsRegistry.find_all()
     self.assertTrue(plugins["sa"].plugin_cls is standalone.Authenticator)
     self.assertTrue(plugins["sa"].entry_point is EP_SA)
Exemplo n.º 3
0
 def setUp(self):
     from letsencrypt.plugins.disco import PluginsRegistry
     self.plugin_ep = mock.MagicMock(name="mock")
     self.plugin_ep.__hash__.side_effect = TypeError
     self.plugins = {"mock": self.plugin_ep}
     self.reg = PluginsRegistry(self.plugins)
Exemplo n.º 4
0
class PluginsRegistryTest(unittest.TestCase):
    """Tests for letsencrypt.plugins.disco.PluginsRegistry."""
    def setUp(self):
        from letsencrypt.plugins.disco import PluginsRegistry
        self.plugin_ep = mock.MagicMock(name="mock")
        self.plugin_ep.__hash__.side_effect = TypeError
        self.plugins = {"mock": self.plugin_ep}
        self.reg = PluginsRegistry(self.plugins)

    def test_find_all(self):
        from letsencrypt.plugins.disco import PluginsRegistry
        with mock.patch("letsencrypt.plugins.disco.pkg_resources") as mock_pkg:
            mock_pkg.iter_entry_points.return_value = iter([EP_SA])
            plugins = PluginsRegistry.find_all()
        self.assertTrue(plugins["sa"].plugin_cls is standalone.Authenticator)
        self.assertTrue(plugins["sa"].entry_point is EP_SA)

    def test_getitem(self):
        self.assertEqual(self.plugin_ep, self.reg["mock"])

    def test_iter(self):
        self.assertEqual(["mock"], list(self.reg))

    def test_len(self):
        self.assertEqual(1, len(self.reg))
        self.plugins.clear()
        self.assertEqual(0, len(self.reg))

    def test_init(self):
        self.plugin_ep.init.return_value = "baz"
        self.assertEqual(["baz"], self.reg.init("bar"))
        self.plugin_ep.init.assert_called_once_with("bar")

    def test_filter(self):
        self.plugins.update({
            "foo": "bar",
            "bar": "foo",
            "baz": "boo",
        })
        self.assertEqual({
            "foo": "bar",
            "baz": "boo"
        }, self.reg.filter(lambda p_ep: str(p_ep).startswith("b")))

    def test_ifaces(self):
        self.plugin_ep.ifaces.return_value = True
        # pylint: disable=protected-access
        self.assertEqual(self.plugins, self.reg.ifaces()._plugins)
        self.plugin_ep.ifaces.return_value = False
        self.assertEqual({}, self.reg.ifaces()._plugins)

    def test_verify(self):
        self.plugin_ep.verify.return_value = True
        # pylint: disable=protected-access
        self.assertEqual(self.plugins,
                         self.reg.verify(mock.MagicMock())._plugins)
        self.plugin_ep.verify.return_value = False
        self.assertEqual({}, self.reg.verify(mock.MagicMock())._plugins)

    def test_prepare(self):
        self.plugin_ep.prepare.return_value = "baz"
        self.assertEqual(["baz"], self.reg.prepare())
        self.plugin_ep.prepare.assert_called_once_with()

    def test_available(self):
        self.plugin_ep.available = True
        # pylint: disable=protected-access
        self.assertEqual(self.plugins, self.reg.available()._plugins)
        self.plugin_ep.available = False
        self.assertEqual({}, self.reg.available()._plugins)

    def test_find_init(self):
        self.assertTrue(self.reg.find_init(mock.Mock()) is None)
        self.plugin_ep.initalized = True
        self.assertTrue(
            self.reg.find_init(self.plugin_ep.init()) is self.plugin_ep)

    def test_repr(self):
        self.plugin_ep.__repr__ = lambda _: "PluginEntryPoint#mock"
        self.assertEqual("PluginsRegistry(PluginEntryPoint#mock)",
                         repr(self.reg))

    def test_str(self):
        self.plugin_ep.__str__ = lambda _: "Mock"
        self.plugins["foo"] = "Mock"
        self.assertEqual("Mock\n\nMock", str(self.reg))
        self.plugins.clear()
        self.assertEqual("No plugins", str(self.reg))
Exemplo n.º 5
0
 def setUp(self):
     from letsencrypt.plugins.disco import PluginsRegistry
     self.plugin_ep = mock.MagicMock(name="mock")
     self.plugin_ep.__hash__.side_effect = TypeError
     self.plugins = {"mock": self.plugin_ep}
     self.reg = PluginsRegistry(self.plugins)
Exemplo n.º 6
0
class PluginsRegistryTest(unittest.TestCase):
    """Tests for letsencrypt.plugins.disco.PluginsRegistry."""

    def setUp(self):
        from letsencrypt.plugins.disco import PluginsRegistry
        self.plugin_ep = mock.MagicMock(name="mock")
        self.plugin_ep.__hash__.side_effect = TypeError
        self.plugins = {"mock": self.plugin_ep}
        self.reg = PluginsRegistry(self.plugins)

    def test_find_all(self):
        from letsencrypt.plugins.disco import PluginsRegistry
        with mock.patch("letsencrypt.plugins.disco.pkg_resources") as mock_pkg:
            mock_pkg.iter_entry_points.return_value = iter([EP_SA])
            plugins = PluginsRegistry.find_all()
        self.assertTrue(plugins["sa"].plugin_cls is standalone.Authenticator)
        self.assertTrue(plugins["sa"].entry_point is EP_SA)

    def test_getitem(self):
        self.assertEqual(self.plugin_ep, self.reg["mock"])

    def test_iter(self):
        self.assertEqual(["mock"], list(self.reg))

    def test_len(self):
        self.assertEqual(1, len(self.reg))
        self.plugins.clear()
        self.assertEqual(0, len(self.reg))

    def test_init(self):
        self.plugin_ep.init.return_value = "baz"
        self.assertEqual(["baz"], self.reg.init("bar"))
        self.plugin_ep.init.assert_called_once_with("bar")

    def test_filter(self):
        self.plugins.update({
            "foo": "bar",
            "bar": "foo",
            "baz": "boo",
        })
        self.assertEqual(
            {"foo": "bar", "baz": "boo"},
            self.reg.filter(lambda p_ep: str(p_ep).startswith("b")))

    def test_ifaces(self):
        self.plugin_ep.ifaces.return_value = True
        # pylint: disable=protected-access
        self.assertEqual(self.plugins, self.reg.ifaces()._plugins)
        self.plugin_ep.ifaces.return_value = False
        self.assertEqual({}, self.reg.ifaces()._plugins)

    def test_verify(self):
        self.plugin_ep.verify.return_value = True
        # pylint: disable=protected-access
        self.assertEqual(
            self.plugins, self.reg.verify(mock.MagicMock())._plugins)
        self.plugin_ep.verify.return_value = False
        self.assertEqual({}, self.reg.verify(mock.MagicMock())._plugins)

    def test_prepare(self):
        self.plugin_ep.prepare.return_value = "baz"
        self.assertEqual(["baz"], self.reg.prepare())
        self.plugin_ep.prepare.assert_called_once_with()

    def test_available(self):
        self.plugin_ep.available = True
        # pylint: disable=protected-access
        self.assertEqual(self.plugins, self.reg.available()._plugins)
        self.plugin_ep.available = False
        self.assertEqual({}, self.reg.available()._plugins)

    def test_find_init(self):
        self.assertTrue(self.reg.find_init(mock.Mock()) is None)
        self.plugin_ep.initalized = True
        self.assertTrue(
            self.reg.find_init(self.plugin_ep.init()) is self.plugin_ep)

    def test_repr(self):
        self.plugin_ep.__repr__ = lambda _: "PluginEntryPoint#mock"
        self.assertEqual("PluginsRegistry(PluginEntryPoint#mock)",
                         repr(self.reg))

    def test_str(self):
        self.plugin_ep.__str__ = lambda _: "Mock"
        self.plugins["foo"] = "Mock"
        self.assertEqual("Mock\n\nMock", str(self.reg))
        self.plugins.clear()
        self.assertEqual("No plugins", str(self.reg))
Exemplo n.º 7
0
 def setUp(self):
     from letsencrypt.plugins.disco import PluginsRegistry
     self.plugin_ep = mock.MagicMock(name="mock")
     self.plugins = {"mock": self.plugin_ep}
     self.reg = PluginsRegistry(self.plugins)