本文整理汇总了Python中mock.Mock.port方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.port方法的具体用法?Python Mock.port怎么用?Python Mock.port使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.Mock
的用法示例。
在下文中一共展示了Mock.port方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_peers
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import port [as 别名]
def test_peers(self):
peer1 = Mock()
peer1.name = "server1"
peer1.ip = "192.168.0.13"
peer1.port = "88"
peer2 = Mock()
peer2.name = "server2"
peer2.ip = "192.168.0.22"
peer2.port = "88"
cluster = Mock()
cluster.name = "a_cluster"
cluster.nodes = [
Mock(peer=peer1),
Mock(peer=None), # skipped
Mock(peer=peer2),
Mock(peer=peer1), # duplicate, skipped
]
stanza = PeersStanza(cluster)
self.assertEqual(stanza.header, "peers a_cluster")
self.assertEqual(
set(stanza.lines),
set([
"peer server1 192.168.0.13:88",
"peer server2 192.168.0.22:88"
])
)
示例2: test_delete
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import port [as 别名]
def test_delete(self):
# arrange
uuid = 'uuid'
network_name = 'network_name'
network = Mock()
network.name = network_name
si = Mock()
vm = Mock()
vm.network = [network]
connection_detail = Mock()
connection_detail.host = Mock()
connection_detail.username = Mock()
connection_detail.password = Mock()
connection_detail.port = Mock()
pv_service = Mock()
pv_service.connect = Mock(return_value=si)
pv_service.find_by_uuid = Mock(return_value=vm)
connector = VirtualSwitchToMachineDisconnectCommand(pv_service, Mock(), 'anetwork')
# act
res = connector.disconnect(si, uuid, network_name)
# assert
self.assertTrue(pv_service.connect.called_with(connection_detail.host,
connection_detail.username,
connection_detail.password,
connection_detail.port))
self.assertTrue(pv_service.find_by_uuid.called_with(si, uuid))
self.assertTrue(res)
示例3: test_circuit_stream_failure
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import port [as 别名]
def test_circuit_stream_failure(self):
"""
If the stream-attach fails the error propagates
"""
reactor = Mock()
torstate = Mock()
target = Mock()
target.connect = Mock(return_value=defer.succeed(None))
circ = Mock()
circ.state = 'FAILED'
src_addr = Mock()
src_addr.host = 'host'
src_addr.port = 1234
target._get_address = Mock(return_value=defer.succeed(src_addr))
stream = Mock()
stream.source_port = 1234
stream.source_addr = 'host'
# okay, so we fire up our circuit-endpoint with mostly mocked
# things, and a circuit that's already in 'FAILED' state.
ep = TorCircuitEndpoint(reactor, torstate, circ, target)
# should get a Failure from the connect()
d = ep.connect(Mock())
attacher = yield _get_circuit_attacher(reactor, Mock())
attacher.attach_stream_failure(stream, RuntimeError("a bad thing"))
try:
yield d
self.fail("Should get exception")
except RuntimeError as e:
self.assertEqual("a bad thing", str(e))
示例4: test_success
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import port [as 别名]
def test_success(self):
"""
Connect a stream via a circuit
"""
reactor = Mock()
torstate = Mock()
target = Mock()
target.connect = Mock(return_value=defer.succeed('fake proto'))
circ = Mock()
circ.state = 'NEW'
src_addr = Mock()
src_addr.host = 'host'
src_addr.port = 1234
target._get_address = Mock(return_value=defer.succeed(src_addr))
stream = Mock()
stream.source_port = 1234
stream.source_addr = 'host'
# okay, so we fire up our circuit-endpoint with mostly mocked
# things, and a circuit that's already in 'FAILED' state.
ep = TorCircuitEndpoint(reactor, torstate, circ, target)
# should get a Failure from the connect()
d = ep.connect(Mock())
attacher = yield _get_circuit_attacher(reactor, torstate)
yield attacher.attach_stream(stream, [circ])
proto = yield d
self.assertEqual(proto, 'fake proto')
示例5: test_delete_all
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import port [as 别名]
def test_delete_all(self):
# arrange
uuid = 'uuid'
si = Mock()
vm = Mock()
connection_detail = Mock()
connection_detail.host = Mock()
connection_detail.username = Mock()
connection_detail.password = Mock()
connection_detail.port = Mock()
pv_service = Mock()
pv_service.connect = Mock(return_value=si)
pv_service.find_by_uuid = Mock(return_value=vm)
connector = VirtualSwitchToMachineDisconnectCommand(pv_service, Mock(), 'anetwork')
# virtual_switch_to_machine_connector.remove_interfaces_from_vm = Mock(return_value=True)
connector.get_network_by_name = lambda x, y: Mock()
# act
res = connector.disconnect(si, uuid)
# assert
self.assertTrue(pv_service.connect.called_with(connection_detail.host,
connection_detail.username,
connection_detail.password,
connection_detail.port))
self.assertTrue(pv_service.find_by_uuid.called_with(si, uuid))
# self.assertTrue(virtual_switch_to_machine_connector.remove_interfaces_from_vm.called_with(vm))
self.assertTrue(res)
示例6: _get_mock_segment
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import port [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
示例7: test_init_provider_override
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import port [as 别名]
def test_init_provider_override(self):
alt_provider = Mock(spec=boto.provider.Provider)
alt_provider.host = None
alt_provider.host_header = None
alt_provider.port = None
alt_provider.secret_key = 'alt_secret_key'
dynamodb = DynamoDBConnection(provider=alt_provider)
self.assertEqual(dynamodb.provider, alt_provider)
示例8: test_provider_override
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import port [as 别名]
def test_provider_override(self):
alt_provider = Mock(spec=boto.provider.Provider)
alt_provider.host = None
alt_provider.host_header = None
alt_provider.port = None
alt_provider.secret_key = 'alt_secret_key'
layer1 = Layer1(aws_access_key_id='aws_access_key', aws_secret_access_key='aws_secret_key', provider=alt_provider)
self.assertEqual(alt_provider, layer1.provider)
示例9: _get_conn
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import port [as 别名]
def _get_conn(reader):
global _conn_port
conn = Mock()
conn.host = "localhost"
conn.port = _conn_port
_conn_port += 1
reader._initialize_conn(conn)
reader._conn_subscribe(conn)
return conn
示例10: create_fake_endpoint
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import port [as 别名]
def create_fake_endpoint(name="source", **kw):
ep = Mock()
ep.zone.name = name
ep.secret_key = kw.get("secret", "secret")
ep.access_key = kw.get("access", "access")
ep.port = kw.get("port", 7777)
ep.host = kw.get("host", "localhost")
ep.debug = kw.get("debug", True)
return ep
示例11: test_get_db_params_returns_args_parameters
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import port [as 别名]
def test_get_db_params_returns_args_parameters(self, mock_parse_config_file):
mock_parse_config_file.return_value = (None, None, None, None )
mock_args = Mock()
mock_args.host = 'pumpkin'
mock_args.port = 12345
mock_args.index = 'ciccio'
elasticsearch_url, elasticsearch_index, elasticsearch_replicas = get_db_params(mock_args)
self.assertEquals(elasticsearch_url, 'http://pumpkin:12345')
self.assertEquals(elasticsearch_index, 'ciccio')
示例12: test_release_connection
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import port [as 别名]
def test_release_connection(self):
conn = Mock()
conn.host = 'foo'
conn.port = 9
mypool = pool.ShardPool(self.servers)
mypool._in_use_connections['foo:9'].add(conn)
self.assertTrue(mypool._in_use_connections['foo:9'])
mypool.release(conn)
self.assertFalse(mypool._in_use_connections['foo:9'])
示例13: test_by_address_with_srv
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import port [as 别名]
def test_by_address_with_srv(self):
with patch("dns.resolver.query") as query:
answer = Mock()
answer.target = "different.example.org."
answer.port = 12345
query.return_value = [answer]
self.server = MinecraftServer.lookup("example.org")
query.assert_called_once_with("_minecraft._tcp.example.org", "SRV")
self.assertEqual(self.server.host, "different.example.org")
self.assertEqual(self.server.port, 12345)
示例14: dns_query
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import port [as 别名]
def dns_query(name, _):
if '-server' not in name or '-ssl' in name:
return []
if name == '_etcd-server._tcp.blabla':
return []
elif name == '_etcd-server._tcp.exception':
raise DNSException()
srv = Mock()
srv.port = 2380
srv.target.to_text.return_value = 'localhost' if name == '_etcd-server._tcp.foobar' else '127.0.0.1'
return [srv]
示例15: _get_registered_scheduler_driver_master
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import port [as 别名]
def _get_registered_scheduler_driver_master(self):
driver = Mock()
framework_id = Mock()
framework_id.value = 'framework_id'
master_info = Mock()
master_info.hostname = 'localhost'
master_info.port = 1234
my_scheduler = scheduler.scale_scheduler.ScaleScheduler(None)
my_scheduler.registered(driver,framework_id,master_info)
return my_scheduler, driver, master_info