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


Python MagicMock.host方法代码示例

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


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

示例1: test_create

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import host [as 别名]
def test_create(async_run, project):
    compute1 = MagicMock()
    compute2 = MagicMock()

    node1 = Node(project, compute1, "node1", node_type="vpcs")
    node1._ports = [EthernetPort("E0", 0, 0, 4)]
    node2 = Node(project, compute2, "node2", node_type="vpcs")
    node2._ports = [EthernetPort("E0", 0, 3, 1)]

    @asyncio.coroutine
    def subnet_callback(compute2):
        """
        Fake subnet callback
        """
        return ("192.168.1.1", "192.168.1.2")

    compute1.get_ip_on_same_subnet.side_effect = subnet_callback

    link = UDPLink(project)
    async_run(link.add_node(node1, 0, 4))

    @asyncio.coroutine
    def compute1_callback(path, data={}, **kwargs):
        """
        Fake server
        """
        if "/ports/udp" in path:
            response = MagicMock()
            response.json = {"udp_port": 1024}
            return response

    @asyncio.coroutine
    def compute2_callback(path, data={}, **kwargs):
        """
        Fake server
        """
        if "/ports/udp" in path:
            response = MagicMock()
            response.json = {"udp_port": 2048}
            return response

    compute1.post.side_effect = compute1_callback
    compute1.host = "example.com"
    compute2.post.side_effect = compute2_callback
    compute2.host = "example.org"
    async_run(link.add_node(node2, 3, 1))

    compute1.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/nio".format(project.id, node1.id), data={
        "lport": 1024,
        "rhost": "192.168.1.2",
        "rport": 2048,
        "type": "nio_udp"
    }, timeout=120)
    compute2.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/3/ports/1/nio".format(project.id, node2.id), data={
        "lport": 2048,
        "rhost": "192.168.1.1",
        "rport": 1024,
        "type": "nio_udp"
    }, timeout=120)
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:61,代码来源:test_udp_link.py

示例2: create_mock_bridge

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import host [as 别名]
 def create_mock_bridge(self, host, allow_hue_groups=True):
     """Return a mock HueBridge with reasonable defaults."""
     mock_bridge = MagicMock()
     mock_bridge.host = host
     mock_bridge.allow_hue_groups = allow_hue_groups
     mock_bridge.lights = {}
     mock_bridge.lightgroups = {}
     return mock_bridge
开发者ID:JiShangShiDai,项目名称:home-assistant,代码行数:10,代码来源:test_hue.py

示例3: node

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import host [as 别名]
def node(project, async_run):
    compute = MagicMock()
    compute.id = "remote1"
    compute.host = "example.org"
    response = MagicMock()
    response.json = {"console": 2048}
    compute.post = AsyncioMagicMock(return_value=response)

    return async_run(project.add_node(compute, "test", None, node_type="vpcs", properties={"startup_config": "test.cfg"}))
开发者ID:GNS3,项目名称:gns3-server,代码行数:11,代码来源:test_notification.py

示例4: test_url_v2

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import host [as 别名]
 def test_url_v2(self):
     args = MagicMock()
     args.dcos_mode = False
     args.scheme = 'http'
     args.host = '127.0.0.1'
     args.port = 9005
     args.base_path = '/'
     args.api_version = '2'
     result = conduct_url.url('test', args)
     self.assertEqual('http://127.0.0.1:9005/v2/test', result)
开发者ID:fsat,项目名称:conductr-cli,代码行数:12,代码来源:test_conduct_url.py

示例5: compute

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import host [as 别名]
def compute(http_controller, async_run):
    compute = MagicMock()
    compute.id = "example.com"
    compute.host = "example.org"
    Controller.instance()._computes = {"example.com": compute}
    return compute
开发者ID:GNS3,项目名称:gns3-server,代码行数:8,代码来源:test_node.py

示例6: test_conductr_host

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import host [as 别名]
 def test_conductr_host(self):
     args = MagicMock()
     args.host = '127.0.0.1'
     result = conduct_url.conductr_host(args)
     self.assertEqual('127.0.0.1', result)
开发者ID:fsat,项目名称:conductr-cli,代码行数:7,代码来源:test_conduct_url.py

示例7: test_create_one_side_failure

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import host [as 别名]
def test_create_one_side_failure(async_run, project):
    compute1 = MagicMock()
    compute2 = MagicMock()

    node1 = Node(project, compute1, "node1", node_type="vpcs")
    node1._ports = [EthernetPort("E0", 0, 0, 4)]
    node2 = Node(project, compute2, "node2", node_type="vpcs")
    node2._ports = [EthernetPort("E0", 0, 3, 1)]

    async def subnet_callback(compute2):
        """
        Fake subnet callback
        """
        return ("192.168.1.1", "192.168.1.2")

    compute1.get_ip_on_same_subnet.side_effect = subnet_callback

    link = UDPLink(project)
    async_run(link.add_node(node1, 0, 4))

    async def compute1_callback(path, data={}, **kwargs):
        """
        Fake server
        """
        if "/ports/udp" in path:
            response = MagicMock()
            response.json = {"udp_port": 1024}
            return response

    async def compute2_callback(path, data={}, **kwargs):
        """
        Fake server
        """
        if "/ports/udp" in path:
            response = MagicMock()
            response.json = {"udp_port": 2048}
            return response
        elif "/adapters" in path:
            raise aiohttp.web.HTTPConflict(text="Error when creating the NIO")

    compute1.post.side_effect = compute1_callback
    compute1.host = "example.com"
    compute2.post.side_effect = compute2_callback
    compute2.host = "example.org"
    with pytest.raises(aiohttp.web.HTTPConflict):
        async_run(link.add_node(node2, 3, 1))

    compute1.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/nio".format(project.id, node1.id), data={
        "lport": 1024,
        "rhost": "192.168.1.2",
        "rport": 2048,
        "type": "nio_udp",
        "filters": {},
        "suspend": False,
    }, timeout=120)
    compute2.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/3/ports/1/nio".format(project.id, node2.id), data={
        "lport": 2048,
        "rhost": "192.168.1.1",
        "rport": 1024,
        "type": "nio_udp",
        "filters": {},
        "suspend": False,
    }, timeout=120)
    # The link creation has failed we rollback the nio
    compute1.delete.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/nio".format(project.id, node1.id), timeout=120)
开发者ID:GNS3,项目名称:gns3-server,代码行数:67,代码来源:test_udp_link.py

示例8: test_update

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import host [as 别名]
def test_update(async_run, project):
    compute1 = MagicMock()
    compute2 = MagicMock()

    node1 = Node(project, compute1, "node1", node_type="vpcs")
    node1._ports = [EthernetPort("E0", 0, 0, 4)]
    node2 = Node(project, compute2, "node2", node_type="vpcs")
    node2._ports = [EthernetPort("E0", 0, 3, 1)]

    async def subnet_callback(compute2):
        """
        Fake subnet callback
        """
        return ("192.168.1.1", "192.168.1.2")

    compute1.get_ip_on_same_subnet.side_effect = subnet_callback

    link = UDPLink(project)
    async_run(link.add_node(node1, 0, 4))
    async_run(link.update_filters({"latency": [10]}))

    async def compute1_callback(path, data={}, **kwargs):
        """
        Fake server
        """
        if "/ports/udp" in path:
            response = MagicMock()
            response.json = {"udp_port": 1024}
            return response

    async def compute2_callback(path, data={}, **kwargs):
        """
        Fake server
        """
        if "/ports/udp" in path:
            response = MagicMock()
            response.json = {"udp_port": 2048}
            return response

    compute1.post.side_effect = compute1_callback
    compute1.host = "example.com"
    compute2.post.side_effect = compute2_callback
    compute2.host = "example.org"
    async_run(link.add_node(node2, 3, 1))

    compute1.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/nio".format(project.id, node1.id), data={
        "lport": 1024,
        "rhost": "192.168.1.2",
        "rport": 2048,
        "type": "nio_udp",
        "suspend": False,
        "filters": {"latency": [10]}
    }, timeout=120)
    compute2.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/3/ports/1/nio".format(project.id, node2.id), data={
        "lport": 2048,
        "rhost": "192.168.1.1",
        "rport": 1024,
        "type": "nio_udp",
        "suspend": False,
        "filters": {}
    }, timeout=120)

    assert link.created
    async_run(link.update_filters({"drop": [5], "bpf": ["icmp[icmptype] == 8"]}))
    compute1.put.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/nio".format(project.id, node1.id), data={
        "lport": 1024,
        "rhost": "192.168.1.2",
        "rport": 2048,
        "type": "nio_udp",
        "suspend": False,
        "filters": {
            "drop": [5],
            "bpf": ["icmp[icmptype] == 8"]
        }
    }, timeout=120)
开发者ID:GNS3,项目名称:gns3-server,代码行数:77,代码来源:test_udp_link.py

示例9: get_mock_smtp_server

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import host [as 别名]
def get_mock_smtp_server(host):
    mock_server = MagicMock()
    mock_server.host = host
    return mock_server
开发者ID:ColCarroll,项目名称:pete,代码行数:6,代码来源:test_broadcaster.py


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