Here are the examples of the python api mock.sentinel.host taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
26 Examples
5
Example 1
Project: networking-hyperv Source File: test_nvgre_ops.py
def test_refresh_tunneling_agents(self):
self.ops._n_client.get_tunneling_agents.return_value = {
mock.sentinel.host: mock.sentinel.host_ip
}
self.ops._refresh_tunneling_agents()
self.assertEqual(mock.sentinel.host_ip,
self.ops._tunneling_agents[mock.sentinel.host])
3
Example 2
def test_main():
with patch('arctic.scripts.arctic_fsck.Arctic') as Arctic, \
patch('arctic.scripts.arctic_fsck.get_mongodb_uri') as get_mongodb_uri, \
patch('arctic.scripts.arctic_fsck.do_db_auth') as do_db_auth:
run_as_main(main, '--host', '%s:%s' % (sentinel.host, sentinel.port),
'-v', '--library', 'sentinel.library', 'lib2', '-f')
get_mongodb_uri.assert_called_once_with('sentinel.host:sentinel.port')
Arctic.assert_called_once_with(get_mongodb_uri.return_value)
assert do_db_auth.call_args_list == [call('%s:%s' % (sentinel.host, sentinel.port),
Arctic.return_value._conn,
'arctic_sentinel'),
call('%s:%s' % (sentinel.host, sentinel.port),
Arctic.return_value._conn,
'arctic')]
assert Arctic.return_value.__getitem__.return_value._fsck.call_args_list == [call(False),
call(False), ]
3
Example 3
Project: arctic Source File: test_arctic_fsck.py
def test_main_dry_run():
with patch('arctic.scripts.arctic_fsck.Arctic') as Arctic, \
patch('arctic.scripts.arctic_fsck.get_mongodb_uri') as get_mongodb_uri, \
patch('arctic.scripts.arctic_fsck.do_db_auth') as do_db_auth:
run_as_main(main, '--host', '%s:%s' % (sentinel.host, sentinel.port),
'-v', '--library', 'sentinel.library', 'sentinel.lib2')
get_mongodb_uri.assert_called_once_with('sentinel.host:sentinel.port')
Arctic.assert_called_once_with(get_mongodb_uri.return_value)
assert do_db_auth.call_count == 0
assert Arctic.return_value.__getitem__.return_value._fsck.call_args_list == [call(True),
call(True), ]
3
Example 4
Project: arctic Source File: test_arctic.py
def test_get_library_not_initialized():
self = create_autospec(Arctic,
mongo_host=sentinel.host)
self._library_cache = {}
with pytest.raises(LibraryNotFoundException) as e, \
patch('arctic.arctic.ArcticLibraryBinding', autospec=True) as ML:
ML.return_value.get_library_type.return_value = None
Arctic.get_library(self, sentinel.lib_name)
assert "Library %s was not correctly initialized in %s." % (sentinel.lib_name, self) in str(e)
3
Example 5
Project: arctic Source File: test_arctic.py
def test_get_library_auth_issue():
self = create_autospec(Arctic,
mongo_host=sentinel.host)
self._library_cache = {}
with pytest.raises(LibraryNotFoundException) as e, \
patch('arctic.arctic.ArcticLibraryBinding', autospec=True) as ML:
ML.return_value.get_library_type.side_effect = OperationFailure('database error: not authorized for query on arctic_marketdata.index.ARCTIC')
Arctic.get_library(self, sentinel.lib_name)
assert "Library %s was not correctly initialized in %s." % (sentinel.lib_name, self) in str(e)
3
Example 6
def test_get_host():
store = Mock()
store._arctic_lib.arctic.mongo_host = sentinel.host
store._collection.database.client.nodes = set([('a', 12)])
store._arctic_lib.get_name.return_value = sentinel.lib_name
assert _get_host(store) == {'mhost': 'sentinel.host',
'mnodes': ['a:12'],
'l': sentinel.lib_name,
}
3
Example 7
def test_get_host_list():
store = Mock()
store._arctic_lib.arctic.mongo_host = sentinel.host
store._collection.database.client.nodes = set([('a', 12)])
store._arctic_lib.get_name.return_value = sentinel.lib_name
assert _get_host([store]) == {'mhost': 'sentinel.host',
'mnodes': ['a:12'],
'l': sentinel.lib_name,
}
3
Example 8
Project: mopidy Source File: test_connection.py
def test_init_ensure_nonblocking_io(self):
sock = Mock(spec=socket.SocketType)
network.Connection.__init__(
self.mock, Mock(), {}, sock, (sentinel.host, sentinel.port),
sentinel.timeout)
sock.setblocking.assert_called_once_with(False)
3
Example 9
Project: mopidy Source File: test_connection.py
def test_init_starts_actor(self):
protocol = Mock(spec=network.LineProtocol)
network.Connection.__init__(
self.mock, protocol, {}, Mock(), (sentinel.host, sentinel.port),
sentinel.timeout)
protocol.start.assert_called_once_with(self.mock)
3
Example 10
Project: mopidy Source File: test_connection.py
def test_init_enables_recv_and_timeout(self):
network.Connection.__init__(
self.mock, Mock(), {}, Mock(), (sentinel.host, sentinel.port),
sentinel.timeout)
self.mock.enable_recv.assert_called_once_with()
self.mock.enable_timeout.assert_called_once_with()
3
Example 11
def test_init_stores_values_in_attributes(self):
addr = (sentinel.host, sentinel.port)
protocol = Mock(spec=network.LineProtocol)
protocol_kwargs = {}
sock = Mock(spec=socket.SocketType)
network.Connection.__init__(
self.mock, protocol, protocol_kwargs, sock, addr, sentinel.timeout)
self.assertEqual(sock, self.mock.sock)
self.assertEqual(protocol, self.mock.protocol)
self.assertEqual(protocol_kwargs, self.mock.protocol_kwargs)
self.assertEqual(sentinel.timeout, self.mock.timeout)
self.assertEqual(sentinel.host, self.mock.host)
self.assertEqual(sentinel.port, self.mock.port)
3
Example 12
Project: mopidy Source File: test_connection.py
def test_init_handles_ipv6_addr(self):
addr = (
sentinel.host, sentinel.port, sentinel.flowinfo, sentinel.scopeid)
protocol = Mock(spec=network.LineProtocol)
protocol_kwargs = {}
sock = Mock(spec=socket.SocketType)
network.Connection.__init__(
self.mock, protocol, protocol_kwargs, sock, addr, sentinel.timeout)
self.assertEqual(sentinel.host, self.mock.host)
self.assertEqual(sentinel.port, self.mock.port)
3
Example 13
Project: mopidy Source File: test_lineprotocol.py
def test_host_property(self):
mock = Mock(spec=network.Connection)
mock.host = sentinel.host
lineprotocol = network.LineProtocol(mock)
self.assertEqual(sentinel.host, lineprotocol.host)
3
Example 14
Project: mopidy Source File: test_server.py
def test_init_fails_on_fileno_call(self):
sock = Mock(spec=socket.SocketType)
sock.fileno.side_effect = socket.error
self.mock.create_server_socket.return_value = sock
with self.assertRaises(socket.error):
network.Server.__init__(
self.mock, sentinel.host, sentinel.port, sentinel.protocol)
3
Example 15
def test_init_stores_values_in_attributes(self):
# This need to be a mock and no a sentinel as fileno() is called on it
sock = Mock(spec=socket.SocketType)
self.mock.create_server_socket.return_value = sock
network.Server.__init__(
self.mock, sentinel.host, sentinel.port, sentinel.protocol,
max_connections=sentinel.max_connections, timeout=sentinel.timeout)
self.assertEqual(sentinel.protocol, self.mock.protocol)
self.assertEqual(sentinel.max_connections, self.mock.max_connections)
self.assertEqual(sentinel.timeout, self.mock.timeout)
self.assertEqual(sock, self.mock.server_socket)
3
Example 16
Project: mopidy Source File: test_server.py
@patch.object(network, 'create_socket', spec=socket.SocketType)
def test_create_server_socket_sets_up_listener(self, create_socket):
sock = create_socket.return_value
network.Server.create_server_socket(
self.mock, sentinel.host, sentinel.port)
sock.setblocking.assert_called_once_with(False)
sock.bind.assert_called_once_with((sentinel.host, sentinel.port))
sock.listen.assert_called_once_with(any_int)
3
Example 17
Project: mopidy Source File: test_server.py
@patch.object(network, 'create_socket', new=Mock())
def test_create_server_socket_fails(self):
network.create_socket.side_effect = socket.error
with self.assertRaises(socket.error):
network.Server.create_server_socket(
self.mock, sentinel.host, sentinel.port)
3
Example 18
Project: mopidy Source File: test_server.py
@patch.object(network, 'create_socket', new=Mock())
def test_create_server_bind_fails(self):
sock = network.create_socket.return_value
sock.bind.side_effect = socket.error
with self.assertRaises(socket.error):
network.Server.create_server_socket(
self.mock, sentinel.host, sentinel.port)
3
Example 19
Project: mopidy Source File: test_server.py
@patch.object(network, 'create_socket', new=Mock())
def test_create_server_listen_fails(self):
sock = network.create_socket.return_value
sock.listen.side_effect = socket.error
with self.assertRaises(socket.error):
network.Server.create_server_socket(
self.mock, sentinel.host, sentinel.port)
3
Example 20
def test_reject_connection(self):
sock = Mock(spec=socket.SocketType)
network.Server.reject_connection(
self.mock, sock, (sentinel.host, sentinel.port))
sock.close.assert_called_once_with()
3
Example 21
Project: mopidy Source File: test_server.py
def test_reject_connection_error(self):
sock = Mock(spec=socket.SocketType)
sock.close.side_effect = socket.error
network.Server.reject_connection(
self.mock, sock, (sentinel.host, sentinel.port))
sock.close.assert_called_once_with()
0
Example 22
Project: arctic Source File: test_decorators_unit.py
def test_mongo_retry():
retries = [2]
self = MagicMock()
self._arctic_lib.arctic.mongo_host = sentinel.host
self._collection.database.client.nodes = set([('a', 12)])
self._arctic_lib.get_name.return_value = sentinel.lib_name
with patch('arctic.decorators._handle_error', autospec=True) as he:
@mongo_retry
def foo(self):
if retries[0] == 2:
retries[0] -= 1
raise OperationFailure('error')
elif retries[0] == 1:
retries[0] -= 1
raise AutoReconnect('error')
return "success"
foo(self)
assert he.call_count == 2
assert isinstance(he.call_args_list[0][0][1], OperationFailure)
assert he.call_args_list[0][0][2] == 1
assert he.call_args_list[0][1] == {'mnodes': ['a:12'],
'mhost': 'sentinel.host',
'l': sentinel.lib_name}
assert isinstance(he.call_args_list[1][0][1], AutoReconnect)
assert he.call_args_list[1][0][2] == 2
0
Example 23
Project: arctic Source File: test_hooks.py
def test_get_auth_hook():
auth_resolver = Mock()
register_get_auth_hook(auth_resolver)
get_auth(sentinel.host, sentinel.app_name, sentinel.database_name)
assert auth_resolver.call_args_list == [call(sentinel.host, sentinel.app_name, sentinel.database_name)]
0
Example 24
Project: mopidy Source File: test_server.py
def test_init_calls_create_server_socket(self):
network.Server.__init__(
self.mock, sentinel.host, sentinel.port, sentinel.protocol)
self.mock.create_server_socket.assert_called_once_with(
sentinel.host, sentinel.port)
0
Example 25
def __init__(self, *args, **kwargs):
super(MockConnection, self).__init__(*args, **kwargs)
self.host = mock.sentinel.host
self.port = mock.sentinel.port
self.response = []
0
Example 26
Project: os-win Source File: test_utilsfactory.py
def test_get_vmutils(self):
instance = self._check_get_class(expected_class=vmutils.VMUtils,
class_type='vmutils',
host=mock.sentinel.host)
self.assertEqual(mock.sentinel.host, instance._host)