本文整理汇总了Python中status.Status.set_hostname方法的典型用法代码示例。如果您正苦于以下问题:Python Status.set_hostname方法的具体用法?Python Status.set_hostname怎么用?Python Status.set_hostname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类status.Status
的用法示例。
在下文中一共展示了Status.set_hostname方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestStatusClass
# 需要导入模块: from status import Status [as 别名]
# 或者: from status.Status import set_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)
'''