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


Python Status.get_hostname方法代碼示例

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


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

示例1: TestStatusClass

# 需要導入模塊: from status import Status [as 別名]
# 或者: from status.Status import get_hostname [as 別名]
class TestStatusClass(unittest.TestCase):

    @patch("status.sh")
    def setUp(self, mock_sh):
        self.root_path = os.path.abspath(os.path.dirname(__file__) + "/../")
        self.name = "status"
        self.bundle = Status(name="status", path=self.root_path)

    def tearDown(self):
        self.bundle = None
        try:
            os.remove("%s/data/%s.json" % (dirpath, self.name))
        except OSError:
            pass

        try:
            os.remove("%s/data/%s.json.backup" % (dirpath, self.name))
        except OSError:
            pass

    @patch("socket.gethostname")
    def test__get_hostname(self, mock_gethostname):
        """
        get_hostname
        """
        mock_gethostname.return_value = "moxa"
        hostname = self.bundle.get_hostname()
        self.assertEqual(hostname, "moxa")

    @patch("socket.gethostname")
    def test__get_hostname__failed(self, mock_gethostname):
        """
        get_hostname: failed
        """
        mock_gethostname.side_effect = OSError
        hostname = self.bundle.get_hostname()
        self.assertEqual(hostname, "")

    @patch("sh.sed")
    @patch("sh.echo")
    @patch("sh.hostname")
    def test__set_hostname(self, mock_sethostname, mock_echo, mock_sed):
        """
        set_hostname
        """
        self.bundle.set_hostname("test")

    @patch("sh.sed")
    @patch("sh.echo")
    @patch("sh.hostname")
    def test__set_hostname_failed(self, mock_sethostname, mock_echo, mock_sed):
        """
        set_hostname: failed
        """
        mock_sethostname.side_effect = OSError
        with self.assertRaises(OSError):
            self.bundle.set_hostname("test")

    @patch("status.sh")
    def test__get_product_version(self, mock_sh):
        """
        get_product_version
        """
        mock_sh.pversion.return_value = PVERSION_INFO
        version = self.bundle.get_product_version()
        self.assertEqual(VERSION_INFO, version)

    @patch("status.sh")
    def test__get_product_version__failed(self, mock_sh):
        """
        get_product_version: failed
        """
        mock_sh.pversion.side_effect = OSError
        version = self.bundle.get_product_version()
        self.assertEqual("(not installed)", version)

    def test__get_password(self):
        """
        get_password
        """
        with tempfile.NamedTemporaryFile() as temp:
            temp.write("moxa:$6$Hs/8c4S4$gBHEMrckbK9dpFJ0xrrO07TecyKNgTeB2Q69PKwFuuZC47W0k7zdWyF115efj9c5UmpxjB.iz.sW/QbhEYER1/:16247:0:99999:7:::")  # noqa
            temp.flush()
            passhash = get_password("moxa", temp.name)
            self.assertEqual(passhash, "$6$Hs/8c4S4$gBHEMrckbK9dpFJ0xrrO07TecyKNgTeB2Q69PKwFuuZC47W0k7zdWyF115efj9c5UmpxjB.iz.sW/QbhEYER1/")  # noqa

    @patch("status.usermod")
    def test__set_password(self, mock_usermod):
        """
        set_password
        """
        set_password("moxa", "user")
        mock_usermod.called_args
        self.assertTrue(mock_usermod.called)
    '''
開發者ID:Sanji-IO,項目名稱:sanji-bundle-status,代碼行數:97,代碼來源:test_status.py


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