當前位置: 首頁>>代碼示例>>Python>>正文


Python DnstestConfig.conf_file方法代碼示例

本文整理匯總了Python中pydnstest.config.DnstestConfig.conf_file方法的典型用法代碼示例。如果您正苦於以下問題:Python DnstestConfig.conf_file方法的具體用法?Python DnstestConfig.conf_file怎麽用?Python DnstestConfig.conf_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pydnstest.config.DnstestConfig的用法示例。


在下文中一共展示了DnstestConfig.conf_file方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_promptconfig_no_confirm

# 需要導入模塊: from pydnstest.config import DnstestConfig [as 別名]
# 或者: from pydnstest.config.DnstestConfig import conf_file [as 別名]
    def test_promptconfig_no_confirm(self, capfd):
        dc = DnstestConfig()
        dc.conf_file = '/foo/bar/baz'

        def prompt_input_se(prompt, default=None, validate_cb=None):
            ret = {
                "Production DNS Server IP": '1.2.3.4',
                "Test/Staging DNS Server IP": '5.6.7.8',
                "Check for reverse DNS by default? [Y|n]": True,
                "Default domain for to append to any input that appears to be less than a FQDN (blank for none)": 'example.com',
                "Ignore difference in TTL when comparing responses? [y|N]": False,
                "Sleep between DNS record tests (seconds)": 0.0,
            }
            return ret[prompt]
        prompt_input_mock = mock.MagicMock(side_effect=prompt_input_se)

        confirm_response_mock = mock.MagicMock()
        confirm_response_mock.return_value = False

        to_string_mock = mock.MagicMock()
        to_string_mock.return_value = 'foo bar baz'

        write_mock = mock.MagicMock()
        write_mock.return_value = True

        with mock.patch('pydnstest.config.DnstestConfig.prompt_input', prompt_input_mock):
            with mock.patch('pydnstest.config.DnstestConfig.to_string', to_string_mock):
                with mock.patch('pydnstest.config.DnstestConfig.confirm_response', confirm_response_mock):
                    with mock.patch('pydnstest.config.DnstestConfig.write', write_mock):
                        with pytest.raises(SystemExit) as excinfo:
                            dc.prompt_config()
        assert excinfo.value.code == "Exiting on user request. No configuration written."
        assert prompt_input_mock.call_count == 6
        assert prompt_input_mock.call_args_list == [
            mock.call("Production DNS Server IP", validate_cb=dc.validate_ipaddr),
            mock.call("Test/Staging DNS Server IP", validate_cb=dc.validate_ipaddr),
            mock.call("Check for reverse DNS by default? [Y|n]", default=True, validate_cb=dc.validate_bool),
            mock.call("Default domain for to append to any input that appears to be less than a FQDN (blank for none)", default=''),
            mock.call("Ignore difference in TTL when comparing responses? [y|N]", default=False, validate_cb=dc.validate_bool),
            mock.call("Sleep between DNS record tests (seconds)", default=0.0, validate_cb=dc.validate_float),
        ]
        assert to_string_mock.call_count == 1
        assert confirm_response_mock.call_count == 1
        assert write_mock.call_count == 0
        out, err = capfd.readouterr()
        assert out == "Configuration:\n#####################\nfoo bar baz\n#####################\n\n"
        assert err == ""
        assert dc.server_prod == '1.2.3.4'
        assert dc.server_test == '5.6.7.8'
        assert dc.have_reverse_dns == True
        assert dc.default_domain == 'example.com'
        assert dc.ignore_ttl == False
        assert dc.sleep == 0.0
開發者ID:,項目名稱:,代碼行數:55,代碼來源:


注:本文中的pydnstest.config.DnstestConfig.conf_file方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。