当前位置: 首页>>代码示例>>Python>>正文


Python StandaloneAuthenticator.subproc_signal_handler方法代码示例

本文整理汇总了Python中letsencrypt.plugins.standalone.authenticator.StandaloneAuthenticator.subproc_signal_handler方法的典型用法代码示例。如果您正苦于以下问题:Python StandaloneAuthenticator.subproc_signal_handler方法的具体用法?Python StandaloneAuthenticator.subproc_signal_handler怎么用?Python StandaloneAuthenticator.subproc_signal_handler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在letsencrypt.plugins.standalone.authenticator.StandaloneAuthenticator的用法示例。


在下文中一共展示了StandaloneAuthenticator.subproc_signal_handler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SubprocSignalHandlerTest

# 需要导入模块: from letsencrypt.plugins.standalone.authenticator import StandaloneAuthenticator [as 别名]
# 或者: from letsencrypt.plugins.standalone.authenticator.StandaloneAuthenticator import subproc_signal_handler [as 别名]
class SubprocSignalHandlerTest(unittest.TestCase):
    """Tests for subproc_signal_handler() method."""
    def setUp(self):
        from letsencrypt.plugins.standalone.authenticator import \
            StandaloneAuthenticator
        self.authenticator = StandaloneAuthenticator(config=CONFIG, name=None)
        self.authenticator.tasks = {"foononce.acme.invalid": "stuff"}
        self.authenticator.child_pid = 12345
        self.authenticator.parent_pid = 23456

    @mock.patch("letsencrypt.plugins.standalone.authenticator.os.kill")
    @mock.patch("letsencrypt.plugins.standalone.authenticator.sys.exit")
    def test_subproc_signal_handler(self, mock_exit, mock_kill):
        self.authenticator.ssl_conn = mock.MagicMock()
        self.authenticator.connection = mock.MagicMock()
        self.authenticator.sock = mock.MagicMock()
        self.authenticator.subproc_signal_handler(signal.SIGINT, None)
        self.assertEquals(self.authenticator.ssl_conn.shutdown.call_count, 1)
        self.assertEquals(self.authenticator.ssl_conn.close.call_count, 1)
        self.assertEquals(self.authenticator.connection.close.call_count, 1)
        self.assertEquals(self.authenticator.sock.close.call_count, 1)
        mock_kill.assert_called_once_with(
            self.authenticator.parent_pid, signal.SIGUSR1)
        mock_exit.assert_called_once_with(0)

    @mock.patch("letsencrypt.plugins.standalone.authenticator.os.kill")
    @mock.patch("letsencrypt.plugins.standalone.authenticator.sys.exit")
    def test_subproc_signal_handler_trouble(self, mock_exit, mock_kill):
        """Test attempting to shut down a non-existent connection.

        (This could occur because none was established or active at the
        time the signal handler tried to perform the cleanup)."""
        self.authenticator.ssl_conn = mock.MagicMock()
        self.authenticator.connection = mock.MagicMock()
        self.authenticator.sock = mock.MagicMock()
        # AttributeError simulates the case where one of these properties
        # is None because no connection exists.  We raise it for
        # ssl_conn.close() instead of ssl_conn.shutdown() for better code
        # coverage.
        self.authenticator.ssl_conn.close.side_effect = AttributeError("!")
        self.authenticator.connection.close.side_effect = AttributeError("!")
        self.authenticator.sock.close.side_effect = AttributeError("!")
        self.authenticator.subproc_signal_handler(signal.SIGINT, None)
        self.assertEquals(self.authenticator.ssl_conn.shutdown.call_count, 1)
        self.assertEquals(self.authenticator.ssl_conn.close.call_count, 1)
        self.assertEquals(self.authenticator.connection.close.call_count, 1)
        self.assertEquals(self.authenticator.sock.close.call_count, 1)
        mock_kill.assert_called_once_with(
            self.authenticator.parent_pid, signal.SIGUSR1)
        mock_exit.assert_called_once_with(0)
开发者ID:mommel,项目名称:lets-encrypt-preview,代码行数:52,代码来源:authenticator_test.py


注:本文中的letsencrypt.plugins.standalone.authenticator.StandaloneAuthenticator.subproc_signal_handler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。