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


Python Mock.hostname方法代码示例

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


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

示例1: test_process_statistics

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import hostname [as 别名]
    def test_process_statistics(self, mock_update_client):
        metadata = self.load_clients_data(metadata=self.load_groups_data())
        md = Mock()
        md.hostname = "client6"
        metadata.process_statistics(md, None)
        mock_update_client.assert_called_with(md.hostname, dict(auth="cert"))

        mock_update_client.reset_mock()
        md.hostname = "client5"
        metadata.process_statistics(md, None)
        self.assertFalse(mock_update_client.called)
开发者ID:seacoastboy,项目名称:bcfg2,代码行数:13,代码来源:TestMetadata.py

示例2: test__write_data_db

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import hostname [as 别名]
    def test__write_data_db(self):
        syncdb(TestProbesDB)
        Bcfg2.Options.setup.probes_db = True
        probes = self.get_obj()
        probes.probedata = self.get_test_probedata()
        probes.cgroups = self.get_test_cgroups()

        for cname in ["foo.example.com", "bar.example.com"]:
            client = Mock()
            client.hostname = cname
            probes._write_data_db(client)

            pdata = ProbesDataModel.objects.filter(hostname=cname).all()
            self.assertEqual(len(pdata), len(probes.probedata[cname]))

            for probe in pdata:
                self.assertEqual(probe.hostname, client.hostname)
                self.assertIsNotNone(probe.data)
                if probe.probe == "xml":
                    xdata = lxml.etree.XML(probe.data)
                    self.assertIsNotNone(xdata)
                    self.assertIsNotNone(xdata.find("test"))
                    self.assertEqual(xdata.find("test").get("foo"), "foo")
                elif probe.probe == "text":
                    pass
                elif probe.probe == "multiline":
                    self.assertGreater(len(probe.data.splitlines()), 1)
                elif probe.probe == "empty":
                    self.assertEqual(probe.data, "")
                elif probe.probe == "yaml":
                    self.assertItemsEqual(test_data, yaml.load(probe.data))
                elif probe.probe == "json":
                    self.assertItemsEqual(test_data, json.loads(probe.data))
                else:
                    assert False, "Strange probe found in _write_data_db data"

            pgroups = ProbesGroupsModel.objects.filter(hostname=cname).all()
            self.assertEqual(len(pgroups), len(probes.cgroups[cname]))

        # test that old probe data is removed properly
        cname = 'foo.example.com'
        del probes.probedata[cname]['text']
        probes.cgroups[cname].pop()
        client = Mock()
        client.hostname = cname
        probes._write_data_db(client)

        pdata = ProbesDataModel.objects.filter(hostname=cname).all()
        self.assertEqual(len(pdata), len(probes.probedata[cname]))
        pgroups = ProbesGroupsModel.objects.filter(hostname=cname).all()
        self.assertEqual(len(pgroups), len(probes.cgroups[cname]))
开发者ID:dhutty,项目名称:bcfg2,代码行数:53,代码来源:TestProbes.py

示例3: test_get_additional_data

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import hostname [as 别名]
 def test_get_additional_data(self):
     probes = self.get_probes_object()
     test_probedata = self.get_test_probedata()
     probes.probedata = self.get_test_probedata()
     for cname in test_probedata.keys():
         metadata = Mock()
         metadata.hostname = cname
         self.assertEqual(test_probedata[cname],
                          probes.get_additional_data(metadata))
     # test a non-existent client
     metadata = Mock()
     metadata.hostname = "nonexistent"
     self.assertEqual(probes.get_additional_data(metadata),
                      ClientProbeDataSet())
开发者ID:stpierre,项目名称:bcfg2,代码行数:16,代码来源:TestProbes.py

示例4: test_get_additional_groups

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import hostname [as 别名]
 def test_get_additional_groups(self):
     probes = self.get_probes_object()
     test_cgroups = self.get_test_cgroups()
     probes.cgroups = self.get_test_cgroups()
     for cname in test_cgroups.keys():
         metadata = Mock()
         metadata.hostname = cname
         self.assertEqual(test_cgroups[cname],
                          probes.get_additional_groups(metadata))
     # test a non-existent client
     metadata = Mock()
     metadata.hostname = "nonexistent"
     self.assertEqual(probes.get_additional_groups(metadata),
                      list())
开发者ID:stpierre,项目名称:bcfg2,代码行数:16,代码来源:TestProbes.py

示例5: virtual

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import hostname [as 别名]
 def virtual(target, builder, svc, resource_helper):
     bigip = Mock()
     builder.mock_get_all_bigips(target, return_value=[bigip])
     va = Mock()
     va.load.return_value = va
     va.name = svc['loadbalancer']['id']
     vses = Mock()
     vses.get_resources.return_value = [vses]
     bigip_resource_helpers_returns = [va, vses, va]
     resource_helper.side_effect = bigip_resource_helpers_returns
     tenant_id = svc['loadbalancer']['tenant_id']
     lb_id = svc['loadbalancer']['id']
     hostnames = ['foobyyou']
     bigip.hostname = hostnames[0]
     builder.mock__init_bigips(target)
     vses.destination = "/{}{}/{}".format(
         target.service_adapter.prefix, tenant_id, va.name)
     delattr(vses, 'pool')
     target.purge_orphaned_loadbalancer(
         tenant_id=tenant_id, loadbalancer_id=lb_id,
         hostnames=hostnames)
     builder.check_mocks(target)
     assert resource_helper.call_count == 3
     assert vses.delete.call_count
     assert va.delete.call_count
开发者ID:jputrino,项目名称:f5-openstack-agent,代码行数:27,代码来源:test_icontrol_driver.py

示例6: test__load_data_db

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import hostname [as 别名]
    def test__load_data_db(self):
        syncdb(TestProbesDB)
        Bcfg2.Options.setup.probes_db = True
        probes = self.get_obj()
        probes.probedata = self.get_test_probedata()
        probes.cgroups = self.get_test_cgroups()
        for cname in probes.probedata.keys():
            client = Mock()
            client.hostname = cname
            probes._write_data_db(client)

        probes.probedata = dict()
        probes.cgroups = dict()
        probes._load_data_db()
        self.assertItemsEqual(probes.probedata, self.get_test_probedata())
        # the db backend does not store groups at all if a client has
        # no groups set, so we can't just use assertItemsEqual here,
        # because loading saved data may _not_ result in the original
        # data if some clients had no groups set.
        test_cgroups = self.get_test_cgroups()
        for cname, groups in test_cgroups.items():
            if cname in probes.cgroups:
                self.assertEqual(groups, probes.cgroups[cname])
            else:
                self.assertEqual(groups, [])
开发者ID:dhutty,项目名称:bcfg2,代码行数:27,代码来源:TestProbes.py

示例7: test_ReceiveData

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import hostname [as 别名]
    def test_ReceiveData(self, mock_ReceiveDataItem, mock_write_data):
        # we use a simple (read: bogus) datalist here to make this
        # easy to test
        datalist = ["a", "b", "c"]

        probes = self.get_probes_object()
        probes.core.metadata_cache_mode = 'off'
        client = Mock()
        client.hostname = "foo.example.com"
        probes.ReceiveData(client, datalist)

        cgroups = []
        cprobedata = ClientProbeDataSet()
        self.assertItemsEqual(mock_ReceiveDataItem.call_args_list,
                              [call(client, "a", cgroups, cprobedata),
                               call(client, "b", cgroups, cprobedata),
                               call(client, "c", cgroups, cprobedata)])
        mock_write_data.assert_called_with(client)
        self.assertFalse(probes.core.metadata_cache.expire.called)

        # change the datalist, ensure that the cache is cleared
        probes.cgroups[client.hostname] = datalist
        probes.core.metadata_cache_mode = 'aggressive'
        probes.ReceiveData(client, ['a', 'b', 'd'])

        mock_write_data.assert_called_with(client)
        probes.core.metadata_cache.expire.assert_called_with(client.hostname)
开发者ID:PhilMiller,项目名称:bcfg2,代码行数:29,代码来源:TestProbes.py

示例8: test_save

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import hostname [as 别名]
    def test_save(self, mock_dump, mock_open):
        core = Mock()
        ts = self.get_obj(core)
        queue = Mock()
        queue.empty = Mock(side_effect=Empty)
        ts.work_queue = queue

        mock_open.side_effect = IOError
        # test that save does _not_ raise an exception even when
        # everything goes pear-shaped
        ts._save()
        queue.empty.assert_any_call()
        mock_open.assert_called_with(ts.pending_file, 'w')

        queue.reset_mock()
        mock_open.reset_mock()

        queue.data = []
        for hostname, xml in self.data:
            md = Mock()
            md.hostname = hostname
            queue.data.append((md, lxml.etree.XML(xml)))
        queue.empty.side_effect = lambda: len(queue.data) == 0
        queue.get_nowait = Mock(side_effect=lambda: queue.data.pop())
        mock_open.side_effect = None

        ts._save()
        queue.empty.assert_any_call()
        queue.get_nowait.assert_any_call()
        mock_open.assert_called_with(ts.pending_file, 'w')
        mock_open.return_value.close.assert_any_call()
        # the order of the queue data gets changed, so we have to
        # verify this call in an ugly way
        self.assertItemsEqual(mock_dump.call_args[0][0], self.data)
        self.assertEqual(mock_dump.call_args[0][1], mock_open.return_value)
开发者ID:psteinbachs,项目名称:bcfg2,代码行数:37,代码来源:Testinterfaces.py

示例9: test_ReceiveDataItem

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import hostname [as 别名]
    def test_ReceiveDataItem(self):
        probes = self.get_probes_object()
        for cname, cdata in self.get_test_probedata().items():
            client = Mock()
            client.hostname = cname
            for pname, pdata in cdata.items():
                dataitem = lxml.etree.Element("Probe", name=pname)
                if pname == "text":
                    # add some groups to the plaintext test to test
                    # group parsing
                    data = [pdata]
                    for group in self.get_test_cgroups()[cname]:
                        data.append("group:%s" % group)
                    dataitem.text = "\n".join(data)
                else:
                    dataitem.text = str(pdata)

                probes.ReceiveDataItem(client, dataitem)
                
                self.assertIn(client.hostname, probes.probedata)
                self.assertIn(pname, probes.probedata[cname])
                self.assertEqual(pdata, probes.probedata[cname][pname])
            self.assertIn(client.hostname, probes.cgroups)
            self.assertEqual(probes.cgroups[cname],
                             self.get_test_cgroups()[cname])
开发者ID:ab,项目名称:bcfg2,代码行数:27,代码来源:TestProbes.py

示例10: _get_mock_segment

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import hostname [as 别名]
 def _get_mock_segment(self, name, datadir, port, hostname, address):
     m = Mock()
     m.name = name
     m.datadir = datadir
     m.port = port
     m.hostname = hostname
     m.address = address
     return m
开发者ID:PengJi,项目名称:gpdb-comments,代码行数:10,代码来源:test_unit_unix.py

示例11: error

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import hostname [as 别名]
 def error(target, svc, builder, resource_helper, logger, error):
     bigip = Mock()
     hostnames = ['foodoozoo']
     bigip.hostname = hostnames[0]
     builder.mock_get_all_bigips(target, return_value=[bigip])
     li_id = svc['healthmonitors'][0]['id']
     t_id = svc['healthmonitors'][0]['tenant_id']
     resource_helper.return_value.load.side_effect = error
     target.purge_orphaned_health_monitor(t_id, li_id, hostnames)
开发者ID:jputrino,项目名称:f5-openstack-agent,代码行数:11,代码来源:test_icontrol_driver.py

示例12: setUp

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import hostname [as 别名]
    def setUp(self):
        mock_host_rpm_builder = Mock(HostRpmBuilder)
        mock_host_rpm_builder.host_config_dir = 'host configuration directory'
        mock_host_rpm_builder.variables_dir = 'variables directory'
        mock_host_rpm_builder.hostname = 'devweb01'
        mock_host_rpm_builder.output_file_path = '/path/to/output/file'
        mock_host_rpm_builder.error_file_path = '/path/to/error/file'

        self.mock_host_rpm_builder = mock_host_rpm_builder
开发者ID:yadt,项目名称:yadt-config-rpm-maker,代码行数:11,代码来源:hostrpmbuilder_test.py

示例13: test_should_lock_host

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import hostname [as 别名]
    def test_should_lock_host(self):
        mock_host = Mock(yadtshell.components.Host)
        mock_host.hostname = 'foobar42.domain'

        yadtshell.components.Host.lock(
            mock_host, message='lock me!', force=False)

        mock_host.remote_call.assert_called_with(
            "yadt-host-lock 'lock me!'", 'lock_host', False)
开发者ID:yadt,项目名称:yadtshell,代码行数:11,代码来源:components_tests.py

示例14: __init__

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import hostname [as 别名]
 def __init__(self):
     self.SLEEP_TIME = 0
     bs = Mock()
     args = Mock()
     args.hostname = 'test_hostname'
     args.platform = 'test_platform'
     args.status_file = None
     args.timeout = 100
     Worker.__init__(self, bs, args)
开发者ID:cpcloud,项目名称:binstar-build,代码行数:11,代码来源:test_worker.py

示例15: main_path

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import hostname [as 别名]
 def main_path(target, builder, svc, resource_helper):
     bigip = Mock()
     hostnames = ['foodoozoo']
     bigip.hostname = hostnames[0]
     builder.mock_get_all_bigips(target, return_value=[bigip])
     li_id = svc['healthmonitors'][0]['id']
     t_id = svc['healthmonitors'][0]['tenant_id']
     target.purge_orphaned_health_monitor(t_id, li_id, hostnames)
     builder.check_mocks(target)
     assert resource_helper.return_value.load.call_count
     assert resource_helper.call_count == 4
开发者ID:jputrino,项目名称:f5-openstack-agent,代码行数:13,代码来源:test_icontrol_driver.py


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