mirror of
https://github.com/sshuttle/sshuttle.git
synced 2024-11-29 11:23:09 +01:00
3bfb975ed9
* re-organized imports according to pep8 * fixed all remaining pep8 issues * moved common config into setup.cfg, additionally test `tests` * removed --select=X -- the errors selected where by default not in flake8's --ignore list so effectively had no effect * update .travis.yml to reflect changes in tox.ini * make travis just use tox in order to avoid code duplaction * replace py.test with pytest * fixed .travis.yml * try different pypy toxenv * hopefully fixed testenv for pypy * added pypy basepython, removed unused python2.6 * install dev package before testing (fixes missing coverage) * fixed empty exception pass blocks with noqa * Added dummy log message on empty try-except-pass blocks to make dodacy happy :( * Replaced Exception with BaseException
66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
import socket
|
|
|
|
from mock import Mock, patch, call
|
|
|
|
import sshuttle.sdnotify
|
|
|
|
|
|
@patch('sshuttle.sdnotify.os.environ.get')
|
|
def test_notify_invalid_socket_path(mock_get):
|
|
mock_get.return_value = 'invalid_path'
|
|
assert not sshuttle.sdnotify.send(sshuttle.sdnotify.ready())
|
|
|
|
|
|
@patch('sshuttle.sdnotify.os.environ.get')
|
|
def test_notify_socket_not_there(mock_get):
|
|
mock_get.return_value = '/run/valid_nonexistent_path'
|
|
assert not sshuttle.sdnotify.send(sshuttle.sdnotify.ready())
|
|
|
|
|
|
@patch('sshuttle.sdnotify.os.environ.get')
|
|
def test_notify_no_message(mock_get):
|
|
mock_get.return_value = '/run/valid_path'
|
|
assert not sshuttle.sdnotify.send()
|
|
|
|
|
|
@patch('sshuttle.sdnotify.socket.socket')
|
|
@patch('sshuttle.sdnotify.os.environ.get')
|
|
def test_notify_socket_error(mock_get, mock_socket):
|
|
mock_get.return_value = '/run/valid_path'
|
|
mock_socket.side_effect = socket.error('test error')
|
|
assert not sshuttle.sdnotify.send(sshuttle.sdnotify.ready())
|
|
|
|
|
|
@patch('sshuttle.sdnotify.socket.socket')
|
|
@patch('sshuttle.sdnotify.os.environ.get')
|
|
def test_notify_sendto_error(mock_get, mock_socket):
|
|
message = sshuttle.sdnotify.ready()
|
|
socket_path = '/run/valid_path'
|
|
|
|
sock = Mock()
|
|
sock.sendto.side_effect = socket.error('test error')
|
|
mock_get.return_value = '/run/valid_path'
|
|
mock_socket.return_value = sock
|
|
|
|
assert not sshuttle.sdnotify.send(message)
|
|
assert sock.sendto.mock_calls == [
|
|
call(message, socket_path),
|
|
]
|
|
|
|
|
|
@patch('sshuttle.sdnotify.socket.socket')
|
|
@patch('sshuttle.sdnotify.os.environ.get')
|
|
def test_notify(mock_get, mock_socket):
|
|
messages = [sshuttle.sdnotify.ready(), sshuttle.sdnotify.status('Running')]
|
|
socket_path = '/run/valid_path'
|
|
|
|
sock = Mock()
|
|
sock.sendto.return_value = 1
|
|
mock_get.return_value = '/run/valid_path'
|
|
mock_socket.return_value = sock
|
|
|
|
assert sshuttle.sdnotify.send(*messages)
|
|
assert sock.sendto.mock_calls == [
|
|
call(b'\n'.join(messages), socket_path),
|
|
]
|